83
85
self.publishers[joint_name].publish(self.msg_to_send)
85
87
def get_position(self, joint_name):
88
return self.positions[joint_name]
90
value = self.positions[joint_name]
92
#We check if the reason to except is that we are trying to access the joint 0
93
#Position of the J0 is the addition of the positions of J1 and J2
94
m = re.match("(?P<finger>\w{2})J0", joint_name)
96
value = self.positions[m.group("finger") + "J1"] + self.positions[m.group("finger") + "J2"]
101
def get_velocity(self, joint_name):
104
value = self.velocities[joint_name]
106
#We check if the reason to except is that we are trying to access the joint 0
107
m = re.match("(?P<finger>\w{2})J0", joint_name)
109
value = self.velocities[m.group("finger") + "J1"] + self.velocities[m.group("finger") + "J2"]
90
114
def get_effort(self, joint_name):
91
return self.efforts[joint_name]
117
value = self.efforts[joint_name]
119
#We check if the reason to except is that we are trying to access the joint 0
120
#Effort of the J0 is the same as the effort of J1 and J2, so we pick J1
121
m = re.match("(?P<finger>\w{2})J0", joint_name)
123
value = self.efforts[m.group("finger") + "J1"]
93
128
def start_record(self, joint_name, callback):
94
129
self.record_js_callback = callback
119
154
self.raw_values = msg.sensors
121
156
def joint_state_callback(self, msg):
122
for name,pos,effort in zip( msg.name, msg.position, msg.effort ):
157
for name,pos,vel,effort in zip( msg.name, msg.position, msg.velocity, msg.effort ):
123
158
self.positions[name] = pos
159
self.velocities[name] = vel
124
160
self.efforts[name] = effort
126
162
if self.record_js_callback is not None:
163
199
# return false (the library is not activated)
165
201
rospy.wait_for_message("/debug_etherCAT_data", EthercatDebug, timeout = 0.2)
166
rospy.wait_for_message("/joint_states", EthercatDebug, timeout = 0.2)
202
rospy.wait_for_message("/joint_states", JointState, timeout = 0.2)
171
207
self.joint_state_subscriber = rospy.Subscriber("/joint_states", JointState, self.joint_state_callback)
210
def activate_joint_states(self):
211
#check if something is being published to this topic, otherwise
212
# return false (the library is not activated)
214
rospy.wait_for_message("/gazebo/joint_states", JointState, timeout = 0.2)
218
self.joint_state_subscriber = rospy.Subscriber("/gazebo/joint_states", JointState, self.joint_state_callback)
174
221
def on_close(self):
175
222
if self.debug_subscriber is not None:
176
223
self.debug_subscriber.unregister()