How to visualize the trajectory of attached object with MoveItCpp API
Hello
I'm following the tutorial of MoveIt to testing the MoveItCpp API in ROS Melodic. Though this tutorial doesn't mention adding objects to planning scene or attaching them to arm, I found an example of adding collision objects to planning scene from the tutorial of ROS 2 Foxy. By inferring to such example, I tried to implement attaching an object to the end-effector of arm as followng:
// define a cylinder to attach to the arm
shape_msgs::SolidPrimitive cylinderPrimitive;
cylinderPrimitive.type = cylinderPrimitive.CYLINDER;
cylinderPrimitive.dimensions.resize(2);
cylinderPrimitive.dimensions[cylinderPrimitive.CYLINDER_HEIGHT] = 0.1;
cylinderPrimitive.dimensions[cylinderPrimitive.CYLINDER_RADIUS] = 0.02;
// define a pose for the cylinder (specified relative to frame_id)
geometry_msgs::Pose grabPose;
grabPose.orientation = robotStartPose.orientation;
grabPose.position.x = 0.24;
grabPose.position.y = 0.04;
grabPose.position.z = 0.26;
// define a collision object ROS message for the robot to avoid
moveit_msgs::CollisionObject object2Attach;
// frame_id decides the coord frame the object belongs to
object2Attach.header.frame_id = jointModelGroupPtr->getLinkModelNames().back();
// the id of the object is used to identify it
object2Attach.id = "object cylinder";
object2Attach.primitives.push_back(cylinderPrimitive);
object2Attach.primitive_poses.push_back(grabPose);
object2Attach.operation = object2Attach.ADD;
moveit_msgs::AttachedCollisionObject attachedObject;
attachedObject.object = object2Attach;
attachedObject.link_name = jointModelGroupPtr->getLinkModelNames().back();
{
// lock PlanningScene
planning_scene_monitor::LockedPlanningSceneRW planningScene(moveitCppPtr->getPlanningSceneMonitor());
planningScene->processAttachedCollisionObjectMsg(attachedObject);
// unlock PlanningScene
}
// re-call the PlanningComponents to compute the plan and visualize it
// note that it is just planning
planSolution05 = planningComponents->plan();
// check if PlanningComponents succeeded in finding the plan
if (planSolution05)
{
visualTools.publishText(textPose, "obstacle goal with attached object", rvt::WHITE, rvt::XLARGE);
// visualize the start pose in rviz
visualTools.publishAxisLabeled(robotStartState->getGlobalLinkTransform(paramVisualLink), "start_pose");
// visualize the goal pose in rviz
visualTools.publishAxisLabeled(goal05.pose, "target_pose");
// visualize the trajectory in rviz
visualTools.publishTrajectoryLine(planSolution05.trajectory, jointModelGroupPtr);
visualTools.trigger();
// uncomment if you want to execute the plan
//planningComponents->execute();
}
While runing this code, I can see the the cylinder is attached to correct position I specified, but it keeps still while arm is in planning annimation, like following gif:
Thanks for your insight!
Asked by Xinjue on 2022-06-09 00:36:43 UTC
Comments