35 RevelCartesianController is a ROS component that allows cartesian velocity control of the Revel robot. 36 This component is run as part a module of the robot driver, giving it explicit USB / Serial access for 39 This method of robot controls require the robot motors to be in velocity control mode. 40 This class expects a 6DOF robot, and is thus untested for custom robot builds. Significant modification 41 to the robot will violate the kinematic model present in the SvenzvaKinematics class. 42 In this event, a generic (or generated) kinematic solver should be used in place of SvenzvaKinematics. 44 Author Maxwell Svetlik 45 Copyright Svenzva Robotics 54 from pykdl_utils.kdl_parser
import kdl_tree_from_urdf_model
56 from sensor_msgs.msg
import JointState
57 from geometry_msgs.msg
import Twist
58 from moveit_msgs.srv
import GetStateValidity
61 import moveit_commander
62 import moveit_msgs.msg
63 import geometry_msgs.msg
69 def __init__(self, controller_namespace, mx_io):
70 rospy.Subscriber(
"/revel/eef_velocity", Twist, self.
cart_vel_cb, queue_size=1);
71 rospy.Subscriber(
"joint_states", JointState, self.
js_cb, queue_size=1);
72 rospack = rospkg.RosPack()
73 path = rospack.get_path(
"svenzva_description");
74 full_path = path +
"/robots/svenzva_arm.urdf";
76 f = file(full_path,
'r') 77 self.robot = Robot.from_xml_string(f.read()) 83 self.js = JointState() 100 rospy.loginfo(
"MoveIt collision check for cartesian movements ENABLED. Using environment information.")
102 rospy.wait_for_service(
'/check_state_validity')
104 except rospy.ServiceException
as exc:
105 rospy.loginfo(
"MoveIt not. Cartesian Velocity controller will not use collision checking.")
106 rospy.logerr(
"Cartesian collision checking DISABLED")
109 rospy.loginfo(
"MoveIt collision check for cartesian movements DISabled. Not using environment information.")
117 return int(round( angle * 4096.0 / 6.2831853) )
120 return rad_per_min * 0.159155
126 Uses MoveIt to check if movement would cause collision with scene or self 127 Returns true if movement causes collision 128 false if movement does not cause collision 131 rs = moveit_msgs.msg.RobotState()
134 rs.joint_state.name.append(self.js.name[i])
135 rs.joint_state.position.append(self.js.position[i] + (qdot_out[i]/scale_factor*dt))
145 tup_list.append( (i+1, 0))
146 self.mx_io.set_multi_speed(tuple(tup_list))
149 self.mx_io.set_multi_speed(tuple(self.
last_cmd))
158 while not rospy.is_shutdown():
171 joint_positions = numpy.empty(0)
173 joint_positions = numpy.append(joint_positions, self.js.position[i])
186 qdot_out = self.jacobian_solver.get_joint_vel(joint_positions, self.
ee_velocity)
191 shoulder_det = self.jacobian_solver.get_jacobian_det()
197 if abs(shoulder_det) < 0.0001
and len(self.
last_cmd) > 0
and numpy.linalg.norm(self.
last_cmd) != 0:
204 if abs(msg.angular.z) > 0:
205 qdot_out[5] = msg.angular.z
207 if not isinstance(qdot_out, numpy.ndarray)
and qdot_out == SvenzvaKinematics.ERROR_SINGULAR:
208 rospy.loginfo(
"Jacobian could not be inverted because it is singular.")
221 acc += math.pow(qdot_out[i], 2)
226 scale_factor = vel_scale
228 if scale_factor != 1:
229 rospy.logdebug(
"Scaling cartesian velocity: scaling all velocity by %f", 1/scale_factor)
237 rospy.loginfo(
"Movement would cause collision with environment.")
239 tup_list.append( (i+1, 0))
242 self.mx_io.set_multi_speed(tuple(tup_list))
248 if self.robot.joints[i+1].limit.lower >= self.js.position[i] + (qdot_out[i]/scale_factor*0.01)
or self.js.position[i] + (qdot_out[i]/scale_factor*0.01) >= self.robot.joints[i+1].limit.upper:
249 rospy.logwarn(
"Cartesian movement would cause movement outside of joint limits. Skipping...")
250 rospy.logwarn(
"Movement would violate joint limit: Joint %d moving to %f with limits [%f,%f]", i+1, (qdot_out[i]/scale_factor) + self.js.position[i], self.robot.joints[i+1].limit.lower, self.robot.joints[i+1].limit.upper)
251 tup_list.append( (i+1, 0))
253 tup_list.append( (i+1, int(round(self.
radpm_to_rpm(qdot_out[i] * self.
gear_ratios[i] / scale_factor) / 0.229 ))))
256 if len(tup_list) > 0:
260 self.mx_io.set_multi_speed(tuple(tup_list))
264 rospy.sleep(time_step)
268 if self.js.position[4] > lim - 0.03
and self.js.position[4] < lim + 0.03:
275 if self.js.position[2] > lim - 0.03
and self.js.position[2] < lim + 0.03:
281 rospy.sleep(time_step)
def cart_vel_cb(self, msg)
def rad_to_raw(self, angle)
def __init__(self, controller_namespace, mx_io)
def check_if_collision(self, qdot_out, scale_factor, dt)
def radpm_to_rpm(self, rad_per_min)