Skip to content

Commit

Permalink
Allow moving of all shapes of an object in one go (moveit#3599)
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-yoshi authored May 15, 2024
1 parent 49ce091 commit 0a966b3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ class World
bool moveShapeInObject(const std::string& object_id, const shapes::ShapeConstPtr& shape,
const Eigen::Isometry3d& shape_pose);

/** \brief Update the pose of all shapes in an object. Shape size is verified. Returns true on success. */
bool moveShapesInObject(const std::string& object_id, const EigenSTL::vector_Isometry3d& shape_poses);

/** \brief Move the object pose (thus moving all shapes and subframes in the object)
* according to the given transform specified in world frame.
* The transform is relative to and changes the object pose. It does not replace it.
Expand Down
20 changes: 20 additions & 0 deletions moveit_core/collision_detection/src/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,26 @@ bool World::moveShapeInObject(const std::string& object_id, const shapes::ShapeC
return false;
}

bool World::moveShapesInObject(const std::string& object_id, const EigenSTL::vector_Isometry3d& shape_poses)
{
auto it = objects_.find(object_id);
if (it != objects_.end())
{
if (shape_poses.size() == it->second->shapes_.size())
{
for (std::size_t i = 0; i < shape_poses.size(); ++i)
{
ASSERT_ISOMETRY(shape_poses[i]) // unsanitized input, could contain a non-isometry
it->second->shape_poses_[i] = shape_poses[i];
it->second->global_shape_poses_[i] = it->second->pose_ * shape_poses[i];
}
notify(it->second, MOVE_SHAPE);
return true;
}
}
return false;
}

bool World::moveObject(const std::string& object_id, const Eigen::Isometry3d& transform)
{
auto it = objects_.find(object_id);
Expand Down
40 changes: 40 additions & 0 deletions moveit_core/planning_scene/src/planning_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,7 @@ bool PlanningScene::processCollisionObjectMove(const moveit_msgs::CollisionObjec
{
if (world_->hasObject(object.id))
{
// update object pose
if (!object.primitives.empty() || !object.meshes.empty() || !object.planes.empty())
ROS_WARN_NAMED(LOGNAME, "Move operation for object '%s' ignores the geometry specified in the message.",
object.id.c_str());
Expand All @@ -1893,6 +1894,45 @@ bool PlanningScene::processCollisionObjectMove(const moveit_msgs::CollisionObjec

const Eigen::Isometry3d object_frame_transform = world_to_object_header_transform * header_to_pose_transform;
world_->setObjectPose(object.id, object_frame_transform);

// update shape poses
if (!object.primitive_poses.empty() || !object.mesh_poses.empty() || !object.plane_poses.empty())
{
auto world_object = world_->getObject(object.id); // object exists, checked earlier

std::size_t shape_size = object.primitive_poses.size() + object.mesh_poses.size() + object.plane_poses.size();
if (shape_size != world_object->shape_poses_.size())
{
ROS_ERROR_NAMED(LOGNAME, "Move operation for object '%s' must have same number of geometry poses. Cannot move.",
object.id.c_str());
return false;
}

// order matters -> primitive, mesh and plane
EigenSTL::vector_Isometry3d shape_poses;
for (const auto& shape_pose : object.primitive_poses)
{
shape_poses.emplace_back();
PlanningScene::poseMsgToEigen(shape_pose, shape_poses.back());
}
for (const auto& shape_pose : object.mesh_poses)
{
shape_poses.emplace_back();
PlanningScene::poseMsgToEigen(shape_pose, shape_poses.back());
}
for (const auto& shape_pose : object.plane_poses)
{
shape_poses.emplace_back();
PlanningScene::poseMsgToEigen(shape_pose, shape_poses.back());
}

if (!world_->moveShapesInObject(object.id, shape_poses))
{
ROS_ERROR_NAMED(LOGNAME, "Move operation for object '%s' internal world error. Cannot move.", object.id.c_str());
return false;
}
}

return true;
}

Expand Down

0 comments on commit 0a966b3

Please sign in to comment.