upkie 6.1.0
Open-source wheeled biped robots
Loading...
Searching...
No Matches
upkie.envs.wheeled_inverted_pendulum.WheeledInvertedPendulum Class Reference

Wheeled inverted pendulum model. More...

Classes

class  Uncertainty
 Biases and noise levels on modeled system uncertainties. More...
 

Public Member Functions

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...
 

Public Attributes

 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.
 

Static Public Attributes

dictionary metadata = {"render_modes": ["plot"]}
 Metadata of the environment containing rendering modes.
 
int version = 1
 Environment version number.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __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_pitchFall detection pitch angle, in [rad].
frequencyRegulated frequency of the control loop, in Hz.
frequency_checksIf 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.
lengthLength of the pole.
max_ground_velocityMaximum commanded ground velocity in [m] / [s].
max_ground_accelMaximum acceleration of the ground point, in [m] / [s]².
regulate_frequencyEnables loop frequency regulation.
render_modeRendering mode, set to "plot" for live plotting.
uncertaintyUncertainty biases and noise magnitudes.

Member Function Documentation

◆ 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
pitchPitch 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
nameName of the entry.
entryDictionary 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
seedNumber used to initialize the environment’s internal random number generator.
optionsCurrently 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
actionAction 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: