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.

164 lines
6.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
1 year 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
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: Contact Models
  2. This tutorial introduces the Stretch Body contact detection system and explains how to configure it for your application.
  3. ## What is Guarded Contact?
  4. Guarded contact is our term for the Stretch contact sensitive behaviors. The guarded contact behavior is simply:
  5. 1. Detect when the actuator effort exceeds a user-specified threshold during joint motion.
  6. 2. If the threshold is exceeded:
  7. 1. Enable the default safety controller for the joint
  8. 2. Remain in safety mode until a subsequent joint command is received
  9. Practically this enables the arm, for example, to move out yet stop upon collision. Let's test this out with the following script:
  10. ```python
  11. #!/usr/bin/env python
  12. import time
  13. import stretch_body.robot
  14. robot=stretch_body.robot.Robot()
  15. robot.startup()
  16. #Move to full retraction
  17. robot.arm.move_to(0.0)
  18. robot.push_command()
  19. robot.arm.wait_until_at_setpoint()
  20. input('Arm will extend and respond to contact. Manually attempt to stop it. Hit enter when ready')
  21. robot.arm.move_to(0.3)
  22. robot.push_command()
  23. robot.arm.wait_until_at_setpoint(timeout=5.0)
  24. #Now turn off guarded contacts
  25. input('Arm will retract but will not respond to contact. Manually attempt to stop it. Hit enter when ready')
  26. robot.arm.motor.disable_guarded_mode()
  27. robot.arm.move_to(0.0)
  28. robot.push_command()
  29. robot.arm.wait_until_at_setpoint(timeout=5.0)
  30. robot.stop()
  31. ```
  32. You should see that the arm stops on contact when it extends, however, it doesn't stop on contact when it then retracts. This is the guarded contact behavior in action.
  33. ## Specifying Guarded Contacts
  34. The four stepper joints (base, arm, and lift) all support guarded contact settings when executing motion. This is evident in their `move_to` and `move_by` methods. For example, we see in the Arm's base class of [PrismaticJoint](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/prismatic_joint.py):
  35. ```python
  36. def move_by(self,x_m,v_m=None, a_m=None, stiffness=None, contact_thresh_pos_N=None,contact_thresh_neg_N=None, req_calibration=True,contact_thresh_pos=None,contact_thresh_neg=None)
  37. ```
  38. In this method, you can optionally specify a contact threshold in the positive and negative direction with `contact_thresh_pos` and `contact_thresh_neg` respectively.
  39. !!! note
  40. These optional parameters will default to `None`, in which case the motion will adopt the default settings as defined by the robot's parameters.
  41. !!! warning
  42. The parameters `contact_thresh_pos_N` and `contact_thresh_neg_N` are deprecated and no longer supported.
  43. ```{.bash .shell-prompt}
  44. stretch_params.py | grep arm | grep contact
  45. ```
  46. ```{.bash .no-copy}
  47. ...
  48. stretch_configuration_params.yaml param.arm.contact_models.effort_pct.contact_thresh_default [-45.0, 45.0]
  49. ...
  50. ```
  51. ## Contact Models
  52. A contact model is simply a function that, given a user-specified contact threshold, computes the motor current at which the motor controller will trigger a guarded contact. The following contact models are currently implemented:
  53. ### The Effort-Pct Contact Model
  54. [Effort-Pct](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/prismatic_joint.py) is the default contact model for Stretch 2. It simply scales the maximum range of motor currents into the range of [-100,100]. Thus, if you desire to have the robot arm extend but stop at 50% of its maximum current, you would write:
  55. ```python
  56. robot.arm.move_by(0.1,contact_thresh_pos=50.0)
  57. ```
  58. ## Adjusting Contact Behaviors
  59. The default factory settings for contact thresholds are tuned to allow Stretch to move throughout its workspace without triggering false-positive guarded contact events. These settings are the worst-case tuning as they account for the internal disturbances of the Stretch drive-train across its entire workspace.
  60. It is possible to obtain greater contact sensitivity in carefully selected portions of the arm and lift workspace. Users who wish to programmatically adjust contact behaviors can create a simple test script and experiment with different values. For example:
  61. ```python
  62. #!/usr/bin/env python
  63. import time
  64. import stretch_body.robot
  65. robot=stretch_body.robot.Robot()
  66. robot.startup()
  67. cpos = 30.0
  68. cneg = -30.0
  69. robot.arm.move_to(0.0, contact_thresh_pos=cpos, contact_thresh_neg=cneg)
  70. robot.push_command()
  71. robot.arm.wait_until_at_setpoint()
  72. robot.arm.move_to(0.5,contact_thresh_pos=cpos, contact_thresh_neg=cneg)
  73. robot.push_command()
  74. robot.arm.wait_until_at_setpoint(timeout=5.0)
  75. robot.stop()
  76. ```
  77. ## Guarded Contact with the Base
  78. Guarded contacts are enabled by default for the arm and lift as they typically require safe and contact-sensitive motion. They are turned off on the base by default as varying surface terrain can produce undesired false-positive events.
  79. That being said, guarded contacts can be enabled on the base. They may be useful as a simple bump detector such that the base will stop when it runs into a wall.
  80. ```python
  81. #!/usr/bin/env python
  82. import time
  83. import stretch_body.robot
  84. robot=stretch_body.robot.Robot()
  85. robot.startup()
  86. robot.base.left_wheel.enable_guarded_mode()
  87. robot.base.right_wheel.enable_guarded_mode()
  88. robot.base.move_by(0.025)
  89. robot.push_command()
  90. robot.base.wait_until_at_setpoint()
  91. robot.base.move_by(-0.025)
  92. robot.push_command()
  93. robot.base.wait_until_at_setpoint()
  94. robot.stop()
  95. ```
  96. ## Advanced: Calibrating Contact Thresholds
  97. The Stretch Factory package provides a tool to allow advanced users to recalibrate the default guarded contact thresholds. This tool can be useful if you've added additional payload to the arm and are experiencing false-positive guarded contact detections.
  98. The tool sweeps the joint through its range of motion for `n-cycle` iterations. It computes the maximum contact forces in both directions, adds padding, `contact_thresh_calibration_margin`, to this value, and stores it to the robot's configuration YAML.
  99. ```{.bash .shell-prompt}
  100. REx_calibrate_guarded_contact.py -h
  101. ```
  102. ```{.bash .no-copy}
  103. For use with S T R E T C H (R) RESEARCH EDITION from Hello Robot Inc.
  104. ---------------------------------------------------------------------
  105. usage: REx_calibrate_guarded_contact.py [-h] (--lift | --arm) [--ncycle NCYCLE]
  106. Calibrate the default guarded contacts for a joint.
  107. optional arguments:
  108. -h, --help show this help message and exit
  109. --lift Calibrate the lift joint
  110. --arm Calibrate the arm joint
  111. --ncycle NCYCLE Number of sweeps to run [4]
  112. ```
  113. ------
  114. <div align="center"> All materials are Copyright 2022 by Hello Robot Inc. Hello Robot and Stretch are registered trademarks.</div>