Skip to content

Commit 702710d

Browse files
Improve comments for pick-and-place task (moveit#238)
1 parent fbc05e4 commit 702710d

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

demo/src/pick_place_task.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ void PickPlaceTask::loadParameters() {
144144
rosparam_shortcuts::shutdownIfError(LOGNAME, errors);
145145
}
146146

147+
// Initialize the task pipeline, defining individual movement stages
147148
bool PickPlaceTask::init() {
148149
ROS_INFO_NAMED(LOGNAME, "Initializing task pipeline");
149150
const std::string object = object_name_;
@@ -153,10 +154,13 @@ bool PickPlaceTask::init() {
153154
task_.reset();
154155
task_.reset(new moveit::task_constructor::Task());
155156

157+
// Individual movement stages are collected within the Task object
156158
Task& t = *task_;
157159
t.stages()->setName(task_name_);
158160
t.loadRobotModel();
159161

162+
/* Create planners used in various stages. Various options are available,
163+
namely Cartesian, MoveIt pipeline, and joint interpolation. */
160164
// Sampling planner
161165
auto sampling_planner = std::make_shared<solvers::PipelinePlanner>();
162166
sampling_planner->setProperty("goal_joint_tolerance", 1e-5);
@@ -201,7 +205,7 @@ bool PickPlaceTask::init() {
201205
* *
202206
***************************************************/
203207
Stage* initial_state_ptr = nullptr;
204-
{ // Open Hand
208+
{
205209
auto stage = std::make_unique<stages::MoveTo>("open hand", sampling_planner);
206210
stage->setGroup(hand_group_name_);
207211
stage->setGoal(hand_open_pose_);
@@ -214,7 +218,8 @@ bool PickPlaceTask::init() {
214218
* Move to Pick *
215219
* *
216220
***************************************************/
217-
{ // Move-to pre-grasp
221+
// Connect initial open-hand state with pre-grasp pose defined in the following
222+
{
218223
auto stage = std::make_unique<stages::Connect>(
219224
"move to pick", stages::Connect::GroupPlannerVector{ { arm_group_name_, sampling_planner } });
220225
stage->setTimeout(5.0);
@@ -229,6 +234,7 @@ bool PickPlaceTask::init() {
229234
***************************************************/
230235
Stage* pick_stage_ptr = nullptr;
231236
{
237+
// A SerialContainer combines several sub-stages, here for picking the object
232238
auto grasp = std::make_unique<SerialContainer>("pick object");
233239
t.properties().exposeTo(grasp->properties(), { "eef", "hand", "group", "ik_frame" });
234240
grasp->properties().configureInitFrom(Stage::PARENT, { "eef", "hand", "group", "ik_frame" });
@@ -237,10 +243,11 @@ bool PickPlaceTask::init() {
237243
---- * Approach Object *
238244
***************************************************/
239245
{
246+
// Move the eef link forward along its z-axis by an amount within the given min-max range
240247
auto stage = std::make_unique<stages::MoveRelative>("approach object", cartesian_planner);
241248
stage->properties().set("marker_ns", "approach_object");
242-
stage->properties().set("link", hand_frame_);
243-
stage->properties().configureInitFrom(Stage::PARENT, { "group" });
249+
stage->properties().set("link", hand_frame_); // link to perform IK for
250+
stage->properties().configureInitFrom(Stage::PARENT, { "group" }); // inherit group from parent stage
244251
stage->setMinMaxDistance(approach_object_min_dist_, approach_object_max_dist_);
245252

246253
// Set hand forward direction
@@ -255,29 +262,31 @@ bool PickPlaceTask::init() {
255262
---- * Generate Grasp Pose *
256263
***************************************************/
257264
{
258-
// Sample grasp pose
265+
// Sample grasp pose candidates in angle increments around the z-axis of the object
259266
auto stage = std::make_unique<stages::GenerateGraspPose>("generate grasp pose");
260267
stage->properties().configureInitFrom(Stage::PARENT);
261268
stage->properties().set("marker_ns", "grasp_pose");
262269
stage->setPreGraspPose(hand_open_pose_);
263-
stage->setObject(object);
270+
stage->setObject(object); // object to sample grasps for
264271
stage->setAngleDelta(M_PI / 12);
265272
stage->setMonitoredStage(initial_state_ptr); // hook into successful initial-phase solutions
266273

267-
// Compute IK
274+
// Compute IK for sampled grasp poses
268275
auto wrapper = std::make_unique<stages::ComputeIK>("grasp pose IK", std::move(stage));
269-
wrapper->setMaxIKSolutions(8);
276+
wrapper->setMaxIKSolutions(8); // limit number of solutions
270277
wrapper->setMinSolutionDistance(1.0);
271-
wrapper->setIKFrame(grasp_frame_transform_, hand_frame_);
272-
wrapper->properties().configureInitFrom(Stage::PARENT, { "eef", "group" });
273-
wrapper->properties().configureInitFrom(Stage::INTERFACE, { "target_pose" });
278+
wrapper->setIKFrame(grasp_frame_transform_, hand_frame_); // define virtual frame to reach the target_pose
279+
wrapper->properties().configureInitFrom(Stage::PARENT, { "eef", "group" }); // inherit properties from parent
280+
wrapper->properties().configureInitFrom(Stage::INTERFACE,
281+
{ "target_pose" }); // inherit property from child solution
274282
grasp->insert(std::move(wrapper));
275283
}
276284

277285
/****************************************************
278286
---- * Allow Collision (hand object) *
279287
***************************************************/
280288
{
289+
// Modify planning scene (w/o altering the robot's pose) to allow touching the object for picking
281290
auto stage = std::make_unique<stages::ModifyPlanningScene>("allow collision (hand,object)");
282291
stage->allowCollisions(
283292
object, t.getRobotModel()->getJointModelGroup(hand_group_name_)->getLinkModelNamesWithCollisionGeometry(),
@@ -300,7 +309,7 @@ bool PickPlaceTask::init() {
300309
***************************************************/
301310
{
302311
auto stage = std::make_unique<stages::ModifyPlanningScene>("attach object");
303-
stage->attachObject(object, hand_frame_);
312+
stage->attachObject(object, hand_frame_); // attach object to hand_frame_
304313
grasp->insert(std::move(stage));
305314
}
306315

@@ -352,6 +361,7 @@ bool PickPlaceTask::init() {
352361
* *
353362
*****************************************************/
354363
{
364+
// Connect the grasped state to the pre-place state, i.e. realize the object transport
355365
auto stage = std::make_unique<stages::Connect>(
356366
"move to place", stages::Connect::GroupPlannerVector{ { arm_group_name_, sampling_planner } });
357367
stage->setTimeout(5.0);
@@ -364,6 +374,7 @@ bool PickPlaceTask::init() {
364374
* Place Object *
365375
* *
366376
*****************************************************/
377+
// All placing sub-stages are collected within a serial container again
367378
{
368379
auto place = std::make_unique<SerialContainer>("place object");
369380
t.properties().exposeTo(place->properties(), { "eef", "hand", "group" });
@@ -498,13 +509,6 @@ bool PickPlaceTask::execute() {
498509
moveit_msgs::MoveItErrorCodes execute_result;
499510

500511
execute_result = task_->execute(*task_->solutions().front());
501-
// // If you want to inspect the goal message, use this instead:
502-
// actionlib::SimpleActionClient<moveit_task_constructor_msgs::ExecuteTaskSolutionAction>
503-
// execute("execute_task_solution", true); execute.waitForServer();
504-
// moveit_task_constructor_msgs::ExecuteTaskSolutionGoal execute_goal;
505-
// task_->solutions().front()->toMsg(execute_goal.solution);
506-
// execute.sendGoalAndWait(execute_goal);
507-
// execute_result = execute.getResult()->error_code;
508512

509513
if (execute_result.val != moveit_msgs::MoveItErrorCodes::SUCCESS) {
510514
ROS_ERROR_STREAM_NAMED(LOGNAME, "Task execution failed and returned: " << execute_result.val);

0 commit comments

Comments
 (0)