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.

92 lines
3.9 KiB

2 years ago
  1. # Tutorial: Custom Wrist DOF
  2. In this tutorial, we explore how to add additional degrees of freedom to the Stretch wrist.
  3. Stretch exposes a Dynamixel X-Series TTL control bus at the end of its arm. It uses the [Dynamixel XL430-W250](https://emanual.robotis.com/docs/en/dxl/x/xl430-w250/) for the [Wrist Yaw](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/wrist_yaw.py) and the [Stretch Gripper](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/stretch_gripper.py) that comes standard with the robot.
  4. See the [Hardware User Guide](https://docs.hello-robot.com/0.2/stretch-hardware-guides/docs/hardware_guide_re2/#wrist-tool-plate) to learn how to mechanically attach additional DOFs to the robot.
  5. !!! note
  6. Stretch is compatible with any [Dynamixel X Series servo](https://emanual.robotis.com/docs/en/dxl/x/) that utilizes the TTL level Multidrop Bus.
  7. ## Adding a Custom DOF
  8. Adding one or more custom Dynamixel X Series servos to Stretch wrist involves:
  9. * Creating a new class that derives from [DynamixelHelloXL430](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/dynamixel_hello_XL430.py)
  10. * Adding YAML parameters to `stretch_user_params.yaml` that configure the servo as desired
  11. * Adding YAML parameters to `stretch_user_params.yaml` that tell Stretch to include this class in its EndOfArm list of servos
  12. Let's create a new DOF called MyWristPitch in a file named [my_wrist_pitch.py](./custom_wrist_dof/my_wrist_pitch.py). Place the file somewhere on the $PYTHONPATH.
  13. ```python
  14. from stretch_body.dynamixel_hello_XL430 import DynamixelHelloXL430
  15. from stretch_body.hello_utils import *
  16. class MyWristPitch(DynamixelHelloXL430):
  17. def __init__(self, chain=None):
  18. DynamixelHelloXL430.__init__(self, 'my_wrist_pitch', chain)
  19. self.poses = {'tool_up': deg_to_rad(45),
  20. 'tool_down': deg_to_rad(-45)}
  21. def pose(self,p,v_r=None,a_r=None):
  22. self.move_to(self.poses[p],v_r,a_r)
  23. ```
  24. Now let's add the tools' parameters to your `stretch_user_params.yaml` to configure this servo. You may want to adapt these parameters to your application but the nominal values [found here](./custom_wrist_dof/stretch_user_params.yaml) usually work well. Below we highlight some of the more useful parameters.
  25. ```yaml
  26. my_wrist_pitch:
  27. id: 1 #ID on the Dynamixel bus
  28. range_t: #Range of servo, in ticks
  29. - 0
  30. - 4096
  31. req_calibration: 0 #Does the joint require homing after startup
  32. use_multiturn: 0 #Single turn or multi-turn mode of rotation
  33. zero_t: 2048 #Position in ticks that corresponds to zero radians
  34. ```
  35. For this example, we are assuming a single-turn joint that doesn't require hard stop-based homing. We also assume the servo has the Robotis default ID of 1.
  36. At this point, your MyWristPitch class is ready to use. Plug the servo into the cable leaving the Stretch WristYaw joint. Experiment with the API from iPython
  37. ```python
  38. In [1]: import my_wrist_pitch
  39. In [2]: w=wrist_pitch.WristPitch()
  40. In [3]: w.startup()
  41. In [4]: w.move_by(0.1)
  42. In [5]: w.pose('tool_up')
  43. In [6]: w.pose('tool_down')
  44. ```
  45. Finally, you'll want to make your WristPitch available from `stretch_body.robot`. Add the following [YAML](./custom_wrist_dof/stretch_user_params.yaml) to your `stretch_user_params.yaml`
  46. ```yaml
  47. end_of_arm:
  48. devices:
  49. wrist_pitch:
  50. py_class_name: WristPitch
  51. py_module_name: wrist_pitch
  52. ```
  53. This tells `stretch_body.robot` to manage a `wrist_pitch.WristPitch` instance and add it to the [EndOfArm](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/end_of_arm.py) list of tools. Try it from iPython:
  54. ```python
  55. In [1]: import stretch_body.robot as robot
  56. In [2]: r=robot.Robot()
  57. In [3]: r.startup()
  58. In [4]: r.end_of_arm.move_by('wrist_pitch',0.1)
  59. ```
  60. ------
  61. <div align="center"> All materials are Copyright 2022 by Hello Robot Inc. Hello Robot and Stretch are registered trademarks.</div>