1
- #include " panda_moveit/pick_and_place.hpp"
1
+ #include " ../include/panda_moveit/pick_and_place.hpp"
2
+
2
3
namespace pnp
3
4
{
4
5
// The init function
@@ -7,7 +8,7 @@ namespace pnp
7
8
pose_point_pub = nh.advertise <visualization_msgs::Marker>(" pose_point" , 10 );
8
9
9
10
// set arm planning time
10
- const double PLANNING_TIME = 5 .0 ;
11
+ const double PLANNING_TIME = 15 .0 ;
11
12
move_group_interface_arm.setPlanningTime (PLANNING_TIME);
12
13
13
14
// Raw pointers are frequently used to refer to the planning group for improved performance.
@@ -21,43 +22,24 @@ namespace pnp
21
22
ROS_INFO_NAMED (" pnp" , " Planning frame: %s" , move_group_interface_arm.getPlanningFrame ().c_str ());
22
23
23
24
std::vector<std::string> linkNames = move_group_interface_arm.getLinkNames ();
24
- std::string linkNamesArm;
25
- for (const auto &link : linkNames)
26
- {
27
- linkNamesArm += link + " , " ;
28
- }
25
+ std::string linkNamesArm = boost::algorithm::join (linkNames, " , " );
29
26
ROS_INFO_NAMED (" pnp" , " Arm links: %s" , linkNamesArm.c_str ());
30
27
31
28
// ROS_INFO_NAMED the arm joint names
32
29
std::vector<std::string> jointNamesArm = move_group_interface_arm.getJoints ();
33
- std::string jointNamesArmString;
34
- for (const auto &joint : jointNamesArm)
35
- {
36
- jointNamesArmString += joint + " , " ;
37
- }
30
+ std::string jointNamesArmString = boost::algorithm::join (jointNamesArm, " , " );
38
31
ROS_INFO_NAMED (" pnp" , " Arm joint names: %s" , jointNamesArmString.c_str ());
39
32
40
33
// ROS_INFO_NAMED the gripper joint names
41
34
std::vector<std::string> jointNamesGripper = move_group_interface_gripper.getJoints ();
42
- std::string jointNamesGripperString;
43
- for (const auto &joint : jointNamesGripper)
44
- {
45
- jointNamesGripperString += joint + " , " ;
46
- }
47
-
35
+ std::string jointNamesGripperString = boost::algorithm::join (jointNamesGripper, " , " );
48
36
ROS_INFO_NAMED (" pnp" , " Gripper joints names: %s" , jointNamesGripperString.c_str ());
49
37
50
38
// We can get a list of all the groups in the robot:
51
39
std::vector<std::string> planningGroups = move_group_interface_arm.getJointModelGroupNames ();
52
- std::string planningGroupsString;
53
- for (const auto &groups : planningGroups)
54
- {
55
- planningGroupsString += groups + " , " ;
56
- }
40
+ std::string planningGroupsString = boost::algorithm::join (planningGroups, " , " );
57
41
ROS_INFO_NAMED (" pnp" , " Available Planning Groups: %s" , planningGroupsString.c_str ());
58
- // Add a delay before calling getCurrentJointValues()
59
- ros::Duration (1.0 ).sleep ();
60
-
42
+
61
43
// using getJointStates to get the current joint values put in a block to print the error
62
44
home_joint_values = move_group_interface_arm.getCurrentJointValues ();
63
45
std::string jointValuesString;
@@ -67,8 +49,6 @@ namespace pnp
67
49
}
68
50
ROS_INFO_NAMED (" pnp" , " Current joint values: %s" , jointValuesString.c_str ());
69
51
70
- // add a sleep
71
- // ros::Duration(1000.0).sleep();
72
52
}
73
53
74
54
void PickandPlace::createCollisionObject (std::string id, std::vector<double > dimensions, std::vector<double > position, double rotation_z)
@@ -168,13 +148,22 @@ namespace pnp
168
148
homogeneous_mat_arm (1 , 3 ) = translation[1 ];
169
149
homogeneous_mat_arm (2 , 3 ) = translation[2 ];
170
150
151
+ // print the homogeneous matrix of the arm
152
+ ROS_INFO_STREAM_NAMED (" pnp" , " homogeneous_mat_arm: \n " << homogeneous_mat_arm);
153
+
171
154
// Create a homogeneous transformation matrix for the end effector with no rotation
172
155
Eigen::Matrix4d homogeneous_trans_end_effector = Eigen::Matrix4d::Identity ();
173
156
homogeneous_trans_end_effector (2 , 3 ) = end_effector_palm_length;
174
157
158
+ // print the homogeneous matrix of the end effector
159
+ ROS_INFO_STREAM_NAMED (" pnp" , " homogeneous_translation_end_effector: \n " << homogeneous_trans_end_effector);
160
+
175
161
// Multiply the homogeneous transformation matrix of the arm by the inverse of the homogeneous transformation matrix of the end effector
176
162
Eigen::Matrix4d homogeneous_mat = homogeneous_mat_arm * homogeneous_trans_end_effector.inverse ();
177
163
164
+ // print the homogeneous matrix of the adjusted homogenous matrix
165
+ ROS_INFO_STREAM_NAMED (" pnp" , " homogeneous_mat: \n " << homogeneous_mat);
166
+
178
167
// Create a quaternion from euler angles
179
168
tf2::Quaternion quaternion;
180
169
// get a quaternion from the rotation matrix R
@@ -184,10 +173,7 @@ namespace pnp
184
173
185
174
// Create message types for the pose target
186
175
geometry_msgs::Quaternion orientation;
187
- orientation.x = quaternion.x ();
188
- orientation.y = quaternion.y ();
189
- orientation.z = quaternion.z ();
190
- orientation.w = quaternion.w ();
176
+ orientation = tf2::toMsg (quaternion);
191
177
192
178
geometry_msgs::Point position;
193
179
position.x = homogeneous_mat (0 , 3 );
@@ -202,7 +188,11 @@ namespace pnp
202
188
// add pose arrow
203
189
add_pose_arrow (pose_target.position , rotation_rads[2 ]);
204
190
205
- // set the target pose
191
+
192
+ // print the target pose
193
+ ROS_INFO_STREAM_NAMED (" pnp" , " pose_target: \n " << pose_target);
194
+
195
+ // set the pose target
206
196
move_group_interface_arm.setPoseTarget (pose_target);
207
197
208
198
// print target pose successfully set
@@ -212,10 +202,8 @@ namespace pnp
212
202
bool success = (move_group_interface_arm.plan (plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
213
203
214
204
// print if the arm was able to move to the target pose
215
- ROS_INFO_NAMED (" pnp" , " Visualizing plan 1 ( pose goal) %s" , success ? " " : " FAILED" );
205
+ ROS_INFO_NAMED (" pnp" , " Moving to pose target %s" , success ? " " : " FAILED" );
216
206
217
- // execute the plan
218
- move_group_interface_arm.move ();
219
207
}
220
208
221
209
void PickandPlace::add_pose_arrow (geometry_msgs::Point desired_position, float z_rotation)
@@ -240,6 +228,17 @@ namespace pnp
240
228
geometry_msgs::Pose Pose;
241
229
Pose.position = desired_position;
242
230
Pose.orientation = tf2::toMsg (quaternion);
231
+
232
+ // print the desired pose for debugging
233
+ ROS_INFO_STREAM_NAMED (" pnp" , " desired pose: \n "
234
+ << " x: " << Pose.position .x << " \n "
235
+ << " y: " << Pose.position .y << " \n "
236
+ << " z: " << Pose.position .z << " \n "
237
+ << " x: " << Pose.orientation .x << " \n "
238
+ << " y: " << Pose.orientation .y << " \n "
239
+ << " z: " << Pose.orientation .z << " \n "
240
+ << " w: " << Pose.orientation .w );
241
+
243
242
marker.pose = Pose;
244
243
245
244
// Publish the marker
@@ -286,6 +285,15 @@ namespace pnp
286
285
// print rod position
287
286
ROS_INFO_NAMED (" pnp" , " Rod position: %f, %f, %f" , rod_position[0 ], rod_position[1 ], rod_position[2 ]);
288
287
289
- ros::Duration (2.0 ).sleep ();
288
+ // set pose target
289
+ set_pose_target (rod_position, {45 , 90 , 45 });
290
+
291
+ // execute the plan
292
+ move_group_interface_arm.move ();
293
+
294
+ // sleep for 10000 seconds for debugging
295
+ ros::Duration (10000 ).sleep ();
296
+
297
+
290
298
}
291
299
};
0 commit comments