Skip to content

Commit e2b24f5

Browse files
authored
Ports moveit1 #3689 (#3357)
* Renames .hpp files to .h to help cherry pick. * Publish planning scene while planning (#3689) So far, the PSM's planning scene was locked during planning, thus stopping any PS updates in rviz. Instead of locking the PSM's current scene, we use an independent clone of that scene for planning. To this end, PlanningSceneMonitor::copyPlanningScene() and ExecutableMotionPlan::copyPlanningScene() were added. * Renames .h files back to .hpp. * Updates message types to ros2. * Updates to use new variable names. * Undoes erroneous autoformatting.
1 parent bbf7e40 commit e2b24f5

File tree

7 files changed

+36
-31
lines changed

7 files changed

+36
-31
lines changed

moveit_planners/pilz_industrial_motion_planner/src/move_group_sequence_action.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,6 @@ void MoveGroupSequenceAction::executeMoveCallbackPlanOnly(
209209
{
210210
RCLCPP_INFO(getLogger(), "Planning request received for MoveGroupSequenceAction action.");
211211

212-
// lock the scene so that it does not modify the world representation while
213-
// diff() is called
214-
planning_scene_monitor::LockedPlanningSceneRO lscene(context_->planning_scene_monitor_);
215-
216-
const planning_scene::PlanningSceneConstPtr& the_scene =
217-
(moveit::core::isEmpty(goal->planning_options.planning_scene_diff)) ?
218-
static_cast<const planning_scene::PlanningSceneConstPtr&>(lscene) :
219-
lscene->diff(goal->planning_options.planning_scene_diff);
220-
221212
rclcpp::Time planning_start = context_->moveit_cpp_->getNode()->now();
222213
RobotTrajCont traj_vec;
223214
try
@@ -233,7 +224,8 @@ void MoveGroupSequenceAction::executeMoveCallbackPlanOnly(
233224
return;
234225
}
235226

236-
traj_vec = command_list_manager_->solve(the_scene, planning_pipeline, goal->request);
227+
auto scene = context_->planning_scene_monitor_->copyPlanningScene(goal->planning_options.planning_scene_diff);
228+
traj_vec = command_list_manager_->solve(scene, planning_pipeline, goal->request);
237229
}
238230
catch (const MoveItErrorCodeException& ex)
239231
{
@@ -277,7 +269,6 @@ bool MoveGroupSequenceAction::planUsingSequenceManager(const moveit_msgs::msg::M
277269
{
278270
setMoveState(move_group::PLANNING);
279271

280-
planning_scene_monitor::LockedPlanningSceneRO lscene(plan.planning_scene_monitor);
281272
RobotTrajCont traj_vec;
282273
try
283274
{
@@ -291,7 +282,7 @@ bool MoveGroupSequenceAction::planUsingSequenceManager(const moveit_msgs::msg::M
291282
return false;
292283
}
293284

294-
traj_vec = command_list_manager_->solve(plan.planning_scene, planning_pipeline, req);
285+
traj_vec = command_list_manager_->solve(plan.copyPlanningScene(), planning_pipeline, req);
295286
}
296287
catch (const MoveItErrorCodeException& ex)
297288
{

moveit_planners/pilz_industrial_motion_planner/src/move_group_sequence_service.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ bool MoveGroupSequenceService::plan(const moveit_msgs::srv::GetMotionSequence::R
8484
return true;
8585
}
8686

87-
// TODO: Do we lock on the correct scene? Does the lock belong to the scene
88-
// used for planning?
89-
planning_scene_monitor::LockedPlanningSceneRO ps(context_->planning_scene_monitor_);
90-
9187
rclcpp::Time planning_start = context_->moveit_cpp_->getNode()->now();
9288
RobotTrajCont traj_vec;
9389
try
@@ -103,7 +99,8 @@ bool MoveGroupSequenceService::plan(const moveit_msgs::srv::GetMotionSequence::R
10399
return false;
104100
}
105101

106-
traj_vec = command_list_manager_->solve(ps, context_->planning_pipeline_, req->request);
102+
auto scene = context_->planning_scene_monitor_->copyPlanningScene();
103+
traj_vec = command_list_manager_->solve(scene, context_->planning_pipeline_, req->request);
107104
}
108105
catch (const MoveItErrorCodeException& ex)
109106
{

moveit_ros/move_group/src/default_capabilities/move_action_capability.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,6 @@ void MoveGroupMoveAction::executeMoveCallbackPlanOnly(const std::shared_ptr<MGAc
193193
{
194194
RCLCPP_INFO(getLogger(), "Planning request received for MoveGroup action. Forwarding to planning pipeline.");
195195

196-
// lock the scene so that it does not modify the world representation while diff() is called
197-
planning_scene_monitor::LockedPlanningSceneRO lscene(context_->planning_scene_monitor_);
198-
const planning_scene::PlanningSceneConstPtr& the_scene =
199-
(moveit::core::isEmpty(goal->get_goal()->planning_options.planning_scene_diff)) ?
200-
static_cast<const planning_scene::PlanningSceneConstPtr&>(lscene) :
201-
lscene->diff(goal->get_goal()->planning_options.planning_scene_diff);
202196
planning_interface::MotionPlanResponse res;
203197

204198
if (preempt_requested_)
@@ -219,7 +213,9 @@ void MoveGroupMoveAction::executeMoveCallbackPlanOnly(const std::shared_ptr<MGAc
219213

220214
try
221215
{
222-
if (!planning_pipeline->generatePlan(the_scene, goal->get_goal()->request, res, context_->debug_))
216+
auto scene =
217+
context_->planning_scene_monitor_->copyPlanningScene(goal->get_goal()->planning_options.planning_scene_diff);
218+
if (!planning_pipeline->generatePlan(scene, goal->get_goal()->request, res, context_->debug_))
223219
{
224220
RCLCPP_ERROR(getLogger(), "Generating a plan with planning pipeline failed.");
225221
res.error_code.val = moveit_msgs::msg::MoveItErrorCodes::FAILURE;
@@ -252,10 +248,9 @@ bool MoveGroupMoveAction::planUsingPlanningPipeline(const planning_interface::Mo
252248
return solved;
253249
}
254250

255-
planning_scene_monitor::LockedPlanningSceneRO lscene(plan.planning_scene_monitor);
256251
try
257252
{
258-
solved = planning_pipeline->generatePlan(plan.planning_scene, req, res, context_->debug_);
253+
solved = planning_pipeline->generatePlan(plan.copyPlanningScene(), req, res, context_->debug_);
259254
}
260255
catch (std::exception& ex)
261256
{

moveit_ros/planning/moveit_cpp/src/planning_component.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,7 @@ planning_interface::MotionPlanResponse PlanningComponent::plan(const PlanRequest
131131
{ // Clone current planning scene
132132
auto planning_scene_monitor = moveit_cpp_->getPlanningSceneMonitorNonConst();
133133
planning_scene_monitor->updateFrameTransforms();
134-
planning_scene = [planning_scene_monitor] {
135-
planning_scene_monitor::LockedPlanningSceneRO ls(planning_scene_monitor);
136-
return planning_scene::PlanningScene::clone(ls);
137-
}();
138-
planning_scene_monitor.reset(); // release this pointer}
134+
planning_scene = planning_scene_monitor->copyPlanningScene();
139135
}
140136
// Init MotionPlanRequest
141137
::planning_interface::MotionPlanRequest request = getMotionPlanRequest(parameters);

moveit_ros/planning/plan_execution/include/moveit/plan_execution/plan_representation.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ struct ExecutableMotionPlan
8282

8383
/// An error code reflecting what went wrong (if anything)
8484
moveit_msgs::msg::MoveItErrorCodes error_code;
85+
86+
planning_scene::PlanningScenePtr copyPlanningScene()
87+
{
88+
// planning_scene_ is based on the scene from this monitor
89+
// (either it's the monitored scene or a diff on top of it)
90+
// so in order to copy the scene, we must also lock the underlying monitor
91+
planning_scene_monitor::LockedPlanningSceneRO ls(planning_scene_monitor);
92+
return planning_scene::PlanningScene::clone(planning_scene);
93+
}
8594
};
8695

8796
/// The signature of a function that can compute a motion plan

moveit_ros/planning/planning_scene_monitor/include/moveit/planning_scene_monitor/planning_scene_monitor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ class MOVEIT_PLANNING_SCENE_MONITOR_EXPORT PlanningSceneMonitor
192192
return scene_const_;
193193
}
194194

195+
/** @brief Returns a copy of the current planning scene. */
196+
planning_scene::PlanningScenePtr
197+
copyPlanningScene(const moveit_msgs::msg::PlanningScene& diff = moveit_msgs::msg::PlanningScene());
198+
195199
/** @brief Return true if the scene \e scene can be updated directly
196200
or indirectly by this monitor. This function will return true if
197201
the pointer of the scene is the same as the one maintained,

moveit_ros/planning/planning_scene_monitor/src/planning_scene_monitor.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ PlanningSceneMonitor::~PlanningSceneMonitor()
152152
rm_loader_.reset();
153153
}
154154

155+
planning_scene::PlanningScenePtr PlanningSceneMonitor::copyPlanningScene(const moveit_msgs::msg::PlanningScene& diff)
156+
{
157+
// We cannot use LockedPlanningSceneRO for RAII because it requires a PSMPtr
158+
// Instead assume clone will not throw
159+
lockSceneRead();
160+
auto scene = planning_scene::PlanningScene::clone(getPlanningScene());
161+
unlockSceneRead();
162+
163+
if (!moveit::core::isEmpty(diff))
164+
scene->setPlanningSceneDiffMsg(diff);
165+
return scene;
166+
}
167+
155168
void PlanningSceneMonitor::initialize(const planning_scene::PlanningScenePtr& scene)
156169
{
157170
if (monitor_name_.empty())

0 commit comments

Comments
 (0)