4646#include < tf2_geometry_msgs/tf2_geometry_msgs.h>
4747#include < tf2_eigen/tf2_eigen.h>
4848
49+ // The circle constant tau = 2*pi. One tau is one rotation in radians.
50+ const double tau = 2 * M_PI;
51+
4952// BEGIN_SUB_TUTORIAL plan1
5053//
5154// Creating the planning request
@@ -121,35 +124,35 @@ void spawnCollisionObjects(moveit::planning_interface::PlanningSceneInterface& p
121124 box.subframe_poses [0 ].position .z = 0.0 + z_offset_box;
122125
123126 tf2::Quaternion orientation;
124- orientation.setRPY (90.0 / 180.0 * M_PI , 0 , 0 );
127+ orientation.setRPY (tau / 4 , 0 , 0 ); // A quarter turn about the x-axis
125128 box.subframe_poses [0 ].orientation = tf2::toMsg (orientation);
126129 // END_SUB_TUTORIAL
127130
128131 box.subframe_names [1 ] = " top" ;
129132 box.subframe_poses [1 ].position .y = .05 ;
130133 box.subframe_poses [1 ].position .z = 0.0 + z_offset_box;
131- orientation.setRPY (-90.0 / 180.0 * M_PI , 0 , 0 );
134+ orientation.setRPY (-tau / 4 , 0 , 0 );
132135 box.subframe_poses [1 ].orientation = tf2::toMsg (orientation);
133136
134137 box.subframe_names [2 ] = " corner_1" ;
135138 box.subframe_poses [2 ].position .x = -.025 ;
136139 box.subframe_poses [2 ].position .y = -.05 ;
137140 box.subframe_poses [2 ].position .z = -.01 + z_offset_box;
138- orientation.setRPY (90.0 / 180.0 * M_PI , 0 , 0 );
141+ orientation.setRPY (tau / 4 , 0 , 0 );
139142 box.subframe_poses [2 ].orientation = tf2::toMsg (orientation);
140143
141144 box.subframe_names [3 ] = " corner_2" ;
142145 box.subframe_poses [3 ].position .x = .025 ;
143146 box.subframe_poses [3 ].position .y = -.05 ;
144147 box.subframe_poses [3 ].position .z = -.01 + z_offset_box;
145- orientation.setRPY (90.0 / 180.0 * M_PI , 0 , 0 );
148+ orientation.setRPY (tau / 4 , 0 , 0 );
146149 box.subframe_poses [3 ].orientation = tf2::toMsg (orientation);
147150
148151 box.subframe_names [4 ] = " side" ;
149152 box.subframe_poses [4 ].position .x = .0 ;
150153 box.subframe_poses [4 ].position .y = .0 ;
151154 box.subframe_poses [4 ].position .z = -.01 + z_offset_box;
152- orientation.setRPY (0 , 180.0 / 180.0 * M_PI , 0 );
155+ orientation.setRPY (0 , tau / 2 , 0 );
153156 box.subframe_poses [4 ].orientation = tf2::toMsg (orientation);
154157
155158 // Next, define the cylinder
@@ -165,7 +168,7 @@ void spawnCollisionObjects(moveit::planning_interface::PlanningSceneInterface& p
165168 cylinder.primitive_poses [0 ].position .x = 0.0 ;
166169 cylinder.primitive_poses [0 ].position .y = 0.0 ;
167170 cylinder.primitive_poses [0 ].position .z = 0.0 + z_offset_cylinder;
168- orientation.setRPY (0 , 90.0 / 180.0 * M_PI , 0 );
171+ orientation.setRPY (0 , tau / 4 , 0 );
169172 cylinder.primitive_poses [0 ].orientation = tf2::toMsg (orientation);
170173
171174 cylinder.subframe_poses .resize (1 );
@@ -174,7 +177,7 @@ void spawnCollisionObjects(moveit::planning_interface::PlanningSceneInterface& p
174177 cylinder.subframe_poses [0 ].position .x = 0.03 ;
175178 cylinder.subframe_poses [0 ].position .y = 0.0 ;
176179 cylinder.subframe_poses [0 ].position .z = 0.0 + z_offset_cylinder;
177- orientation.setRPY (0 , 90.0 / 180.0 * M_PI , 0 );
180+ orientation.setRPY (0 , tau / 4 , 0 );
178181 cylinder.subframe_poses [0 ].orientation = tf2::toMsg (orientation);
179182
180183 // BEGIN_SUB_TUTORIAL object2
@@ -282,7 +285,7 @@ int main(int argc, char** argv)
282285 fixed_pose.header .frame_id = " panda_link0" ;
283286 fixed_pose.pose .position .y = -.4 ;
284287 fixed_pose.pose .position .z = .3 ;
285- target_orientation.setRPY (0 , (-20.0 / 180 .0 * M_PI ), 0 );
288+ target_orientation.setRPY (0 , (-20.0 / 360 .0 * tau ), 0 );
286289 fixed_pose.pose .orientation = tf2::toMsg (target_orientation);
287290
288291 // Set up a small command line interface to make the tutorial interactive.
@@ -316,7 +319,7 @@ int main(int argc, char** argv)
316319 // The target pose is given relative to a box subframe:
317320 target_pose.header .frame_id = " box/bottom" ;
318321 // The orientation is determined by RPY angles to align the cylinder and box subframes:
319- target_orientation.setRPY (0 , 180.0 / 180.0 * M_PI, 90.0 / 180.0 * M_PI );
322+ target_orientation.setRPY (0 , tau / 2 , tau / 4 );
320323 target_pose.pose .orientation = tf2::toMsg (target_orientation);
321324 // To keep some distance to the box, we use a small offset:
322325 target_pose.pose .position .z = 0.01 ;
@@ -330,7 +333,7 @@ int main(int argc, char** argv)
330333 {
331334 ROS_INFO_STREAM (" Moving to top of box with cylinder tip" );
332335 target_pose.header .frame_id = " box/top" ;
333- target_orientation.setRPY (180.0 / 180.0 * M_PI , 0 , 90.0 / 180.0 * M_PI );
336+ target_orientation.setRPY (tau / 2 , 0 , tau / 4 );
334337 target_pose.pose .orientation = tf2::toMsg (target_orientation);
335338 target_pose.pose .position .z = 0.01 ;
336339 showFrames (target_pose, " cylinder/tip" );
@@ -341,7 +344,7 @@ int main(int argc, char** argv)
341344 {
342345 ROS_INFO_STREAM (" Moving to corner1 of box with cylinder tip" );
343346 target_pose.header .frame_id = " box/corner_1" ;
344- target_orientation.setRPY (0 , 180.0 / 180.0 * M_PI, 90.0 / 180.0 * M_PI );
347+ target_orientation.setRPY (0 , tau / 2 , tau / 4 );
345348 target_pose.pose .orientation = tf2::toMsg (target_orientation);
346349 target_pose.pose .position .z = 0.01 ;
347350 showFrames (target_pose, " cylinder/tip" );
@@ -350,7 +353,7 @@ int main(int argc, char** argv)
350353 else if (character_input == 4 )
351354 {
352355 target_pose.header .frame_id = " box/corner_2" ;
353- target_orientation.setRPY (0 , 180.0 / 180.0 * M_PI, 90.0 / 180.0 * M_PI );
356+ target_orientation.setRPY (0 , tau / 2 , tau / 4 );
354357 target_pose.pose .orientation = tf2::toMsg (target_orientation);
355358 target_pose.pose .position .z = 0.01 ;
356359 showFrames (target_pose, " cylinder/tip" );
@@ -359,7 +362,7 @@ int main(int argc, char** argv)
359362 else if (character_input == 5 )
360363 {
361364 target_pose.header .frame_id = " box/side" ;
362- target_orientation.setRPY (0 , 180.0 / 180.0 * M_PI, 90.0 / 180.0 * M_PI );
365+ target_orientation.setRPY (0 , tau / 2 , tau / 4 );
363366 target_pose.pose .orientation = tf2::toMsg (target_orientation);
364367 target_pose.pose .position .z = 0.01 ;
365368 showFrames (target_pose, " cylinder/tip" );
0 commit comments