Skip to content

Commit

Permalink
[xs_sdk] Added backward compatibility for cobots (#29)
Browse files Browse the repository at this point in the history
* [sdk_sim] Added backward compatibility for cobot

* [sdk_sim] Added conversion for rack_n_pinion

* [sdk_sim] fixed suggested changes

* [sdk_sim] Updated error to fatal
  • Loading branch information
pinakjani authored Jul 21, 2023
1 parent c1bbd9c commit f2380b8
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions interbotix_ros_xseries/interbotix_xs_sdk/scripts/xs_sdk_sim
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,17 @@ class InterbotixRobotXS(object):

# populate self.gripper_map
for gpr, items in grippers.items():
self.gripper_map[gpr] = {"horn_radius" : items["horn_radius"],
"arm_length" : items["arm_length"],
"left_finger" : items["left_finger"],
"right_finger" : items["right_finger"]}
self.gripper_map[gpr] = {
'type': items.get("type", "swing_arm"),
'horn_radius': items.get("horn_radius", 0.014),
'pitch_radius': items.get("pitch_radius", 0.0127),
'arm_length': items.get("arm_length", 0.024),
'left_finger': items.get("left_finger", "left_finger"),
'right_finger': items.get("right_finger", "right_finger"),
'calibrate': items.get("calibrate", False)
}
if (self.gripper_map[gpr]["type"] != "swing_arm" and self.gripper_map[gpr]["type"] != "rack_and_pinion"):
rospy.logfatal("Invalid Gripper Type: '%s' . Options are: 'swing_arm', 'rack_and_pinion'", self.gripper_map[gpr]["type"])

# populate self.sleep_map, self.gripper_order, and self.js_index_map
# also, initialize self.joint_states
Expand Down Expand Up @@ -217,23 +224,30 @@ class InterbotixRobotXS(object):
### @param linear_position - desired distance [m] between the two gripper fingers
### @return result - angular position [rad] that achieves the desired linear distance
def robot_convert_linear_position_to_radian(self, name, linear_position):
half_dist = linear_position / 2.0
arm_length = self.gripper_map[name]["arm_length"]
horn_radius = self.gripper_map[name]["horn_radius"]
result = math.pi/2.0 - math.acos((horn_radius**2 + half_dist**2 - arm_length**2) / (2 * horn_radius * half_dist))
return result
if (self.gripper_map[name]["type"] == "swing_arm"):
half_dist = linear_position / 2.0
arm_length = self.gripper_map[name]["arm_length"]
horn_radius = self.gripper_map[name]["horn_radius"]
result = math.pi/2.0 - math.acos((horn_radius**2 + half_dist**2 - arm_length**2) / (2 * horn_radius * half_dist))
return result
else:
return linear_position / 2 * self.gripper_map[name]["pitch_radius"]

### @brief Converts a specified angular position into the linear distance from one gripper finger to the center of the gripper servo horn
### @param name - name of the gripper servo to command
### @param angular_position - desired gripper angular position [rad]
### @return - linear position [m] from a gripper finger to the center of the gripper servo horn
def robot_convert_angular_position_to_linear(self, name, angular_position):
arm_length = self.gripper_map[name]["arm_length"]
horn_radius = self.gripper_map[name]["horn_radius"]
a1 = horn_radius * math.sin(angular_position)
c = math.sqrt(horn_radius**2 - a1**2)
a2 = math.sqrt(arm_length**2 - c**2)
return a1 + a2
if (self.gripper_map[name]["type"] == "swing_arm"):
arm_length = self.gripper_map[name]["arm_length"]
horn_radius = self.gripper_map[name]["horn_radius"]
a1 = horn_radius * math.sin(angular_position)
c = math.sqrt(horn_radius**2 - a1**2)
a2 = math.sqrt(arm_length**2 - c**2)
return a1 + a2
else:
return self.gripper_map[name]["pitch_radius"] * angular_position


### @brief ROS Subscriber callback function to command a group of joints
### @param msg - JointGroupCommand message dictating the joint group to command along with the actual commands
Expand Down

0 comments on commit f2380b8

Please sign in to comment.