Wheeled inverted pendulum model.
More...
|
def | __init__ (self, float fall_pitch=1.0, float frequency=200.0, bool frequency_checks=True, float length=0.6, float max_ground_accel=10.0, float max_ground_velocity=1.0, bool regulate_frequency=True, Optional[str] render_mode=None, Optional["WheeledInvertedPendulum.Uncertainty"] uncertainty=None) |
| Initialize a new environment. More...
|
|
Tuple[np.ndarray, dict] | reset (self, *Optional[int] seed=None, Optional[dict] options=None) |
| Resets the spine and get an initial observation. More...
|
|
Tuple[np.ndarray, float, bool, bool, dict] | step (self, np.ndarray action) |
| Run one timestep of the environment's dynamics. More...
|
|
bool | detect_fall (self, float pitch) |
| Detect a fall based on the base-to-world pitch angle. More...
|
|
def | render (self) |
| Render state to a live plot.
|
|
def | log (self, str name, Any entry) |
| Log a new entry to the "log" key of the action dictionary. More...
|
|
|
| observation_space |
| Observation space.
|
|
| action_space |
| Action space.
|
|
| dt |
| Period of the control loop in seconds.
|
|
| fall_pitch |
| Fall pitch angle, in radians.
|
|
| length |
| Length of the inverted pendulum.
|
|
| model |
| Robot model read from its URDF description.
|
|
| plot |
| Optional plot used for rendering.
|
|
| render_mode |
| Inherited from gymnasium.Env.
|
|
| uncertainty |
| Biases and noise levels on modeled system uncertainties.
|
|
|
dictionary | metadata = {"render_modes": ["plot"]} |
| Metadata of the environment containing rendering modes.
|
|
int | version = 1 |
| Environment version number.
|
|
Wheeled inverted pendulum model.
This environment helps test and debug behaviors in a perfect or noise-controlled setting. It has the same observation and action spaces as upkie.envs.upkie_ground_velocity.UpkieGroundVelocity. Model assumptions and discretization are summed up in this note.
Action space
The action corresponds to the ground velocity resulting from wheel velocities. The action vector is simply:
Index | Description |
0 | Ground velocity in [m] / [s]. |
Observation space
Vectorized observations have the following structure:
Index | Description |
0 | Pitch angle of the base with respect to the world vertical, in radians. This angle is positive when the robot leans forward. |
1 | Position of the average wheel contact point, in meters. |
2 | Body angular velocity of the base frame along its lateral axis, in radians per seconds. |
3 | Velocity of the average wheel contact point, in meters per seconds. |
◆ __init__()
def upkie.envs.wheeled_inverted_pendulum.WheeledInvertedPendulum.__init__ |
( |
|
self, |
|
|
float |
fall_pitch = 1.0 , |
|
|
float |
frequency = 200.0 , |
|
|
bool |
frequency_checks = True , |
|
|
float |
length = 0.6 , |
|
|
float |
max_ground_accel = 10.0 , |
|
|
float |
max_ground_velocity = 1.0 , |
|
|
bool |
regulate_frequency = True , |
|
|
Optional[str] |
render_mode = None , |
|
|
Optional["WheeledInvertedPendulum.Uncertainty"] |
uncertainty = None |
|
) |
| |
Initialize a new environment.
- Parameters
-
fall_pitch | Fall detection pitch angle, in [rad]. |
frequency | Regulated frequency of the control loop, in Hz. |
frequency_checks | If regulate_frequency is set and this parameter is true (default), a warning is issued every time the control loop runs slower than the desired frequency . Set this parameter to false to disable these warnings. |
length | Length of the pole. |
max_ground_velocity | Maximum commanded ground velocity in [m] / [s]. |
max_ground_accel | Maximum acceleration of the ground point, in [m] / [s]². |
regulate_frequency | Enables loop frequency regulation. |
render_mode | Rendering mode, set to "plot" for live plotting. |
uncertainty | Uncertainty biases and noise magnitudes. |
◆ detect_fall()
bool upkie.envs.wheeled_inverted_pendulum.WheeledInvertedPendulum.detect_fall |
( |
|
self, |
|
|
float |
pitch |
|
) |
| |
Detect a fall based on the base-to-world pitch angle.
- Parameters
-
pitch | Pitch angle of the rotation from base to world frame. |
- Returns
- True if and only if a fall is detected.
◆ log()
def upkie.envs.wheeled_inverted_pendulum.WheeledInvertedPendulum.log |
( |
|
self, |
|
|
str |
name, |
|
|
Any |
entry |
|
) |
| |
Log a new entry to the "log" key of the action dictionary.
- Parameters
-
name | Name of the entry. |
entry | Dictionary to log along with the actual action. |
◆ reset()
Tuple[np.ndarray, dict] upkie.envs.wheeled_inverted_pendulum.WheeledInvertedPendulum.reset |
( |
|
self, |
|
|
*Optional[int] |
seed = None , |
|
|
Optional[dict] |
options = None |
|
) |
| |
Resets the spine and get an initial observation.
- Parameters
-
seed | Number used to initialize the environment’s internal random number generator. |
options | Currently unused. |
- Returns
observation
: Initial vectorized observation, i.e. an element of the environment's observation_space
.
info
: Dictionary with auxiliary diagnostic information. For Upkie this is the full observation dictionary sent by the spine.
◆ step()
Tuple[np.ndarray, float, bool, bool, dict] upkie.envs.wheeled_inverted_pendulum.WheeledInvertedPendulum.step |
( |
|
self, |
|
|
np.ndarray |
action |
|
) |
| |
Run one timestep of the environment's dynamics.
When the end of the episode is reached, you are responsible for calling reset()
to reset the environment's state.
- Parameters
-
action | Action from the agent. |
- Returns
observation
: Observation of the environment, i.e. an element of its observation_space
.
reward
: Reward returned after taking the action.
terminated
: Whether the agent reached a terminal state, which can be a good or a bad thing. When true, the user needs to call reset()
.
truncated
: Whether the episode is reaching max number of steps. This boolean can signal a premature end of the episode, i.e. before a terminal state is reached. When true, the user needs to call reset()
.
info
: Dictionary with auxiliary diagnostic information. For us this is the full observation dictionary coming from the spine.
The documentation for this class was generated from the following file:
- upkie/envs/wheeled_inverted_pendulum.py