@@ -116,6 +116,9 @@ int main(int argc, char** argv)
116
116
std::copy (move_group_interface.getJointModelGroupNames ().begin (),
117
117
move_group_interface.getJointModelGroupNames ().end (), std::ostream_iterator<std::string>(std::cout, " , " ));
118
118
119
+ // We can get the current state of the robot as well
120
+ moveit::core::RobotStatePtr initial_state = move_group_interface.getCurrentState ();
121
+
119
122
// Start the demo
120
123
// ^^^^^^^^^^^^^^^^^^^^^^^^^
121
124
visual_tools.prompt (" Press 'next' in the RvizVisualToolsGui window to start the demo" );
@@ -152,56 +155,11 @@ int main(int argc, char** argv)
152
155
visual_tools.trigger ();
153
156
visual_tools.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
154
157
155
- // Finally, to execute the trajectory stored in my_plan, you could use the following method call.
156
- // Note that this can lead to problems if the robot moved in the meanwhile.
157
- // This tutorial does not actually move the robot, so this line is commented out
158
-
159
- /* move_group_interface.execute(my_plan); */
160
-
161
158
// Moving to a pose goal
162
159
// ^^^^^^^^^^^^^^^^^^^^^
163
- //
164
- // If you do not want to inspect the planned trajectory,
165
- // the following is a more robust combination of the two-step plan+execute pattern shown above
166
- // and should be preferred. Note that the pose goal we had set earlier is still active,
167
- // so the robot will try to move to that goal.
168
- // This tutorial does not actually move the robot, so this line is commented out
169
-
170
- /* move_group_interface.move(); */
171
-
172
- // Planning to a joint-space goal
173
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
174
- //
175
- // Let's set a joint space goal and move towards it. This will replace the
176
- // pose target we set above.
177
- //
178
- // To start, we'll create an pointer that references the current robot's state.
179
- // RobotState is the object that contains all the current position/velocity/acceleration data.
180
- moveit::core::RobotStatePtr current_state = move_group_interface.getCurrentState ();
181
- //
182
- // Next get the current set of joint values for the group.
183
- std::vector<double > joint_group_positions;
184
- current_state->copyJointGroupPositions (joint_model_group, joint_group_positions);
185
-
186
- // Now, let's modify one of the joints, plan to the new joint space goal and visualize the plan.
187
- joint_group_positions[0 ] = -tau / 6 ; // -1/6 turn in radians
188
- move_group_interface.setJointValueTarget (joint_group_positions);
189
-
190
- // We lower the allowed maximum velocity and acceleration to 5% of their maximum.
191
- // The default values are 10% (0.1).
192
- // Set your preferred defaults in the joint_limits.yaml file of your robot's moveit_config
193
- // or set explicit factors in your code if you need your robot to move faster.
194
- move_group_interface.setMaxVelocityScalingFactor (0.05 );
195
- move_group_interface.setMaxAccelerationScalingFactor (0.05 );
196
-
197
- success = (move_group_interface.plan (my_plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
198
- ROS_INFO_NAMED (" tutorial" , " Visualizing plan 2 (joint space goal) %s" , success ? " " : " FAILED" );
199
-
200
- // Visualize the plan in RViz
201
- visual_tools.deleteAllMarkers ();
202
- visual_tools.publishText (text_pose, " Joint Space Goal" , rvt::WHITE, rvt::XLARGE);
203
- visual_tools.publishTrajectoryLine (my_plan.trajectory_ , joint_model_group);
204
- visual_tools.trigger ();
160
+ // Finally, to execute the trajectory stored in :code:`my_plan`, you can use the following method call.
161
+ // Note that this can lead to problems if the robot moved between planning and this call.
162
+ move_group_interface.execute (my_plan);
205
163
visual_tools.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
206
164
207
165
// Planning with Path Constraints
@@ -240,22 +198,18 @@ int main(int argc, char** argv)
240
198
// sampling to find valid requests. Please note that this might
241
199
// increase planning time considerably.
242
200
//
243
- // We will reuse the old goal that we had and plan to it .
201
+ // We will plan to a new pose goal .
244
202
// Note that this will only work if the current state already
245
- // satisfies the path constraints. So we need to set the start
246
- // state to a new pose.
247
- moveit::core::RobotState start_state (*move_group_interface.getCurrentState ());
248
- geometry_msgs::Pose start_pose2;
249
- start_pose2.orientation .w = 1.0 ;
250
- start_pose2.position .x = 0.55 ;
251
- start_pose2.position .y = -0.05 ;
252
- start_pose2.position .z = 0.8 ;
253
- start_state.setFromIK (joint_model_group, start_pose2);
254
- move_group_interface.setStartState (start_state);
255
-
256
- // Now we will plan to the earlier pose target from the new
257
- // start state that we have just created.
258
- move_group_interface.setPoseTarget (target_pose1);
203
+ // satisfies the path constraints.
204
+ geometry_msgs::Pose target_pose2;
205
+ target_pose2.orientation .w = 1.0 ;
206
+ target_pose2.position .x = 0.55 ;
207
+ target_pose2.position .y = -0.05 ;
208
+ target_pose2.position .z = 0.8 ;
209
+
210
+ // Now we will plan from the current state to the new target pose that we have just created.
211
+ move_group_interface.setStartStateToCurrentState ();
212
+ move_group_interface.setPoseTarget (target_pose2);
259
213
260
214
// Planning with constraints can be slow because every sample must call an inverse kinematics solver.
261
215
// Lets increase the planning time from the default 5 seconds to be sure the planner has enough time to succeed.
@@ -266,12 +220,16 @@ int main(int argc, char** argv)
266
220
267
221
// Visualize the plan in RViz
268
222
visual_tools.deleteAllMarkers ();
269
- visual_tools.publishAxisLabeled (start_pose2 , " start" );
223
+ visual_tools.publishAxisLabeled (target_pose2 , " start" );
270
224
visual_tools.publishAxisLabeled (target_pose1, " goal" );
271
225
visual_tools.publishText (text_pose, " Constrained Goal" , rvt::WHITE, rvt::XLARGE);
272
226
visual_tools.publishTrajectoryLine (my_plan.trajectory_ , joint_model_group);
273
227
visual_tools.trigger ();
274
- visual_tools.prompt (" next step" );
228
+ visual_tools.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
229
+
230
+ // Execute the previous plan
231
+ move_group_interface.execute (my_plan);
232
+ visual_tools.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
275
233
276
234
// When done with the path constraint be sure to clear it.
277
235
move_group_interface.clearPathConstraints ();
@@ -280,12 +238,10 @@ int main(int argc, char** argv)
280
238
// ^^^^^^^^^^^^^^^
281
239
// You can plan a Cartesian path directly by specifying a list of waypoints
282
240
// for the end-effector to go through. Note that we are starting
283
- // from the new start state above. The initial pose (start state) does not
241
+ // from the new start target above. The initial pose (start state) does not
284
242
// need to be added to the waypoint list but adding it can help with visualizations
285
243
std::vector<geometry_msgs::Pose> waypoints;
286
- waypoints.push_back (start_pose2);
287
-
288
- geometry_msgs::Pose target_pose3 = start_pose2;
244
+ geometry_msgs::Pose target_pose3 = target_pose2;
289
245
290
246
target_pose3.position .z -= 0.2 ;
291
247
waypoints.push_back (target_pose3); // down
@@ -322,10 +278,38 @@ int main(int argc, char** argv)
322
278
// plans cannot currently be set through the maxVelocityScalingFactor, but requires you to time
323
279
// the trajectory manually, as described `here <https://groups.google.com/forum/#!topic/moveit-users/MOoFxy2exT4>`_.
324
280
// Pull requests are welcome.
281
+ move_group_interface.execute (trajectory);
282
+ visual_tools.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
283
+
284
+ // Planning to a joint-space goal
285
+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
325
286
//
326
- // You can execute a trajectory like this. This tutorial does not actually move the robot, so this line is commented out
287
+ // Let's set a joint space goal and move towards it. We will pick the initial state the robot started in at the
288
+ // beginning of the tutorial
289
+ std::vector<double > joint_group_positions;
290
+ initial_state->copyJointGroupPositions (joint_model_group, joint_group_positions);
291
+
292
+ // We can directly set a joint state target
293
+ move_group_interface.setJointValueTarget (joint_group_positions);
294
+ move_group_interface.setStartStateToCurrentState ();
295
+
296
+ // We lower the allowed maximum velocity and acceleration to 5% of their maximum.
297
+ // The default values are 10% (0.1).
298
+ // Set your preferred defaults in the joint_limits.yaml file of your robot's moveit_config
299
+ // or set explicit factors in your code if you need your robot to move faster.
300
+ move_group_interface.setMaxVelocityScalingFactor (0.05 );
301
+ move_group_interface.setMaxAccelerationScalingFactor (0.05 );
327
302
328
- /* move_group_interface.execute(trajectory); */
303
+ // Visualize the plan in RViz
304
+ visual_tools.deleteAllMarkers ();
305
+ visual_tools.publishText (text_pose, " Joint Space Move" , rvt::WHITE, rvt::XLARGE);
306
+ visual_tools.trigger ();
307
+ visual_tools.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
308
+
309
+ // If you do not want to inspect the planned trajectory, the following is a more robust combination of the two-step
310
+ // plan+execute pattern shown above and should be preferred.
311
+ move_group_interface.move ();
312
+ visual_tools.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
329
313
330
314
// Adding objects to the environment
331
315
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0 commit comments