make_samples.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # capture samples!!!!1!one
4 
5 # this script should eventually be replaced by something that finds
6 # samples automatically
7 
8 import rospy
9 from sensor_msgs.msg import JointState
10 
11 import string, os
12 
13 header1 = """camera_measurements:
14 - {cam_id: head_camera, config: small_cb_4x5}
15 joint_commands:
16 """
17 
18 header2_arm = """- controller: arm_controller
19  segments:
20  - duration: 2.0
21  positions: """
22 
23 header2_head = """- controller: head_controller
24  segments:
25  - duration: 2.0
26  positions: """
27 
28 header3 = """joint_measurements:
29 - {chain_id: arm_chain, config: tight_tol}
30 - {chain_id: head_chain, config: tight_tol}
31 
32 sample_id: arm_"""
33 
34 header4 = """target: {chain_id: arm_chain, target_id: small_cb_4x5}"""
35 
37 
38  def __init__(self):
39  rospy.init_node("make_samples")
40  rospy.Subscriber("joint_states", JointState, self.callback)
41  self.arm_joints = ["RARM_JOINT0", "RARM_JOINT1", "RARM_JOINT2", "RARM_JOINT3", "RARM_JOINT4", "RARM_JOINT5", ]
42  self.arm_state = [0.0 for joint in self.arm_joints]
43  self.head_joints = ["HEAD_JOINT0", "HEAD_JOINT1", ]
44  self.head_state = [0.0 for joint in self.head_joints]
45 
46  self.count = 0
47 
48  while not rospy.is_shutdown():
49  print "Move arm/head to a new sample position."
50  resp = raw_input("press <enter> ")
51  if string.upper(resp) == "EXIT":
52  break
53  else:
54  # save a sample:
55  count = str(self.count).zfill(4)
56  f = open(os.path.dirname(__file__)+"/samples/arm/arm_"+count+".yaml", "w")
57  f.write(header1)
58  print('saving ... {0}'.format(self.count))
59  print(' arm_state: {0}'.format(self.arm_state))
60 
61  f.write(header2_arm)
62  print>>f, self.arm_state
63  print(' head_state: {0}'.format(self.head_state))
64 
65  f.write(header2_head)
66  print>>f, self.head_state
67 
68  f.write(header3)
69  print>>f, count
70  f.write(header4)
71  self.count += 1
72 
73  def callback(self, msg):
74 
75  for i in range(len(self.arm_joints)):
76  try:
77  idx = msg.name.index(self.arm_joints[i])
78  self.arm_state[i] = msg.position[idx]
79  except:
80  pass
81 
82  for i in range(len(self.head_joints)):
83  try:
84  idx = msg.name.index(self.head_joints[i])
85  self.head_state[i] = msg.position[idx]
86  except:
87  pass
88 
89 
90 if __name__=="__main__":
91  SampleMaker()
def callback(self, msg)
Definition: make_samples.py:73


hironx_calibration
Author(s): Kei Okada
autogenerated on Thu May 14 2020 03:52:29