|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +Example for demonstrating start and final joint positions for Lab 2. |
| 4 | +""" |
| 5 | + |
| 6 | +import sys |
| 7 | + |
| 8 | +import numpy as np |
| 9 | +import rospy |
| 10 | + |
| 11 | +from sensor_msgs.msg import JointState |
| 12 | + |
| 13 | + |
| 14 | +ROSTOPIC_SET_ARM_JOINT = '/goal_dynamixel_position' |
| 15 | + |
| 16 | + |
| 17 | +def home_arm(pub): |
| 18 | + set_arm_joint(pub, np.zeros(5)) |
| 19 | + rospy.sleep(5) |
| 20 | + |
| 21 | +def set_arm_joint(pub, joint_target): |
| 22 | + joint_state = JointState() |
| 23 | + joint_state.position = tuple(joint_target) |
| 24 | + rospy.loginfo('Going to arm joint position: {}'.format(joint_state.position)) |
| 25 | + pub.publish(joint_state) |
| 26 | + |
| 27 | + |
| 28 | +def main(): |
| 29 | + rospy.init_node('command_joints_example', anonymous=True) |
| 30 | + |
| 31 | + rad_from_deg = np.pi/180. |
| 32 | + start_joints_deg = [ 0., 20., 50., -80., 0.] |
| 33 | + final_joints_deg = [135., 20., 50., -80., 0.] |
| 34 | + |
| 35 | + pub = rospy.Publisher(ROSTOPIC_SET_ARM_JOINT, |
| 36 | + JointState, queue_size=1) |
| 37 | + rospy.sleep(2) |
| 38 | + |
| 39 | + raw_input("Robot ready to move to HOME POSITION. Press Enter to continue.") |
| 40 | + print("Robot moving. Please wait.") |
| 41 | + home_arm(pub) |
| 42 | + rospy.sleep(5) |
| 43 | + |
| 44 | + raw_input("Robot ready to move to START POSITION. Press Enter to continue.") |
| 45 | + print("Robot moving. Please wait.") |
| 46 | + set_arm_joint(pub, rad_from_deg*np.array(start_joints_deg)) |
| 47 | + rospy.sleep(5) |
| 48 | + |
| 49 | + raw_input("Robot ready to move to FINAL POSITION. Press Enter to continue.") |
| 50 | + print("Robot moving. Please wait.") |
| 51 | + set_arm_joint(pub, rad_from_deg*np.array(final_joints_deg)) |
| 52 | + rospy.sleep(10) |
| 53 | + |
| 54 | + raw_input("Robot ready to move to HOME POSITION. Press Enter to continue.") |
| 55 | + print("Robot moving. Please wait.") |
| 56 | + home_arm(pub) |
| 57 | + rospy.sleep(5) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + main() |
0 commit comments