Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 import rospy
00009 from sensor_msgs.msg import JointState
00010
00011 import string, os
00012
00013 header1 = """camera_measurements:
00014 - {cam_id: head_camera, config: small_cb_4x5}
00015 joint_commands:
00016 """
00017
00018 header2_arm = """- controller: arm_controller
00019 segments:
00020 - duration: 2.0
00021 positions: """
00022
00023 header2_head = """- controller: head_controller
00024 segments:
00025 - duration: 2.0
00026 positions: """
00027
00028 header3 = """joint_measurements:
00029 - {chain_id: arm_chain, config: tight_tol}
00030 - {chain_id: head_chain, config: tight_tol}
00031
00032 sample_id: arm_"""
00033
00034 header4 = """target: {chain_id: arm_chain, target_id: small_cb_4x5}"""
00035
00036 class SampleMaker:
00037
00038 def __init__(self):
00039 rospy.init_node("make_samples")
00040 rospy.Subscriber("joint_states", JointState, self.callback)
00041 self.arm_joints = ["RARM_JOINT0", "RARM_JOINT1", "RARM_JOINT2", "RARM_JOINT3", "RARM_JOINT4", "RARM_JOINT5", ]
00042 self.arm_state = [0.0 for joint in self.arm_joints]
00043 self.head_joints = ["HEAD_JOINT0", "HEAD_JOINT1", ]
00044 self.head_state = [0.0 for joint in self.head_joints]
00045
00046 self.count = 0
00047
00048 while not rospy.is_shutdown():
00049 print "Move arm/head to a new sample position."
00050 resp = raw_input("press <enter> ")
00051 if string.upper(resp) == "EXIT":
00052 break
00053 else:
00054
00055 count = str(self.count).zfill(4)
00056 f = open(os.path.dirname(__file__)+"/samples/arm/arm_"+count+".yaml", "w")
00057 f.write(header1)
00058 print('saving ... {0}'.format(self.count))
00059 print(' arm_state: {0}'.format(self.arm_state))
00060
00061 f.write(header2_arm)
00062 print>>f, self.arm_state
00063 print(' head_state: {0}'.format(self.head_state))
00064
00065 f.write(header2_head)
00066 print>>f, self.head_state
00067
00068 f.write(header3)
00069 print>>f, count
00070 f.write(header4)
00071 self.count += 1
00072
00073 def callback(self, msg):
00074
00075 for i in range(len(self.arm_joints)):
00076 try:
00077 idx = msg.name.index(self.arm_joints[i])
00078 self.arm_state[i] = msg.position[idx]
00079 except:
00080 pass
00081
00082 for i in range(len(self.head_joints)):
00083 try:
00084 idx = msg.name.index(self.head_joints[i])
00085 self.head_state[i] = msg.position[idx]
00086 except:
00087 pass
00088
00089
00090 if __name__=="__main__":
00091 SampleMaker()