@@ -224,6 +224,135 @@ def test_joint_angles_duration_0(self): # https://github.com/start-jsk/rtmros_co
224
224
rospy .logwarn ("difference between two angles %r %r" % (array ([30 ,30 ,30 ,- 90 ,- 40 ,- 30 ])- array (goal_angles ),linalg .norm (array ([30 ,30 ,30 ,- 90 ,- 40 ,- 30 ])- array (goal_angles ))))
225
225
self .assertAlmostEqual (linalg .norm (array ([30 ,30 ,30 ,- 90 ,- 40 ,- 30 ])- array (goal_angles )), 0 , delta = 0.1 )
226
226
227
+ # https://github.com/start-jsk/rtmros_common/pull/765#issuecomment-120208947
228
+ def test_jta_cancel_goal (self ):
229
+ # for < kinetic
230
+ if os .environ ['ROS_DISTRO' ] >= 'kinetic' :
231
+ return True
232
+ from pr2_controllers_msgs .msg import JointTrajectoryAction , JointTrajectoryGoal
233
+ larm = actionlib .SimpleActionClient ("/larm_controller/joint_trajectory_action" , JointTrajectoryAction )
234
+ self .impl_test_jta_cancel_goal (larm , JointTrajectoryGoal ())
235
+
236
+ def test_fjta_cancel_goal (self ):
237
+ # for >= kinetic
238
+ if os .environ ['ROS_DISTRO' ] < 'kinetic' :
239
+ return True
240
+ from control_msgs .msg import FollowJointTrajectoryAction , FollowJointTrajectoryGoal
241
+ larm = actionlib .SimpleActionClient ("/larm_controller/follow_joint_trajectory_action" , FollowJointTrajectoryAction )
242
+ self .impl_test_jta_cancel_goal (larm , FollowJointTrajectoryGoal ())
243
+
244
+ def impl_test_jta_cancel_goal (self , larm , goal ):
245
+ larm .wait_for_server ()
246
+
247
+ # initialize
248
+ goal .trajectory .header .stamp = rospy .get_rostime ()
249
+ goal .trajectory .joint_names .append ("LARM_SHOULDER_P" )
250
+ goal .trajectory .joint_names .append ("LARM_SHOULDER_R" )
251
+ goal .trajectory .joint_names .append ("LARM_SHOULDER_Y" )
252
+ goal .trajectory .joint_names .append ("LARM_ELBOW" )
253
+ goal .trajectory .joint_names .append ("LARM_WRIST_Y" )
254
+ goal .trajectory .joint_names .append ("LARM_WRIST_P" )
255
+ point = JointTrajectoryPoint ()
256
+ point .positions = [0 ,0 ,0 ,0 ,0 ,0 ]
257
+ point .time_from_start = rospy .Duration (5.0 )
258
+ goal .trajectory .points .append (point )
259
+ larm .send_goal (goal )
260
+ larm .wait_for_result ()
261
+
262
+ try :
263
+ self .listener .waitForTransform ('/WAIST_LINK0' , '/LARM_LINK7' , rospy .Time (), rospy .Duration (120 ))
264
+ except tf .Exception :
265
+ self .assertTrue (None , "could not found tf from /WAIST_LINK0 to /LARM_LINK7" )
266
+ goal .trajectory .header .stamp = rospy .get_rostime ()
267
+ point .positions = [ x * math .pi / 180.0 for x in [20 ,20 ,20 ,20 ,20 ,20 ] ]
268
+ point .time_from_start = rospy .Duration (5.0 )
269
+ del goal .trajectory .points [:]
270
+ goal .trajectory .points .append (point )
271
+ larm .send_goal (goal )
272
+ rospy .sleep (2.5 )
273
+ (trans1 ,rot1 ) = self .listener .lookupTransform ('/WAIST_LINK0' , '/LARM_LINK7' , rospy .Time (0 ))
274
+ rospy .logwarn ("tf_echo /WAIST_LINK0 /LARM_LINK7 %r %r" % (trans1 ,rot1 ))
275
+ larm .cancel_goal ()
276
+ rospy .sleep (2.5 )
277
+ (trans2 ,rot2 ) = self .listener .lookupTransform ('/WAIST_LINK0' , '/LARM_LINK7' , rospy .Time (0 ))
278
+ rospy .logwarn ("tf_echo /WAIST_LINK0 /LARM_LINK7 %r %r" % (trans2 ,rot2 ))
279
+ larm .wait_for_result ()
280
+ rospy .logwarn ("difference between two /LARM_LINK7 %r %r" % (array (trans1 )- array (trans2 ),linalg .norm (array (trans1 )- array (trans2 ))))
281
+ self .assertAlmostEqual (linalg .norm (array (trans1 )- array (trans2 )), 0 , delta = 0.1 )
282
+
283
+ # https://github.com/start-jsk/rtmros_common/pull/765#issuecomment-392741195
284
+ def test_jta_overwrite_goal (self ):
285
+ # for < kinetic
286
+ if os .environ ['ROS_DISTRO' ] >= 'kinetic' :
287
+ return True
288
+ from pr2_controllers_msgs .msg import JointTrajectoryAction , JointTrajectoryGoal
289
+ larm = actionlib .SimpleActionClient ("/larm_controller/joint_trajectory_action" , JointTrajectoryAction )
290
+ self .impl_test_jta_overwrite_goal (larm , JointTrajectoryGoal ())
291
+
292
+ def test_fjta_overwrite_goal (self ):
293
+ # for >= kinetic
294
+ if os .environ ['ROS_DISTRO' ] < 'kinetic' :
295
+ return True
296
+ from control_msgs .msg import FollowJointTrajectoryAction , FollowJointTrajectoryGoal
297
+ larm = actionlib .SimpleActionClient ("/larm_controller/follow_joint_trajectory_action" , FollowJointTrajectoryAction )
298
+ self .impl_test_jta_overwrite_goal (larm , FollowJointTrajectoryGoal ())
299
+
300
+ def impl_test_jta_overwrite_goal (self , larm , goal ):
301
+ larm .wait_for_server ()
302
+
303
+ # initialize
304
+ goal .trajectory .header .stamp = rospy .get_rostime ()
305
+ goal .trajectory .joint_names .append ("LARM_SHOULDER_P" )
306
+ goal .trajectory .joint_names .append ("LARM_SHOULDER_R" )
307
+ goal .trajectory .joint_names .append ("LARM_SHOULDER_Y" )
308
+ goal .trajectory .joint_names .append ("LARM_ELBOW" )
309
+ goal .trajectory .joint_names .append ("LARM_WRIST_Y" )
310
+ goal .trajectory .joint_names .append ("LARM_WRIST_P" )
311
+ point = JointTrajectoryPoint ()
312
+ point .positions = [0 ,0 ,0 ,0 ,0 ,0 ]
313
+ point .time_from_start = rospy .Duration (5.0 )
314
+ goal .trajectory .points .append (point )
315
+ larm .send_goal (goal )
316
+ larm .wait_for_result ()
317
+
318
+ try :
319
+ self .listener .waitForTransform ('/WAIST_LINK0' , '/LARM_LINK7' , rospy .Time (), rospy .Duration (120 ))
320
+ except tf .Exception :
321
+ self .assertTrue (None , "could not found tf from /WAIST_LINK0 to /LARM_LINK7" )
322
+ (trans1 ,rot1 ) = self .listener .lookupTransform ('/WAIST_LINK0' , '/LARM_LINK7' , rospy .Time (0 ))
323
+ rospy .logwarn ("tf_echo /WAIST_LINK0 /LARM_LINK7 %r %r" % (trans1 ,rot1 ))
324
+ goal .trajectory .header .stamp = rospy .get_rostime ()
325
+ point .positions = [ x * math .pi / 180.0 for x in [20 ,20 ,20 ,20 ,20 ,20 ] ]
326
+ point .time_from_start = rospy .Duration (5.0 )
327
+ del goal .trajectory .points [:]
328
+ goal .trajectory .points .append (point )
329
+ # send first goal
330
+ larm .send_goal (goal )
331
+ rospy .sleep (2.5 )
332
+ goal .trajectory .header .stamp = rospy .get_rostime ()
333
+ point .positions = [0 ,0 ,0 ,0 ,0 ,0 ]
334
+ point .time_from_start = rospy .Duration (2.5 )
335
+ del goal .trajectory .points [:]
336
+ goal .trajectory .points .append (point )
337
+ # send second goal
338
+ larm .send_goal (goal )
339
+ jt_pos1 = rospy .wait_for_message ('/joint_states' , JointState )
340
+ rospy .logwarn ("joint position just after sending second goal: %r" % (array (jt_pos1 .position )))
341
+ rospy .sleep (0.5 )
342
+ jt_pos2 = rospy .wait_for_message ('/joint_states' , JointState )
343
+ rospy .logwarn ("joint position 0.5 sec after sending second goal: %r" % (array (jt_pos2 .position )))
344
+ rospy .sleep (2 )
345
+ (trans2 ,rot2 ) = self .listener .lookupTransform ('/WAIST_LINK0' , '/LARM_LINK7' , rospy .Time (0 ))
346
+ rospy .logwarn ("tf_echo /WAIST_LINK0 /LARM_LINK7 %r %r" % (trans2 ,rot2 ))
347
+ larm .wait_for_result ()
348
+ rospy .logwarn ("difference between two joint positions %r" % (array (jt_pos2 .position )- array (jt_pos1 .position )))
349
+ # if robot suddenly stops when goal is overwritten, joint position immediately starts to decrease (heading for new goal (zero)).
350
+ # joint_states includes unchanged hand joints, so using assertGreaterEqual instead of assertGreater is necessary.
351
+ for x in array (jt_pos2 .position )- array (jt_pos1 .position ):
352
+ self .assertGreaterEqual (x , 0 )
353
+ rospy .logwarn ("difference between two /LARM_LINK7 %r %r" % (array (trans1 )- array (trans2 ),linalg .norm (array (trans1 )- array (trans2 ))))
354
+ self .assertAlmostEqual (linalg .norm (array (trans1 )- array (trans2 )), 0 , delta = 0.1 )
355
+
227
356
228
357
#unittest.main()
229
358
if __name__ == '__main__' :
0 commit comments