Go to the documentation of this file.00001
00002
00003 import roslib
00004 roslib.load_manifest( 'rospy' )
00005
00006 import rospy
00007
00008 import sys
00009 import numpy as np
00010 import dynamics_utils as dynutils
00011
00012 if __name__== '__main__':
00013
00014 if ( len( sys.argv ) != 2 ):
00015 rospy.logerr( 'no filename passed to play_motion.py' )
00016 exit(-1)
00017
00018 fname = sys.argv[1];
00019
00020 node_name = "play_motion"
00021 rospy.loginfo( 'register node %s ...'%node_name )
00022 rospy.init_node( node_name )
00023 rospy.loginfo( 'node %s up and running!'%node_name )
00024
00025 print dynutils.get_joint_names( 'l_arm_controller' )
00026
00027
00028 dynutils.move_arm( [ -np.pi / 3,
00029 np.pi / 3,
00030 0,
00031 -3 * np.pi/4,
00032 0,
00033 0,
00034 0], arm = 'r' )
00035
00036
00037 ( name, time, pos, vel, acc ) = dynutils.load_motion( fname );
00038 dt = time[1] - time[0]
00039 total_time = dt * len( time )
00040
00041
00042
00043 l_jt_client = dynutils.init_jt_client(arm = 'l')
00044
00045
00046 dynutils.move_arm( pos[0,:],
00047 time_from_start = 3.0,
00048 client = l_jt_client )
00049
00050 rospy.loginfo( 'playing \'%s\' motion ...'%name )
00051
00052
00053 last_call = rospy.Time().now() + rospy.Duration().from_sec( .5 );
00054 dynutils.track_trajectory(pos, vel, acc, time, arm = 'l', client = l_jt_client, stamp = last_call )
00055
00056
00057 while ( not rospy.is_shutdown() ):
00058 dur = rospy.Time().now() - last_call;
00059 if ( dur.to_sec() > total_time - (total_time / 2.0) ):
00060 last_call += rospy.Duration().from_sec( total_time );
00061 dynutils.track_trajectory(pos, vel, acc, time, arm = 'l', client = l_jt_client, stamp = last_call )