ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Planning is not executing and the collision objects are not in the Moveit scene during executing a trajectoy.

asked 2021-03-31 23:30:29 -0500

Astronaut gravatar image

updated 2021-03-31 23:31:11 -0500

When Im detecting collision object during the execution of the trajectory in the Moveit simulation I got the following error:

[ERROR] [1617248212.709207448]: RRTConnect: Unable to sample any valid states for goal tree

Also, the detected collision objects with the ZED Camera are not shown in the Moveit Scene

Here the code

using namespace sensor_msgs;
using namespace std;

void chatterCallback(const darknet_ros_3d_msgs::BoundingBoxes3d& boxes)
{ 

 int counter_id = 0;
 const std::string PLANNING_GROUP = "crane_control";    
 moveit::planning_interface::PlanningSceneInterface planning_scene_interface;
 moveit::planning_interface::MoveGroupInterface move_group(PLANNING_GROUP);
 moveit::planning_interface::MoveGroupInterface::Plan my_plan;
 const std::string MoveGroupInterface = "robot_description";  

 namespace rvt = rviz_visual_tools;
 moveit_visual_tools::MoveItVisualTools visual_tools("panda_link0");
 visual_tools.deleteAllMarkers(); 


  Eigen::Affine3d text_pose = Eigen::Affine3d::Identity();
  text_pose.translation().z() = 1.75;
  visual_tools.publishText(text_pose, "MoveGroupInterface Demo", rvt::WHITE, rvt::XLARGE);

  visual_tools.trigger();

  // Planning to a Pose goal
  geometry_msgs::Pose target_pose1;
  target_pose1.orientation.w = 1.0;
  target_pose1.position.x = 0.28;
  target_pose1.position.z = 0.5;
  move_group.setPoseTarget(target_pose1);
  bool success = (move_group.plan(my_plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
  move_group.move();


 std::vector<std::string> object_ids;
 moveit_msgs::CollisionObject collision_object;
 collision_object.header.frame_id = "world";
 collision_object.id = "BOX_";
 std::vector<moveit_msgs::CollisionObject> collision_objects;

          for(auto bb : boxes.bounding_boxes)
                    {



                                  shape_msgs::SolidPrimitive primitive;
                                  primitive.type = primitive.BOX;
                                  primitive.dimensions.resize(3);

                                  string str= to_string(counter_id++);

                                  //Pose
                                  geometry_msgs::Pose box_pose;
                                  box_pose.position.x = abs ((bb.xmax + bb.xmin)/2);
                                  box_pose.position.y = abs ((bb.ymax + bb.ymin)/2);
                                  box_pose.position.z = abs ((bb.zmax + bb.zmin)/2)-10;
                                  box_pose.orientation.x = 0; 
                                  box_pose.orientation.y = 0;   
                                  box_pose.orientation.z = 0;
                                  box_pose.orientation.w = 1.0;

                                  //Dimension
                                  primitive.dimensions[0] = abs (bb.xmax - bb.xmin);
                                  primitive.dimensions[1] = abs (bb.ymax - bb.ymin);
                                  primitive.dimensions[2] = abs (bb.zmax - bb.zmin); 


                                  //Collision object                                 
                                  collision_object.primitives.push_back(primitive);
                                  collision_object.primitive_poses.push_back(box_pose);                                 
                                  collision_objects.push_back(collision_object); 
                                  sleep(0.3);                        


                            }
                                 collision_object.operation = collision_object.REMOVE; 
                                 object_ids.push_back(collision_object.id);
                                 planning_scene_interface.removeCollisionObjects(object_ids); 

                                 sleep(0.5); 
                                 collision_object.operation = collision_object.ADD;
                                 planning_scene_interface.applyCollisionObjects(collision_objects);

 }

int main(int argc,  char** argv)

{
  ros::init(argc, argv, "cpp_subscriber");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe("/darknet_ros_3d/bounding_boxes", 5, chatterCallback);
  ros::spin();  

}

Here the robot controller yaml from the config file

crane:
  # Publish all joint states -----------------------------------
  joint_state_controller:
    type: joint_state_controller/JointStateController
    publish_rate: 50
    joints:
      - crane_rotation
      - crane_linearX
      - crane_linearZ
      - crane_joint1
      - crane_joint2
      - crane_joint3

  # Position Controllers ---------------------------------------
  joint1_position_controller:
    type: position_controllers/JointPositionController
    joint: crane_rotation
    # pid: {p: 1000.0, i: 1.0, d: 100.0}
  joint2_position_controller:
    type: position_controllers/JointPositionController
    joint: crane_linearX
    # pid: {p: 500.0, i: 1.0, d: 100.0}
  joint3_position_controller:
    type: position_controllers/JointPositionController
    joint: crane_linearZ
    # pid: {p: 500.0, i: 0.01, d: 10.0}

Here the RVIZRVIZ

Any Help?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-04-01 02:35:10 -0500

fvd gravatar image

updated 2021-04-01 02:35:39 -0500

In this section of your code, you forget to add the collision object message to your vector. Thus the vector collision_objects that you apply to the collision scene is empty:

collision_object.operation = collision_object.REMOVE; 
object_ids.push_back(collision_object.id);
planning_scene_interface.removeCollisionObjects(object_ids); 

sleep(0.5); 
collision_object.operation = collision_object.ADD;
planning_scene_interface.applyCollisionObjects(collision_objects);

Just for the record, there is no need to remove objects before adding them to the scene. If a collision object message with the operation ADD is received and an existing object has the same name, it is removed automatically.

Also note that planning_scene_interface.applyCollisionObject() exists, so you don't have to make a vector.

edit flag offensive delete link more

Comments

Sorry , don't understand. To add the collision object message to my vector? And why the plan is not executing?

Astronaut gravatar image Astronaut  ( 2021-04-01 04:15:59 -0500 )edit

You are making a vector in the line std::vector<moveit_msgs::CollisionObject> collision_objects; but you never fill it.

The planning pipeline says that it can't sample valid states for the goal tree, so it cannot find a position that the robot could be at the goal. The pose might be in collision with something or out of reach of your robot, or the target orientation might not be feasible for your end effector link. I don't know your robot and scene, so I can't tell. Try visualizing with moveit_visual_tools and read closely through your code to find your mistake.

fvd gravatar image fvd  ( 2021-04-01 06:45:32 -0500 )edit

Ok thanks. Will heck

Astronaut gravatar image Astronaut  ( 2021-04-05 21:30:48 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-03-31 23:30:29 -0500

Seen: 452 times

Last updated: Apr 01 '21