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.

156 lines
7.4 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
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: Parameter Management
  2. In this tutorial, we will discuss how parameters are managed in Stretch Body and show examples of how to customize your robot by overriding parameters.
  3. ## Overview
  4. Stretch Body shares a global set of parameters across all of the hardware it manages. All members of the [Device class](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/device.py) have an instance of [RobotParams](https://github.com/hello-robot/stretch_body/blob/master/body/stretch_body/robot_params.py). This class constructs a dictionary of the device parameters as well as the global parameters for each device. For example, from iPython try:
  5. ```python
  6. import stretch_body.arm
  7. a=stretch_body.arm.Arm()
  8. a.params
  9. ```
  10. ```{.python .no-copy}
  11. Out[7]:
  12. {'usb_name': '/dev/hello-motor-arm',
  13. 'force_N_per_A': 55.9
  14. 'chain_pitch': 0.0167,
  15. 'chain_sprocket_teeth': 10,
  16. 'gr_spur': 3.875,
  17. 'i_feedforward': 0,
  18. 'calibration_range_bounds': [0.515, 0.525],
  19. 'contact_model': 'effort_pct',
  20. 'contact_model_homing': 'effort_pct',
  21. 'contact_models': {'effort_pct': {'contact_thresh_calibration_margin': 10.0,
  22. 'contact_thresh_max': [-90.0, 90.0],
  23. 'contact_thresh_default': [-45.0, 45.0],
  24. 'contact_thresh_homing': [-45.0, 45.0]}},
  25. 'motion': {'default': {'accel_m': 0.14, 'vel_m': 0.14},
  26. 'fast': {'accel_m': 0.3, 'vel_m': 0.3},
  27. 'max': {'accel_m': 0.4, 'vel_m': 0.4},
  28. 'slow': {'accel_m': 0.05, 'vel_m': 0.05},
  29. 'trajectory_max': {'vel_m': 0.4, 'accel_m': 0.4}},
  30. 'range_m': [0.0, 0.52]}
  31. ```
  32. or to access another device params:
  33. ```python
  34. a.robot_params['lift']
  35. ```
  36. ```{.python .no-copy}
  37. Out[9]:
  38. {'usb_name': '/dev/hello-motor-lift',
  39. 'force_N_per_A': 75.0
  40. 'calibration_range_bounds': [1.094, 1.106],
  41. 'contact_model': 'effort_pct',
  42. 'contact_model_homing': 'effort_pct',
  43. 'contact_models': {'effort_pct': {'contact_thresh_calibration_margin': 10.0,
  44. 'contact_thresh_max': [-100, 100],
  45. 'contact_thresh_default': [-69.0, 69.0],
  46. 'contact_thresh_homing': [-69.0, 69.0]}},
  47. 'belt_pitch_m': 0.005,
  48. 'motion': {'default': {'accel_m': 0.2, 'vel_m': 0.11},
  49. 'fast': {'accel_m': 0.25, 'vel_m': 0.13},
  50. 'max': {'accel_m': 0.3, 'vel_m': 0.15},
  51. 'slow': {'accel_m': 0.05, 'vel_m': 0.05},
  52. 'trajectory_max': {'accel_m': 0.3, 'vel_m': 0.15}},
  53. 'pinion_t': 12,
  54. 'i_feedforward': 1.2,
  55. 'range_m': [0.0, 1.1]}
  56. ```
  57. ## Parameter Organization
  58. Stretch Body utilizes a prioritized parameter organization such that default settings can be easily overridden
  59. | Priority | Name | Location | Description |
  60. | -------- | --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
  61. | 1 | user_params | $HELLO_FLEET_PATH/$HELLO_FLEET_ID/ stretch_user_params.yaml | Yaml file for users to override default settings and to define custom configurations. |
  62. | 2 | configuration_params | $HELLO_FLEET_PATH/$HELLO_FLEET_ID/ stretch_configuration_params.yaml | Robot specific data (eg, serial numbers and calibrations). Calibration tools may update these. |
  63. | 3 | external_params | Imported via a list defined as `params` in stretch_user_params.yaml | External Python parameter dictionaries for 3rd party devices and peripherals. |
  64. | 4 | nominal_params | stretch_body.robot_params_RE2V0.py | Generic systems settings (common across all robots of a given model. |
  65. | 5 | nominal_system_params | stretch_body.robot_params.py | Generic systems settings (common across all robot models). |
  66. This allows the user to override any of the parameters by defining it in their `stretch_user_params.yaml`. It also allows Hello Robot to periodically update parameters defined in the Python files via Pip updates.
  67. The tool `stretch_params.py` will print out all of the robot parameters as well as their origin. For example:
  68. ```{.bash .shell-prompt}
  69. stretch_params.py
  70. ```
  71. ```{.bash .no-copy}
  72. ############################################################ Parameters for stretch-re2-xxxx
  73. Origin Parameter Value
  74. --------------------------------------------------------------------------------------------------------------------------------- ...
  75. stretch_body.robot_params.nominal_params param.arm.chain_pitch 0.0167
  76. stretch_body.robot_params.nominal_params param.arm.chain_sprocket_teeth 10 ...
  77. stretch_configuration_params.yaml param.arm.contact_models.effort_pct.contact_thresh_default [-45.0, 45.0]
  78. ```
  79. ## Manually Querying and Modifying Parameters
  80. A quick way to query parameters is with the `stretch_params.py` tool. For example, to look at parameters relating to the arm motion:
  81. ```{.bash .shell-prompt}
  82. stretch_params.py | grep arm | grep motion
  83. ```
  84. ```{.bash .no-copy}
  85. stretch_body.robot_params.nominal_params param.arm.motion.default.accel_m 0.14
  86. stretch_body.robot_params.nominal_params param.arm.motion.default.vel_m 0.14
  87. stretch_body.robot_params.nominal_params param.arm.motion.fast.accel_m 0.3
  88. stretch_body.robot_params.nominal_params param.arm.motion.fast.vel_m 0.3
  89. stretch_body.robot_params.nominal_params param.arm.motion.max.accel_m 0.4
  90. stretch_body.robot_params.nominal_params param.arm.motion.max.vel_m 0.4
  91. stretch_body.robot_params.nominal_params param.arm.motion.slow.accel_m 0.05
  92. stretch_body.robot_params.nominal_params param.arm.motion.slow.vel_m 0.05
  93. ...
  94. ```
  95. The tool displays each parameter's value as well as which parameter file it was loaded from.
  96. For example, if you want to override the default motion settings for the arm, you could add the following to your `stretch_user_params.yaml`:
  97. ```yaml
  98. arm:
  99. motion:
  100. default:
  101. vel_m: 0.1
  102. accel_m: 0.1
  103. ```
  104. Run the tool again and we see:
  105. ```{.bash .shell-prompt}
  106. stretch_params.py | grep arm | grep motion | grep default
  107. ```
  108. ```{.bash .no-copy}
  109. stretch_body.robot_params.nominal_params param.arm.motion.default.accel_m 0.1
  110. stretch_body.robot_params.nominal_params param.arm.motion.default.vel_m 0.1
  111. ```
  112. !!! note
  113. The factory parameter settings should suffice for most use cases.
  114. ## Programmatically Modifying and Storing Parameters
  115. A user can compute the value of a parameter programmatically and modify the robot settings accordingly. For example, in the Stretch Factory tool [REx_base_calibrate_wheel_separation.py](https://github.com/hello-robot/stretch_factory/blob/master/python/tools/REx_base_calibrate_wheel_separation.py) we see that the parameter `wheel_separation_m` is recomputed as the variable `d_avg`. This new value could be used during the robot execution by simply:
  116. ```python
  117. robot.base.params['wheel_separation_m']=d_vag
  118. ```
  119. or it could be saved as a user override:
  120. ```python
  121. robot.write_user_param_to_YAML('base.wheel_separation_m', d_avg)
  122. ```
  123. This will update the file `stretch_user_params.yaml`.
  124. ------
  125. <div align="center"> All materials are Copyright 2022 by Hello Robot Inc. Hello Robot and Stretch are registered trademarks.</div>