|
upkie
11.0.0
Open-source wheeled biped robots
|
Upkie environment where actions command servomotors directly. More...
Public Member Functions | |
| None | __init__ (self, Backend backend, Optional[float] frequency=200.0, bool frequency_checks=True, Optional[RobotState] init_state=None, bool regulate_frequency=True, float max_gain_scale=5.0, Optional[Model] model=None) |
| Initialize servos environment. More... | |
| dict | get_env_observation (self, dict spine_observation) |
| Extract environment observation from spine observation dictionary. More... | |
| dict | get_neutral_action (self) |
| Get the neutral action where servos don't move. More... | |
| dict | get_spine_action (self, dict env_action) |
| Convert environment action to a spine action dictionary. More... | |
| None | close (self) |
| Close the environment and clean up resources. More... | |
| Optional[float] | dt (self) |
Regulated period of the control loop in seconds, or None if there is no loop frequency regulation. | |
| Optional[float] | frequency (self) |
Regulated frequency of the control loop in Hz, or None if there is no loop frequency regulation. | |
| dict | get_spine_action (self, env_action) |
| Get spine action from Gym environment action. More... | |
| None | log (self, str name, Any entry) |
| Log a new entry to the "env" key of the action dictionary. More... | |
| Tuple[dict, dict] | reset (self, Optional[int] seed=None, Optional[dict] options=None) |
| Resets the backend and get an initial observation. More... | |
| Tuple[dict, float, bool, bool, dict] | step (self, dict action) |
| Run one timestep of the environment's dynamics. More... | |
| None | update_init_rand (self, **kwargs) |
| Update initial-state randomization. More... | |
Public Attributes | |
| action_space | |
| Action space of the environment. | |
| observation_space | |
| Observation space of the environment. | |
| backend | |
| Spine or simulation backend. | |
| init_state | |
| Initial state for the floating base of the robot, which may be randomized upon resets. | |
| model | |
| Upkie robot model. | |
Upkie environment where actions command servomotors directly.
Actions and observations correspond to the moteus servo API.
The action space is a dictionary with one key for each servo:
left_hip: left hip joint (qdd100)left_knee: left knee joint (qdd100)left_wheel: left wheel joint (mj5208)right_hip: right hip joint (qdd100)right_knee: right knee joint (qdd100)right_wheel: right wheel joint (mj5208)The value for each servo dictionary is itself a dictionary with the following keys:
position: commanded joint angle \(\theta^*\) in radians (NaN to disable) (required).velocity: commanded joint velocity \(\dot{\theta}^*\) in rad/s (required).feedforward_torque: feedforward joint torque \(\tau_{\mathit{ff}}\) in N·m.kp_scale: scaling factor \(k_{p}^{\mathit{scale}}\) applied to the position feedback gain, between zero and one.kd_scale: scaling factor \(k_{d}^{\mathit{scale}}\) applied to the velocity feedback gain, between zero and one.maximum_torque: maximum joint torque \(\tau_{\mathit{max}}\) (feedforward + feedback) enforced during the whole actuation step, in N⋅m.The resulting torque applied by the servo is then:
\[ \begin{align*} \tau & = \underset{ [-\tau_{\mathit{max}}, +\tau_{\mathit{max}}]}{ \mathrm{clamp} } \left( \tau_{\mathit{ff}} + k_{p} k_{p}^{\mathit{scale}} (\theta^* - \theta) + k_{d} k_{d}^{\mathit{scale}} (\dot{\theta}^* - \dot{\theta})) \right) \end{align*} \]
Position and velocity gains \(k_{p}\) and \(k_{d}\) are configured in each moteus controller directly and don't change during execution. We can rather modulate the overall feedback gains via the normalized parameters \(k_{p}^{\mathit{scale}} \in [0, 1]\) and \(k_{d}^{\mathit{scale}} \in [0, 1]\). Note that the servo regulates the torque above at its own frequency, which is higher (typically 40 kHz) than the agent and the spine frequencies. See the moteus reference for more details.
The observation space is a dictionary with one key for each servo. The value for each key is a dictionary with keys:
position: Joint angle in rad.velocity: Joint velocity in rad/s.torque: Joint torque in N⋅m.temperature: Servo temperature in degree Celsius.voltage: Power bus voltage of the servo, in V.Full observations from the backend (detailed in Observations) are also available in the info dictionary returned by the reset and step functions.