$search
00001 #!/usr/bin/env python 00002 00003 # capture samples!!!!1!one 00004 00005 # this script should eventually be replaced by something that finds 00006 # samples automatically 00007 00008 import roslib; roslib.load_manifest("armadillo_calibration"); 00009 00010 import rospy 00011 from sensor_msgs.msg import JointState 00012 00013 import string 00014 00015 header1 = """camera_measurements: 00016 - {cam_id: kinect_camera, config: small_cb_4x5} 00017 joint_commands: 00018 - controller: arm_controller 00019 segments: 00020 - duration: 2.0 00021 positions: """ 00022 00023 header3 = """joint_measurements: 00024 - {chain_id: arm_chain, config: tight_tol} 00025 sample_id: arm_""" 00026 00027 header4 = """target: {chain_id: arm_chain, target_id: small_cb_4x5}""" 00028 00029 class SampleMaker: 00030 00031 def __init__(self): 00032 rospy.init_node("make_samples") 00033 rospy.Subscriber("joint_states", JointState, self.callback) 00034 00035 self.arm_joints = ['joint_'+j for j in ['s','l','e','u','r','b','t']] 00036 self.arm_state = [0.0 for joint in self.arm_joints] 00037 self.count = 0 00038 00039 while not rospy.is_shutdown(): 00040 print "Move arm/head to a new sample position." 00041 resp = raw_input("press <enter> ") 00042 if string.upper(resp) == "EXIT": 00043 break 00044 else: 00045 # save a sample: 00046 count = str(self.count).zfill(4) 00047 f = open("samples/arm_"+count+".yaml", "w") 00048 f.write(header1) 00049 print>>f, self.arm_state 00050 f.write(header3) 00051 print>>f, count 00052 f.write(header4) 00053 f.close() 00054 self.count += 1 00055 00056 def callback(self, msg): 00057 for i in range(len(self.arm_joints)): 00058 try: 00059 idx = msg.name.index(self.arm_joints[i]) 00060 self.arm_state[i] = msg.position[idx] 00061 except: 00062 pass 00063 00064 00065 if __name__=="__main__": 00066 SampleMaker() 00067