35 Svenzva's Revel general utility service interface 37 Includes exposing the following services: 38 + Arm torque enabled / disabled 39 + Finger position reset (finger-removal service) 40 + Finger hotswap (finger-insert service) 41 Author: Maxwell Svetlik 43 from __future__
import division
44 from threading
import Thread
51 from std_srvs.srv
import Empty
52 from std_msgs.msg
import Float64, Int32
53 from svenzva_msgs.msg
import MotorState, MotorStateList, GripperFeedback, GripperResult, GripperAction
55 from svenzva_msgs.srv
import SetTorqueEnable, HomeArm, SetControlMode
61 def __init__(self, controller_namespace, mx_io, num_motors):
71 rospy.Subscriber(
"revel/motor_states", MotorStateList, self.
motor_state_cb, queue_size=1)
81 Service call back that pushes fingers out of gripper and resets motor position for correct finger 87 cur_pos = self.motor_state.position
90 self.mx_io.set_torque_enabled(7, 0)
91 self.mx_io.set_torque_enabled(7, 1)
93 self.mx_io.set_position(7, int(round(self.
reset_pos * 4096.0 / 6.2831853)))
97 self.mx_io.set_torque_enabled(7, 0)
98 self.mx_io.set_operation_mode(7, 0)
99 self.mx_io.set_torque_enabled(7, 1)
104 Service used in conjunction with `remove_fingers` service. This service should be called after the 105 fingers have been pushed into the gripper by the user. 109 self.mx_io.set_torque_enabled(7, 0)
110 self.mx_io.set_operation_mode(7, 4)
111 self.mx_io.set_torque_enabled(7, 1)
113 self.mx_io.set_position(7, int(round(0 * 4096.0 / 6.2831853)))
117 self.mx_io.set_torque_enabled(7, 0)
118 self.mx_io.set_operation_mode(7, 0)
119 self.mx_io.set_torque_enabled(7, 1)
124 tup_list_op = tuple()
125 if data.control_mode == data.POSITION:
126 tup_list_op = tuple(((1,5),(2,5),(3,5),(4,5),(5,5),(6,5),(7,0)))
127 elif data.control_mode == data.VELOCITY:
128 tup_list_op = tuple(((1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,0)))
129 elif data.control_mode == data.TORQUE:
130 tup_list_op = tuple(((1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0)))
132 tup_list_op = tuple(((1,5),(2,5),(3,5),(4,5),(5,5),(6,5),(7,0)))
133 tup_list_dis = tuple(((1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0)))
134 tup_list_en = tuple(((1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1)))
135 self.mx_io.sync_set_torque_enabled(tup_list_dis)
136 self.mx_io.sync_set_operation_mode(tup_list_op)
137 self.mx_io.sync_set_torque_enabled(tup_list_en)
143 rospy.logerr(
"SetTorqueEnable: input motor_list is not the right length. Aborting.")
146 for i, val
in enumerate(data.motor_list):
147 if val > 1
or val < 0:
148 rospy.logwarn(
"Torque value for motor %d was not binary. Interpreting as ENABLE.", i)
150 self.mx_io.set_torque_enabled(i+1, val)
155 rospy.logerr(
"SetTorqueEnable: input motor_list is not the right length. Aborting.")
158 for i, val
in enumerate(data.data):
159 cmds.append( (i+1, val))
160 self.mx_io.set_multi_current(tuple(cmds))
164 rospy.loginfo(
"Starting RevelArmServices...")
168 Calls a service that restores the control parameters for each motor, which get reset to defaults when torque is 169 disabled, which happes when a user changes modes or dis/enables torque 173 reset_motor_param = rospy.ServiceProxy(
'/revel/reload_firmware_parameters', Empty)
174 return reset_motor_param()
175 except rospy.ServiceException, e:
176 rospy.loginfo(
"Unable to reset motor parmeters after context change... call failed: %s"%e)
181 rospack = rospkg.RosPack()
182 path = rospack.get_path(
'svenzva_drivers')
183 f = open(path+
"/config/home_position.yaml")
184 qmap = yaml.safe_load(f)
188 req = SvenzvaJointGoal()
189 if len(qmap[
'home']) < 6:
190 rospy.logerr(
"Could not home arm. Home position configuration file ill-formed or missing. Aborting.")
192 req.positions = qmap[
'home']
196 fkine.wait_for_server()
197 rospy.loginfo(
"Found Trajectory action server")
198 rospy.loginfo(
"Homing arm...")
199 fkine.send_goal_and_wait(req)
def insert_fingers_cb(self, data)
def reset_motor_parmeters(self)
def control_mode_cb(self, data)
def motor_state_cb(self, data)
def __init__(self, controller_namespace, mx_io, num_motors)
def remove_fingers_cb(self, data)
def torque_enable_cb(self, data)
def torque_goal_cb(self, data)