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

DiffDriveDynamics class. Describes the motion of a differential drive robot in the plane: the centre of its axle at (x, y), facing theta. Three versions: More...

#include <diff_drive_dynamics.h>

Inheritance diagram for bitsim::dynamics::DiffDriveDynamics:
Collaboration diagram for bitsim::dynamics::DiffDriveDynamics:

Public Types

enum class  DynamicVersion { V1 , V2 , V3 }
 The DynamicVersion enum. Helper enum to disambiguate the two supplied configurations. More...
using state_type
 The type of the state handled by this dynamics object.
using input_type
 input_t The type of the input for solving the dynamics
using matrix_type
 matrix_t Matrix type that describes the dynamics
using vector_type
 vector_t
Public Types inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >
using state_type
using output_type
using input_type
using matrix_descriptor_type
using matrix_type
using vector_type

Public Member Functions

 DiffDriveDynamics (DynamicVersion type=DynamicVersion::V1, bool update_description_matrices_on_evaluate=true)
 Constructor.
 DiffDriveDynamics (state_type &&state)
 Constructor.
virtual state_type & evaluate (const input_type &input) override
 Evaluate the new state using the given input it also updates the various matrices if needed.
void integrate (const input_type &input)
 Integrate the new state. It also uses error terms.
real_t get_x_position () const
 Read the x-coordinate.
void set_x_position (real_t x)
 Set the x-coordinate.
real_t get_y_position () const
 Read the y-coordinate.
void set_y_position (real_t y)
 Set the y-coordinate.
real_t get_orientation () const
 Read the y-coordinate.
void set_orientation (real_t theta)
 Set the orientation.
real_t get_velocity () const
 get_velocity Returns the velocity used for integration
real_t get_angular_velocity () const
 get_velocity Returns the angular velocity used for integration
void update_matrices (const input_type &input)
 updates the matrices used to describe this motion model
void initialize_matrices (const input_type &input)
 Initialize the matrices describing the the dynamics.
Public Member Functions inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >
virtual ~MotionModelDynamicsBase ()=default
 Destructor.
virtual state_type & evaluate (const input_type &input)=0
 Updates and returns the value of the state given the input.
const state_type & get_state () const
 Read access to the state.
state_type & get_state ()
 Read/write access to the state.
std::vector< std::string_view > get_state_variables_names () const
 get_state_variables_names. Returns the name of the variables in the state
matrix_type & get_matrix (const std::string &name)
const matrix_type & get_matrix (const std::string &name) const
void set_matrix (const std::string &name, const matrix_type &mat)
vector_type & get_vector (const std::string &name)
const vector_type & get_vector (const std::string &name) const
void set_vector (const std::string &name, const vector_type &vec)
void set_matrix_update_flag (bool f)
 set the matrix update flag
bool allows_matrix_updates () const
 Set the flag for updating or not the matrices describing the model.
bool has_matrix (const std::string &name) const
 Returns true if the matrix with the given name already exists.
real_t get_state_property (const std::string &name) const
 Returns the state property with the given name.
void set_state_property (const std::string &name, real_t value)
 Set the name-th value of the state.
void set_state_name_value (uint_t i, const std::string &name, real_t val)
 Set the state names.
void set_state_name_value (uint_t i, const std::pair< std::string, real_t > &val)
 Set the state names.
void set_time_step (real_t dt)
 Set the time step.
real_t get_time_step () const
 get_time_step Returns the sampling time the dynamics model is using
real_t get_tolerance () const
 get_tolerance Returns the general tolerance used in the calculations
void set_tolerance (real_t tol)
 set_tolerance Set the general tolerance used in the calculations. Default is KernelConsts::tolerance()

Static Public Member Functions

static SysState< 3 > integrate_state_v1 (const SysState< 3 > &state, real_t tol, real_t dt, real_t v, real_t w, const std::array< real_t, 2 > &errors)
 integrate_state_v1
static SysState< 3 > integrate_state_v2 (const SysState< 3 > &state, real_t dt, real_t v, real_t w, const std::array< real_t, 2 > &errors)
 integrate_state_v2
static SysState< 3 > integrate_state_v3 (const SysState< 3 > &state, real_t r, real_t l, real_t dt, real_t w1, real_t w2, const std::array< real_t, 2 > &errors)
 integrate_state_v3
static SysState< 3 > integrate (const SysState< 3 > &state, const input_type &input, const DynamicVersion version)
 integrate Factory method to apply the different integration methods

Additional Inherited Members

Static Public Attributes inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >
static const uint_t state_dimension
 The dimension of the state.
Protected Member Functions inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >
 MotionModelDynamicsBase (bool update_description_matrices_on_evaluate=true)
 Constructor.
 MotionModelDynamicsBase (const state_type &init_state, bool update_description_matrices_on_evaluate=true)
 Constructor.
Protected Attributes inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >
state_type state_
 The object describing the state of the object of which its dynamics are described/modeled by this MotionModel.
matrix_descriptor_type matrix_description_
 matrix descriptor
bool update_description_matrices_on_evaluate_
 flag indicating the update of the matrices the model is using to describe itself
real_t dt_
 The time step the integrator uses.
real_t tol_
 tolerance

Detailed Description

DiffDriveDynamics class. Describes the motion of a differential drive robot in the plane: the centre of its axle at (x, y), facing theta. Three versions:

  • V1, the default: the input is the speed v [m/s] and the rate of turn w [rad/s], and over a step the robot drives an arc of length \(d = v \Delta t + e_0\) that turns it by \(\phi = \omega \Delta t + e_1\), where \(e_0\) and \(e_1\) are the errors:

    \[ x' = x + \frac{d}{\phi} (\sin\theta' - \sin\theta), \quad y' = y - \frac{d}{\phi} (\cos\theta' - \cos\theta), \quad \theta' = \theta + \phi \]

    With \(|\phi|\) below the tolerance it moves by d along \(\theta + \phi/2\), what the arc tends to. With no errors this is exact for a constant v and w. update_matrices() gives its Jacobians F, with respect to the state, and L, with respect to the errors, for an extended Kalman filter. theta' is wrapped to \((-\pi, \pi]\).
  • V2: a forward Euler step with v and w: the robot moves along its heading, then turns.
  • V3: the speeds of the two wheels as input, w1 and w2, with the wheel radius r and l, and a forward Euler step.

Member Typedef Documentation

◆ input_type

Initial value:
std::map<std::string, std::any>>::input_type
MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >::input_type input_type
input_t The type of the input for solving the dynamics
Definition diff_drive_dynamics.h:61
The DynamicsMatrixDescriptor class. Helper class to model the matrix representon of dynamical systems...
Definition dynamics_matrix_descriptor.h:19

input_t The type of the input for solving the dynamics

◆ matrix_type

Initial value:
std::map<std::string, std::any>>::matrix_type
MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >::matrix_type matrix_type
matrix_t Matrix type that describes the dynamics
Definition diff_drive_dynamics.h:67

matrix_t Matrix type that describes the dynamics

◆ state_type

Initial value:
std::map<std::string, std::any>>::state_type
MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >::state_type state_type
The type of the state handled by this dynamics object.
Definition diff_drive_dynamics.h:55

The type of the state handled by this dynamics object.

◆ vector_type

Initial value:
std::map<std::string, std::any>>::vector_type
MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >::vector_type vector_type
vector_t
Definition diff_drive_dynamics.h:73

vector_t

Member Enumeration Documentation

◆ DynamicVersion

The DynamicVersion enum. Helper enum to disambiguate the two supplied configurations.

Enumerator
V1 
V2 
V3 

Constructor & Destructor Documentation

◆ DiffDriveDynamics() [1/2]

bitsim::dynamics::DiffDriveDynamics::DiffDriveDynamics ( DiffDriveDynamics::DynamicVersion type = DynamicVersion::V1,
bool update_description_matrices_on_evaluate = true )
explicit

Constructor.

◆ DiffDriveDynamics() [2/2]

bitsim::dynamics::DiffDriveDynamics::DiffDriveDynamics ( DiffDriveDynamics::state_type && state)
explicit

Constructor.

Member Function Documentation

◆ evaluate()

DiffDriveDynamics::state_type & bitsim::dynamics::DiffDriveDynamics::evaluate ( const input_type & input)
overridevirtual

Evaluate the new state using the given input it also updates the various matrices if needed.

◆ get_angular_velocity()

real_t bitsim::dynamics::DiffDriveDynamics::get_angular_velocity ( ) const
inline

get_velocity Returns the angular velocity used for integration

◆ get_orientation()

real_t bitsim::dynamics::DiffDriveDynamics::get_orientation ( ) const
inline

Read the y-coordinate.

◆ get_velocity()

real_t bitsim::dynamics::DiffDriveDynamics::get_velocity ( ) const
inline

get_velocity Returns the velocity used for integration

◆ get_x_position()

real_t bitsim::dynamics::DiffDriveDynamics::get_x_position ( ) const
inline

Read the x-coordinate.

◆ get_y_position()

real_t bitsim::dynamics::DiffDriveDynamics::get_y_position ( ) const
inline

Read the y-coordinate.

◆ initialize_matrices()

void bitsim::dynamics::DiffDriveDynamics::initialize_matrices ( const input_type & input)

Initialize the matrices describing the the dynamics.

◆ integrate() [1/2]

void bitsim::dynamics::DiffDriveDynamics::integrate ( const input_type & input)

Integrate the new state. It also uses error terms.

◆ integrate() [2/2]

SysState< 3 > bitsim::dynamics::DiffDriveDynamics::integrate ( const SysState< 3 > & state,
const input_type & input,
const DynamicVersion version )
static

integrate Factory method to apply the different integration methods

◆ integrate_state_v1()

SysState< 3 > bitsim::dynamics::DiffDriveDynamics::integrate_state_v1 ( const SysState< 3 > & state,
real_t tol,
real_t dt,
real_t v,
real_t w,
const std::array< real_t, 2 > & errors )
static

integrate_state_v1

◆ integrate_state_v2()

SysState< 3 > bitsim::dynamics::DiffDriveDynamics::integrate_state_v2 ( const SysState< 3 > & state,
real_t dt,
real_t v,
real_t w,
const std::array< real_t, 2 > & errors )
static

integrate_state_v2

◆ integrate_state_v3()

SysState< 3 > bitsim::dynamics::DiffDriveDynamics::integrate_state_v3 ( const SysState< 3 > & state,
real_t r,
real_t l,
real_t dt,
real_t w1,
real_t w2,
const std::array< real_t, 2 > & errors )
static

integrate_state_v3

◆ set_orientation()

void bitsim::dynamics::DiffDriveDynamics::set_orientation ( real_t theta)
inline

Set the orientation.

◆ set_x_position()

void bitsim::dynamics::DiffDriveDynamics::set_x_position ( real_t x)
inline

Set the x-coordinate.

◆ set_y_position()

void bitsim::dynamics::DiffDriveDynamics::set_y_position ( real_t y)
inline

Set the y-coordinate.

◆ update_matrices()

void bitsim::dynamics::DiffDriveDynamics::update_matrices ( const input_type & input)

updates the matrices used to describe this motion model


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