Go to the documentation of this file.00001
00002
00003
00004
00005 import rospy
00006 from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
00007 from sr_robot_commander.sr_hand_commander import SrHandCommander
00008 from numpy import sin, cos, pi, arange
00009
00010
00011 f = 1
00012
00013 w = 2*pi*f
00014
00015 rospy.init_node("hand_sine_example", anonymous=True)
00016
00017 hand_commander = SrHandCommander()
00018
00019
00020
00021 joint_names = ['rh_FFJ3', 'rh_MFJ3']
00022 min_pos_J3 = 0.0
00023 max_pos_J3 = pi/2
00024
00025 rospy.sleep(rospy.Duration(2))
00026
00027 hand_joint_states_1 = {'rh_FFJ1': 0.35, 'rh_FFJ2': 0.0, 'rh_FFJ3': 0.0, 'rh_FFJ4': 0.0,
00028 'rh_MFJ1': 0.35, 'rh_MFJ2': 0.0, 'rh_MFJ3': 0.0, 'rh_MFJ4': 0.0,
00029 'rh_RFJ1': 0.35, 'rh_RFJ2': 0.0, 'rh_RFJ3': 0.0, 'rh_RFJ4': 0.0,
00030 'rh_LFJ1': 0.35, 'rh_LFJ2': 0.0, 'rh_LFJ3': 0.0, 'rh_LFJ4': 0.0, 'rh_LFJ5': 0.0,
00031 'rh_THJ1': 0.35, 'rh_THJ2': 0.0, 'rh_THJ3': 0.0, 'rh_THJ4': 0.0, 'rh_THJ5': 0.0,
00032 'rh_WRJ1': 0.0, 'rh_WRJ2': 0.0}
00033
00034
00035 print("Running joints trajectory")
00036
00037 joint_trajectory = JointTrajectory()
00038 joint_trajectory.header.stamp = rospy.Time.now()
00039 joint_trajectory.joint_names = list(hand_joint_states_1.keys())
00040 joint_trajectory.points = []
00041 time_from_start = rospy.Duration(5)
00042
00043
00044 for t in arange(0.002, 20, 0.02):
00045 trajectory_point = JointTrajectoryPoint()
00046 trajectory_point.time_from_start = rospy.Duration.from_sec(float(t))
00047 trajectory_point.positions = []
00048 trajectory_point.velocities = []
00049 trajectory_point.accelerations = []
00050 trajectory_point.effort = []
00051 for key in joint_trajectory.joint_names:
00052 if key in joint_names[0]:
00053 joint_position = sin(w * t) * (max_pos_J3 - min_pos_J3)/2 + (max_pos_J3 - min_pos_J3)/2 + min_pos_J3
00054 trajectory_point.positions.append(joint_position)
00055 elif key in joint_names[1]:
00056 joint_position = cos(w * t) * (max_pos_J3 - min_pos_J3)/2 + (max_pos_J3 - min_pos_J3)/2 + min_pos_J3
00057 trajectory_point.positions.append(joint_position)
00058 else:
00059 trajectory_point.positions.append(hand_joint_states_1[key])
00060 trajectory_point.velocities.append(0.0)
00061 trajectory_point.accelerations.append(0.0)
00062 trajectory_point.effort.append(0.0)
00063
00064 joint_trajectory.points.append(trajectory_point)
00065
00066 hand_commander.run_joint_trajectory_unsafe(joint_trajectory)
00067
00068 rospy.sleep(rospy.Duration(15))