You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
9.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. # Tutorial: Tool Change
  2. Many users will want to work with tools other than the default Stretch Gripper that ships with the robot. In this tutorial, you will learn how to configure the Stretch software interfaces to support other tools.
  3. ## Changing Tool Interfaces in Stretch Body
  4. Stretch Body supports a plug-in-based architecture for tools. A tool is an extension of the [EndOfArm](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/end_of_arm.py) class that supports additional degrees of freedom.
  5. ### Standard Tools
  6. Stretch Body supports two tool interfaces by default: The [ToolNone & ToolStretchGripper](https://github.com/hello-robot/stretch_body/tree/master/body/end_of_arm_tools.py). We will explore swapping between these default tools.
  7. ### ToolStretchGripper
  8. Stretch is configured to load the ToolStretchGripper interface by default. This tool is loaded according to the `robot.tool` parameter:
  9. ```{.bash .shell-prompt}
  10. stretch_params.py | grep robot.tool
  11. ```
  12. ```{.bash .no-copy}
  13. stretch_body.robot_params.nominal_params param.robot.tool tool_stretch_gripper
  14. ```
  15. We can interact with this tool from iPython
  16. ```{.bash .shell-prompt}
  17. ipython
  18. ```
  19. ```{.python .no-copy}
  20. In [1]: import stretch_body.robot as robot
  21. In [2]: r=robot.Robot()
  22. In [3]: r.startup()
  23. In [4]: r.end_of_arm
  24. Out[4]: <stretch_body.end_of_arm_tools.ToolStretchGripper instance at 0x7f99109155a0>
  25. In [5]: r.end_of_arm.motors
  26. Out[5]:
  27. {'stretch_gripper': <stretch_body.stretch_gripper.StretchGripper instance at 0x7f99109159b0>,
  28. 'wrist_yaw': <stretch_body.wrist_yaw.WristYaw instance at 0x7f9910915820>}
  29. In [6]: r.end_of_arm.stow()
  30. --------- Stowing Wrist Yaw ----
  31. --------- Stowing Gripper ----
  32. In [7]: r.stop()
  33. ```
  34. ### ToolNone
  35. The ToolNone interface can be loaded when no tool is attached to the Wrist Yaw joint. To switch to this interface, simply update the field in your `stretch_re1_user_params.yaml` to:
  36. ```yaml
  37. robot:
  38. tool: tool_none
  39. ```
  40. After updating the YAML we can interact with the ToolNone via iPython
  41. ```python
  42. In [1]: import stretch_body.robot as robot
  43. In [2]: r=robot.Robot()
  44. In [3]: r.startup()
  45. In [4]: r.end_of_arm
  46. Out[4]: <stretch_body.end_of_arm_tools.ToolNone instance at 0x7f245f786fa0>
  47. In [5]: r.end_of_arm.motors
  48. Out[5]: {'wrist_yaw': <stretch_body.wrist_yaw.WristYaw instance at 0x7f245e69e410>}
  49. In [6]: r.end_of_arm.stow()
  50. --------- Stowing Wrist Yaw ----
  51. In [7]: r.stop()
  52. ```
  53. ## Loading Tool Interfaces from Stretch Tool Share
  54. The [Stretch Tool Share](https://github.com/hello-robot/stretch_tool_share/) is an open Git repository for non-standard Stretch tools. It hosts the CAD, URDF, and Python files needed to integrate these tools with your robot.
  55. To use Stretch Tool Share tools, first update your installation:
  56. ```{.bash .shell-prompt}
  57. pip install -U hello-robot-stretch-tool-share
  58. ```
  59. As an example, we see on the Tool Share that there is a tool, the [ToolDryEraseToolHolderV1](https://github.com/hello-robot/stretch_tool_share/blob/master/python/stretch_tool_share/dry_erase_holder_v1/tool.py) which [extends the EndOfArm](https://github.com/hello-robot/stretch_tool_share/blob/master/python/stretch_tool_share/usbcam_wrist_v1/tool.py) class. To load this tool interface, modify your `stretch_user_params.yaml` to load the tool as before. We will also need to tell it where to find the tool's [parameter file](https://github.com/hello-robot/stretch_tool_share/blob/master/python/stretch_tool_share/dry_erase_holder_v1/params.py):
  60. ```yaml
  61. robot:
  62. tool: tool_dry_erase_holder_v1
  63. params:
  64. - stretch_tool_share.dry_erase_holder_v1.params
  65. ```
  66. We can now interact with the tool in iPython:
  67. ```python
  68. In [1]: import stretch_body.robot as robot
  69. In [2]: r=robot.Robot()
  70. In [3]: r.startup()
  71. In [4]: r.end_of_arm
  72. Out[4]: <stretch_tool_share.dry_erase_holder_v1.tool.ToolDryEraseHolderV1 instance at 0x7f3b61c17f00>
  73. In [5]: r.end_of_arm.motors
  74. Out[5]: {'wrist_yaw': <stretch_body.wrist_yaw.WristYaw instance at 0x7f3b61c59280>}
  75. In [6]: r.end_of_arm.stow()
  76. --------- Stowing Wrist Yaw ----
  77. ```
  78. # Changing Tool Interfaces in Stretch ROS
  79. Next, we'll see how to change the ROS interface for a tool. Here we will continue with the [ToolDryEraseHolderV1](https://github.com/hello-robot/stretch_tool_share/blob/master/python/stretch_tool_share/dry_erase_holder_v1/tool.py#L3) example. First, configure Stretch Body to use the tool as in the previous exercise.
  80. Next, ensure ROS is up to date:
  81. ```{.bash .shell-prompt}
  82. cd ~/catkin_ws/src/stretch_ros/
  83. git pull
  84. ```
  85. To access the URDF data for the [ToolDryEraseHolderV1](https://github.com/hello-robot/stretch_tool_share/blob/master/python/stretch_tool_share/dry_erase_holder_v1/tool.py#L3) we'll need to clone the Tool Share repository:
  86. ```{.bash .shell-prompt}
  87. cd ~/repos
  88. git clone https://github.com/hello-robot/stretch_tool_share
  89. ```
  90. Copy the tool's URDF data into the Stretch ROS repository:
  91. ```{.bash .shell-prompt}
  92. cd ~/repos/stretch_tool_share/tool_share/dry_erase_holder_v1
  93. cp stretch_description/urdf/*.xacro ~/catkin_ws/src/stretch_ros/stretch_description/urdf/
  94. cp stretch_description/meshes/*.STL ~/catkin_ws/src/stretch_ros/stretch_description/meshes/
  95. ```
  96. Now we will update the tool Xacro for Stretch. Open the file `~/catkin_ws/src/stretch_ros/stretch_description/urdf/stretch_description.xacro` in an editor. Comment out the current tool Xacro and include the Xacro for the dry-erase holder.
  97. ```xml
  98. <?xml version="1.0"?>
  99. <robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="stretch_description">
  100. <!--<xacro:include filename="stretch_gripper.xacro" />-->
  101. <xacro:include filename="stretch_dry_erase_marker.xacro" />
  102. <xacro:include filename="stretch_main.xacro" />
  103. <xacro:include filename="stretch_aruco.xacro" />
  104. <xacro:include filename="stretch_d435i.xacro" />
  105. <xacro:include filename="stretch_laser_range_finder.xacro" />
  106. <xacro:include filename="stretch_respeaker.xacro" />
  107. </robot>
  108. ```
  109. Finally, we'll update the calibrated URDF to use this new tool:
  110. ```{.bash .shell-prompt}
  111. cd ~/catkin_ws/src/stretch_ros/stretch_description/urdf
  112. cp stretch.urdf stretch.urdf.bak
  113. rosrun stretch_calibration update_urdf_after_xacro_change.sh
  114. ```
  115. Press Ctrl-C when the `rosrun` command terminates and you're ready to visualize the tool in RViz:
  116. ```{.bash .shell-prompt}
  117. roslaunch stretch_calibration simple_test_head_calibration.launch
  118. ```
  119. ![](./images/dry_erase_rviz.png)
  120. # Advanced Topics
  121. ## Understanding How the Tool Plug-In Works
  122. For users looking to create their custom tools, it can be useful to understand how the tool plug-in architecture works. Here we will walk through the basics of the system for both Stretch Body and Stretch ROS
  123. ### Stretch Body
  124. The [Robot](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/robot.py#L97) class expects an instance of the EndOfArm tool to be present. The EndOfArm tool is an extension of the [DynamixelXChain](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/dynamixel_X_chain.py#L16) class, which manages a chain of Dynamixel servos.
  125. A tool is defined via its parameters (either in user YAML or Python). For example, the ToolStretchGripper is defined in [robot_params.py](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/robot_params.py). These parameters tell the plug-in which [DynamixelHelloXL430](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/dynamixel_hello_XL430.py) instances to load and manage. Here we see:
  126. ```python
  127. "tool_stretch_gripper": {
  128. 'use_group_sync_read': 1,
  129. 'retry_on_comm_failure': 1,
  130. 'baud':115200,
  131. 'verbose':0,
  132. 'py_class_name': 'ToolStretchGripper',
  133. 'py_module_name': 'stretch_body.end_of_arm_tools',
  134. 'stow': {'stretch_gripper': 0, 'wrist_yaw': 3.4},
  135. 'devices': {
  136. 'stretch_gripper': {
  137. 'py_class_name': 'StretchGripper',
  138. 'py_module_name': 'stretch_body.stretch_gripper'
  139. },
  140. 'wrist_yaw': {
  141. 'py_class_name': 'WristYaw',
  142. 'py_module_name': 'stretch_body.wrist_yaw'
  143. }
  144. }
  145. },
  146. ```
  147. This dictionary defines a tool of the class ToolStretchGripper with two [DynamixelHelloXL430](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/dynamixel_hello_XL430.py) devices on its bus (StretchGripper and WristYaw).
  148. We see that the [ToolStretchGripper](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/end_of_arm_tools.py#L7) class extends the EndOfArm class and provides its stowing behavior:
  149. ```python
  150. class ToolStretchGripper(EndOfArm):
  151. def __init__(self, name='tool_stretch_gripper'):
  152. EndOfArm.__init__(self,name)
  153. def stow(self):
  154. # Fold in wrist and gripper
  155. print('--------- Stowing Wrist Yaw ----')
  156. self.move_to('wrist_yaw', self.params['stow']['wrist_yaw'])
  157. print('--------- Stowing Gripper ----')
  158. self.move_to('stretch_gripper', self.params['stow']['stretch_gripper'])
  159. ```
  160. For tools that are not a part of Stretch Body, such as from the Tool Share, you must include the tool parameters as well in your `stretch_user_params.yaml`. A robot that supports many tools may have a user YAML that looks like:
  161. ```yaml
  162. params:
  163. - stretch_tool_share.usbcam_wrist_v1.params
  164. - stretch_tool_share.stretch_dex_wrist_beta.params
  165. - stretch_tool_share.dry_erase_holder_v1.params
  166. robot:
  167. tool: tool_dry_erase_holder_v1
  168. #tool: tool_none
  169. #tool: tool_stretch_gripper
  170. #tool: tool_usbcam_wrist_v1
  171. #tool: tool_stretch_dex_wrist_beta
  172. ```
  173. !!! tip
  174. For a more complex implementation of a tool, we recommend reviewing the Stretch Dex Wrist implementation on the Stretch Tool Share.
  175. ### Stretch ROS
  176. Stretch ROS also supports the tool plug-in architecture. Under ROS this is managed by extending the [SimpleCommandGroup](https://github.com/hello-robot/stretch_ros/blob/master/hello_helpers/src/hello_helpers/simple_command_group.py).
  177. More coming soon.
  178. ------
  179. <div align="center"> All materials are Copyright 2022 by Hello Robot Inc. Hello Robot and Stretch are registered trademarks.</div>