bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::dynamics::CartPoleDynamics Class Reference

A cart on a straight track, pushed by a horizontal force F, with a pole hinged on it. More...

#include <cart_pole_dynamics.h>

Public Member Functions

 CartPoleDynamics (const CartPoleParameters &parameters=CartPoleParameters(), const CartPoleState &state=CartPoleState::Zero())
void step (real_t force, real_t dt)
 Advance by dt [s], with the force F [N] held over the step.
CartPoleState derivative (const CartPoleState &x, real_t force) const
CartPoleLinearModel linearise (const CartPoleState &x=CartPoleState::Zero(), real_t force=0.0) const
real_t limit (real_t force) const
real_t energy (const CartPoleState &x) const
bool off_track () const
const CartPoleState & state () const noexcept
CartPoleState & state () noexcept
const CartPoleParameters & parameters () const noexcept
real_t time () const noexcept

Detailed Description

A cart on a straight track, pushed by a horizontal force F, with a pole hinged on it.

The pole is a uniform rod of mass m with its centre l from the pivot, on a cart of mass M, without friction. With \(\theta\) the angle of the pole from upright,

\[\ddot\theta = \frac{g \sin\theta - \cos\theta \, \tau}{l \left(\tfrac{4}{3} - \tfrac{m \cos^2\theta}{M + m}\right)}, \quad \ddot x = \tau - \frac{m l \ddot\theta \cos\theta}{M + m}, \quad \tau = \frac{F + m l \dot\theta^2 \sin\theta}{M + m} , \]

the equations of Barto, Sutton and Anderson. Upright, \(\theta = 0\), is an equilibrium, and an unstable one: the model is the classic test of a controller that has to balance something.

step() integrates with fourth order Runge-Kutta, with the force first limited to max_force. The track is not a wall: off_track() says when the cart has gone past its end, and the application decides what that means.

Constructor & Destructor Documentation

◆ CartPoleDynamics()

bitsim::dynamics::CartPoleDynamics::CartPoleDynamics ( const CartPoleParameters & parameters = CartPoleParameters(),
const CartPoleState & state = CartPoleState::Zero() )
explicit

Member Function Documentation

◆ derivative()

CartPoleState bitsim::dynamics::CartPoleDynamics::derivative ( const CartPoleState & x,
real_t force ) const
Returns
The derivative of the state, for the state and the force, which is not limited

◆ energy()

real_t bitsim::dynamics::CartPoleDynamics::energy ( const CartPoleState & x) const
Returns
The kinetic and the potential energy, the potential from the pivot

◆ limit()

real_t bitsim::dynamics::CartPoleDynamics::limit ( real_t force) const
Returns
The force limited to [-max_force, max_force]

◆ linearise()

CartPoleLinearModel bitsim::dynamics::CartPoleDynamics::linearise ( const CartPoleState & x = CartPoleState::Zero(),
real_t force = 0.0 ) const
Returns
The model linearised about the state x and the force, by central differences

◆ off_track()

bool bitsim::dynamics::CartPoleDynamics::off_track ( ) const
Returns
Whether the cart is past either end of the track

◆ parameters()

const CartPoleParameters & bitsim::dynamics::CartPoleDynamics::parameters ( ) const
inlinenoexcept

◆ state() [1/2]

const CartPoleState & bitsim::dynamics::CartPoleDynamics::state ( ) const
inlinenoexcept

◆ state() [2/2]

CartPoleState & bitsim::dynamics::CartPoleDynamics::state ( )
inlinenoexcept

◆ step()

void bitsim::dynamics::CartPoleDynamics::step ( real_t force,
real_t dt )

Advance by dt [s], with the force F [N] held over the step.

◆ time()

real_t bitsim::dynamics::CartPoleDynamics::time ( ) const
inlinenoexcept

The documentation for this class was generated from the following files: