4
4
// Define the namespace to group related code together
5
5
namespace pnp
6
6
{
7
- PickandPlace::PickandPlace (ros::NodeHandle &nh) : move_group_interface_arm(PLANNING_GROUP_ARM), move_group_interface_gripper(PLANNING_GROUP_GRIPPER)
8
- {
7
+ PickandPlace::PickandPlace (ros::NodeHandle &nh)
8
+ {
9
9
// Set up a publisher for the pose point visualization marker
10
10
pose_point_pub = nh.advertise <visualization_msgs::Marker>(" pose_point" , 10 );
11
11
12
+ move_group_interface_arm = std::make_unique<moveit::planning_interface::MoveGroupInterface>(PLANNING_GROUP_ARM);
13
+ move_group_interface_gripper = std::make_unique<moveit::planning_interface::MoveGroupInterface>(PLANNING_GROUP_GRIPPER);
14
+
12
15
// Set the planning time for the arm movement
13
16
const double PLANNING_TIME = 15.0 ;
14
- move_group_interface_arm. setPlanningTime (PLANNING_TIME);
17
+ move_group_interface_arm-> setPlanningTime (PLANNING_TIME);
15
18
16
- // Use raw pointers for performance. These point to the joint model groups for the arm and gripper
17
- joint_model_group_arm = move_group_interface_arm.getCurrentState ()->getJointModelGroup (PLANNING_GROUP_ARM);
18
- joint_model_group_gripper = move_group_interface_gripper.getCurrentState ()->getJointModelGroup (PLANNING_GROUP_GRIPPER);
19
19
}
20
20
21
21
void PickandPlace::writeRobotDetails ()
22
22
{
23
23
// Print out the planning frame for the arm
24
- ROS_INFO_NAMED (" pnp" , " Planning frame: %s" , move_group_interface_arm. getPlanningFrame ().c_str ());
24
+ ROS_INFO_NAMED (" pnp" , " Planning frame: %s" , move_group_interface_arm-> getPlanningFrame ().c_str ());
25
25
26
26
// Get the link names for the arm and concatenate them into a single string, then print
27
- std::vector<std::string> linkNames = move_group_interface_arm. getLinkNames ();
27
+ std::vector<std::string> linkNames = move_group_interface_arm-> getLinkNames ();
28
28
std::string linkNamesArm = boost::algorithm::join (linkNames, " , " );
29
29
ROS_INFO_NAMED (" pnp" , " Arm links: %s" , linkNamesArm.c_str ());
30
30
31
31
// Get the joint names for the arm and concatenate them into a single string, then print
32
- std::vector<std::string> jointNamesArm = move_group_interface_arm. getJoints ();
32
+ std::vector<std::string> jointNamesArm = move_group_interface_arm-> getJoints ();
33
33
std::string jointNamesArmString = boost::algorithm::join (jointNamesArm, " , " );
34
34
ROS_INFO_NAMED (" pnp" , " Arm joint names: %s" , jointNamesArmString.c_str ());
35
35
36
36
// Get the joint names for the gripper and concatenate them into a single string, then print
37
- std::vector<std::string> jointNamesGripper = move_group_interface_gripper. getJoints ();
37
+ std::vector<std::string> jointNamesGripper = move_group_interface_gripper-> getJoints ();
38
38
std::string jointNamesGripperString = boost::algorithm::join (jointNamesGripper, " , " );
39
39
ROS_INFO_NAMED (" pnp" , " Gripper joints names: %s" , jointNamesGripperString.c_str ());
40
40
41
41
// Get the list of all available planning groups, concatenate them into a single string, then print
42
- std::vector<std::string> planningGroups = move_group_interface_arm. getJointModelGroupNames ();
42
+ std::vector<std::string> planningGroups = move_group_interface_arm-> getJointModelGroupNames ();
43
43
std::string planningGroupsString = boost::algorithm::join (planningGroups, " , " );
44
44
ROS_INFO_NAMED (" pnp" , " Available Planning Groups: %s" , planningGroupsString.c_str ());
45
45
46
46
47
47
// Get the home joint values and print them out
48
- home_joint_values = move_group_interface_arm. getCurrentJointValues ();
48
+ home_joint_values = move_group_interface_arm-> getCurrentJointValues ();
49
49
std::string jointValuesString;
50
50
for (const auto &joint : home_joint_values)
51
51
{
@@ -184,10 +184,10 @@ namespace pnp
184
184
add_pose_arrow (pose_target.position , rotation_rads[2 ]);
185
185
186
186
// set the pose target
187
- move_group_interface_arm. setPoseTarget (pose_target);
187
+ move_group_interface_arm-> setPoseTarget (pose_target);
188
188
189
189
// move to arm to the target pose
190
- bool success = (move_group_interface_arm. plan (plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
190
+ bool success = (move_group_interface_arm-> plan (plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
191
191
192
192
// print if the arm was able to move to the target pose
193
193
ROS_INFO_NAMED (" pnp" , " Moving to pose target %s" , success ? " " : " FAILED" );
@@ -254,25 +254,25 @@ namespace pnp
254
254
void PickandPlace::go_to_home_position ()
255
255
{
256
256
// uses the home_joint_value variable to go to the home position of the robot
257
- move_group_interface_arm. setJointValueTarget (home_joint_values);
257
+ move_group_interface_arm-> setJointValueTarget (home_joint_values);
258
258
259
259
// move to arm to the target pose
260
- bool success = (move_group_interface_arm. plan (plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
260
+ bool success = (move_group_interface_arm-> plan (plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
261
261
262
262
// print if the arm was able to move to the target pose
263
263
ROS_INFO_NAMED (" pnp" , " Moving to home position %s" , success ? " " : " FAILED" );
264
264
265
265
// move the arm to the target pose
266
- move_group_interface_arm. move ();
266
+ move_group_interface_arm-> move ();
267
267
268
268
}
269
269
270
270
void PickandPlace::open_gripper (){
271
271
// Set the joint value target for the gripper
272
- move_group_interface_gripper. setJointValueTarget (OPEN_GRIPPER);
273
- bool success = (move_group_interface_gripper. plan (plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
272
+ move_group_interface_gripper-> setJointValueTarget (OPEN_GRIPPER);
273
+ bool success = (move_group_interface_gripper-> plan (plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
274
274
ROS_INFO_NAMED (" pnp" , " Opening gripper %s" , success ? " " : " FAILED" );
275
- move_group_interface_gripper. move ();
275
+ move_group_interface_gripper-> move ();
276
276
277
277
}
278
278
@@ -298,17 +298,17 @@ namespace pnp
298
298
set_pose_target (rod_position, {45 , 90 , 45 });
299
299
300
300
// execute the plan
301
- move_group_interface_arm. move ();
301
+ move_group_interface_arm-> move ();
302
302
303
- std::cout << " Press enter to continue... " ;
303
+ ROS_INFO_NAMED ( " pnp " , " Target Reached - Press any button to continue" ) ;
304
304
std::cin.ignore ();
305
305
306
306
// reset
307
307
go_to_home_position ();
308
308
clean_scene ();
309
309
remove_pose_arrow ();
310
310
311
- std::cout << " Press enter to exit... " ;
311
+ ROS_INFO_NAMED ( " pnp " , " Simulation Complete - Press any button to exit" ) ;
312
312
std::cin.ignore ();
313
313
314
314
}
0 commit comments