forked from ros-industrial/universal_robot
-
Notifications
You must be signed in to change notification settings - Fork 0
PSI-273 Robotiq3f integration #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+151
−4
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
586ae48
PSI-273 Robotiq3F Integration
nitish3693 bae3506
Added Mode Provider Service and Updated Error Handling
nitish3693 a58bbfb
Change environment variable for gripper mode
nitish3693 c59bfff
Changing Enum to Dict and Error Handling
robotist-nitish 33c6be4
add python linters for extend grippers package
97fb86b
exclude scripts from CI that weren't a part of this PR
b297f1b
Merge branch 'noetic-devel' into PSI-273-RObotiq3F-Integration
nitish3693 376f1bc
Changes requested in review
nitish3693 d5f9b4e
trigger checks
f27f221
Update workflow reference for Python linters
tomqext 61910fc
Merge pull request #8 from Extend-Robotics/ERD-1633_switch_to_public_…
tomqext ab9d73c
Fix formatting issues in gripper control script
nitish3693 1c87fe0
PSI-270 Review Comments adjustments
nitish3693 bd38042
Fixed a Typo
nitish3693 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
extend_gripper_control_ur/scripts/gripper_control_robotiq_3f.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| #!/usr/bin/env python3 | ||
| import os | ||
| import time | ||
|
|
||
| import rospy | ||
| from std_msgs.msg import Header | ||
| from robotiq_3f_gripper_articulated_msgs.msg import Robotiq3FGripperRobotOutput | ||
| from extend_msgs.msg import GripperControl, GripperResponse | ||
| from extend_msgs.srv import GetString, GetStringResponse | ||
|
|
||
| FINGER_FORCE = 150 | ||
| FINGER_SPEED = 255 | ||
| ROBOTIQ_3F_GRIPPER_MODE_ENUM_DICT = {"BASIC": 0, "PINCH": 1, "WIDE": 2, "SCISSOR": 3} | ||
|
|
||
|
|
||
| class Robotiq3FGripperControlNode: | ||
| NUM_ACTIVE_JOINTS = 3 | ||
| FINGER_POSITION_REGISTER_MAX = 255 | ||
| MAX_FINGER_ANGLE_DEGREES = 70.0 | ||
|
|
||
| def __init__(self, mode): | ||
nitish3693 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.robotiq_control_pub = rospy.Publisher('Robotiq3FGripperRobotOutput', Robotiq3FGripperRobotOutput, queue_size=1) | ||
| self.gripper_command_republisher = rospy.Publisher('extend_gripper_republished_command', GripperControl, queue_size=1) | ||
| self.gripper_response_pub = rospy.Publisher('extend_gripper_response', GripperResponse, queue_size=1) | ||
| rospy.Service('robotiq_3f_current_mode', GetString, self.current_mode_provider) | ||
| self.current_mode = mode | ||
| self.joint_command_values = [0.0] * self.NUM_ACTIVE_JOINTS | ||
| self.analog_command_value = 0.0 | ||
|
|
||
| def current_mode_provider(self, _): | ||
| response = GetStringResponse() | ||
| response.data = self.current_mode | ||
| return response | ||
|
|
||
| def reset_gripper(self): | ||
| gripper_control_msg = Robotiq3FGripperRobotOutput() | ||
nitish3693 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # rACT = 0 is the reset command for the Robotiq 3F gripper, resets it to its initial state. | ||
| # Making the assignmenent explicitly here for clarity, even though the default value of rACT is 0 | ||
| gripper_control_msg.rACT = 0 | ||
| self.robotiq_control_pub.publish(gripper_control_msg) | ||
|
|
||
| def activate_gripper(self): | ||
| gripper_control_msg = Robotiq3FGripperRobotOutput() | ||
| gripper_control_msg.rACT = 1 | ||
| self.robotiq_control_pub.publish(gripper_control_msg) | ||
|
|
||
| def mode_select(self): | ||
| gripper_control_msg = Robotiq3FGripperRobotOutput() | ||
| gripper_control_msg.rACT = 1 | ||
| gripper_control_msg.rMOD = ROBOTIQ_3F_GRIPPER_MODE_ENUM_DICT[self.current_mode] | ||
| self.robotiq_control_pub.publish(gripper_control_msg) | ||
|
|
||
| def gripper_command_publish(self): | ||
| gripper_control_msg = Robotiq3FGripperRobotOutput() | ||
| gripper_control_msg.rACT = 1 | ||
| gripper_control_msg.rGTO = 1 | ||
| gripper_control_msg.rATR = 0 | ||
| gripper_control_msg.rGLV = 0 | ||
| gripper_control_msg.rICS = 0 | ||
|
|
||
| gripper_control_msg.rSPA = FINGER_SPEED | ||
| gripper_control_msg.rFRA = FINGER_FORCE | ||
|
|
||
| gripper_control_msg.rSPB = FINGER_SPEED | ||
| gripper_control_msg.rFRB = FINGER_FORCE | ||
|
|
||
| gripper_control_msg.rSPC = FINGER_SPEED | ||
| gripper_control_msg.rFRC = FINGER_FORCE | ||
|
|
||
| gripper_control_msg.rPRS = 0 | ||
| gripper_control_msg.rSPS = 0 | ||
| gripper_control_msg.rFRS = 0 | ||
|
|
||
| gripper_control_msg.rMOD = ROBOTIQ_3F_GRIPPER_MODE_ENUM_DICT[self.current_mode] | ||
|
|
||
| if self.current_mode in ("BASIC", "WIDE"): | ||
| # For BASIC and WIDE modes, joint command values are in the range of 0-70 degrees for the fingers | ||
| gripper_control_msg.rICF = 1 | ||
| gripper_control_msg.rPRA = int(self.FINGER_POSITION_REGISTER_MAX * self.joint_command_values[0] / self.MAX_FINGER_ANGLE_DEGREES) | ||
| gripper_control_msg.rPRB = int(self.FINGER_POSITION_REGISTER_MAX * self.joint_command_values[1] / self.MAX_FINGER_ANGLE_DEGREES) | ||
| gripper_control_msg.rPRC = int(self.FINGER_POSITION_REGISTER_MAX * self.joint_command_values[2] / self.MAX_FINGER_ANGLE_DEGREES) | ||
| else: | ||
| # For PINCH and SCISSOR modes, all fingers move together based on the analog value between 0-1 | ||
| gripper_control_msg.rICF = 0 | ||
| gripper_control_msg.rPRA = int(self.FINGER_POSITION_REGISTER_MAX * self.analog_command_value) | ||
| self.robotiq_control_pub.publish(gripper_control_msg) | ||
|
|
||
| def vr_gripper_command_callback(self, msg): | ||
| if self.current_mode in ("PINCH", "SCISSOR"): | ||
| self.analog_command_value = msg.gripperAnalog.data | ||
| if not 0.0 <= self.analog_command_value <= 1.0: | ||
| raise ValueError("Gripper analog command value must be between 0 and 1 for PINCH and SCISSOR modes.") | ||
| else: | ||
| if len(msg.handJointValues) == self.NUM_ACTIVE_JOINTS: | ||
| value_error = [] | ||
| self.joint_command_values = msg.handJointValues | ||
| for i, value in enumerate(self.joint_command_values): | ||
| if not 0.0 <= value <= self.MAX_FINGER_ANGLE_DEGREES: | ||
| value_error.append((f"Joint Command {value} recieved for Index {i} is outside [0.0, {self.MAX_FINGER_ANGLE_DEGREES}]")) | ||
| if value_error: | ||
| raise ValueError("\n".join(value_error)) | ||
| else: | ||
| raise ValueError("Invalid hand joint values received.") | ||
|
|
||
| header = Header() | ||
| header.seq = 0 | ||
| header.frame_id = "" | ||
nitish3693 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| header.stamp = rospy.Time.now() | ||
|
|
||
| gripper_command_republisher_data = msg | ||
| gripper_command_republisher_data.header = header | ||
| self.gripper_command_republisher.publish(gripper_command_republisher_data) | ||
|
|
||
| # Data collection always requires a response to be published, even if it's empty | ||
| # Data collection config is based on arm models and does not consider the attached gripper type. | ||
| # Therefore, till we distinguish between different grippers we need to publish the response. | ||
| gripper_response_data = GripperResponse() | ||
nitish3693 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| gripper_response_data.header = header | ||
| self.gripper_response_pub.publish(gripper_response_data) | ||
nitish3693 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.gripper_command_publish() | ||
|
|
||
|
|
||
| def main(): | ||
| gripper_mode = os.getenv("gripperMode", "BASIC").upper() | ||
nitish3693 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if gripper_mode not in ROBOTIQ_3F_GRIPPER_MODE_ENUM_DICT: | ||
| raise ValueError(f"Invalid gripper mode \"{gripper_mode}\" selected. Valid modes are: {list(ROBOTIQ_3F_GRIPPER_MODE_ENUM_DICT.keys())}") | ||
|
|
||
| rospy.init_node("ur_robotiq_gripper") | ||
| gripper_control_node = Robotiq3FGripperControlNode(mode=gripper_mode) | ||
|
|
||
| gripper_control_node.reset_gripper() | ||
| time.sleep(1) | ||
|
|
||
| gripper_control_node.activate_gripper() | ||
| time.sleep(0.5) | ||
|
|
||
| gripper_control_node.mode_select() | ||
| time.sleep(0.5) | ||
|
|
||
| rospy.Subscriber("extend_gripper_command", GripperControl, gripper_control_node.vr_gripper_command_callback) | ||
| rospy.spin() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.