bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::sensors::backends::IMUBackendBase Class Reference

Base class for inertial measurement units with a three axis accelerometer and a three axis gyroscope, such as an MPU-6050. More...

#include <imu_backend_base.h>

Inheritance diagram for bitsim::sensors::backends::IMUBackendBase:
Collaboration diagram for bitsim::sensors::backends::IMUBackendBase:

Public Types

using Position = std::array<real_t, 3>

Public Member Functions

const Position & position () const noexcept
void set_position (const Position &position) noexcept
std::string sensor_units () const override
virtual void load (const nlohmann::json &j)
 Read the settings of the IMU from its section of a robot or sensor file, all optional:
void load_from_json (const std::string &filename) override
 Read the settings from a JSON file, see load().
void add_visual_shape (const std::unordered_map< std::string, std::any > &shape_properties) override
 Draw the IMU as a small box on the body. The properties are x_length, y_length, z_length (float_t) and chrono::ChColor.
Public Member Functions inherited from bitsim::sensors::backends::SensorBackendBase
virtual ~SensorBackendBase ()=default
 Destructor.
real_t sampling_period () const noexcept
 Returns the sampling period of the sensor.
void set_sampling_period (real_t period)
 Set the sampling period of the backend.
virtual std::vector< real_t > read_values ()=0
 Read the sensor value.
uint_t n_read_values () const noexcept
std::string backend_type_str () const noexcept
 Return a string that specifies the type of the backend.
void set_chrono_body (std::shared_ptr< chrono::ChBody > body)
 Set the pointer to the body that this sensor is attached.

Static Public Member Functions

static std::shared_ptr< IMUBackendBase > create (const std::string &backend_type)
 Create a backend by the name a robot file gives it.

Protected Member Functions

 IMUBackendBase (const std::string &backend_type)
Protected Member Functions inherited from bitsim::sensors::backends::SensorBackendBase
 SensorBackendBase (const std::string &backend_type)
 Constructor.
void set_n_read_values (uint_t n) noexcept
 Set how many values the implementation returns.

Additional Inherited Members

Protected Attributes inherited from bitsim::sensors::backends::SensorBackendBase
std::shared_ptr< chrono::ChBody > body_ {nullptr}
 The body on which the sensor sits.

Detailed Description

Base class for inertial measurement units with a three axis accelerometer and a three axis gyroscope, such as an MPU-6050.

A backend reads six values, along the axes of the body the IMU is on:

  • 0, 1, 2: the specific force [m/s^2], what the accelerometer measures. It is the acceleration minus gravity, so an IMU at rest reads 9.81 up
  • 3, 4, 5: the angular velocity [rad/s], what the gyroscope measures

Member Typedef Documentation

◆ Position

Constructor & Destructor Documentation

◆ IMUBackendBase()

bitsim::sensors::backends::IMUBackendBase::IMUBackendBase ( const std::string & backend_type)
inlineexplicitprotected

Member Function Documentation

◆ add_visual_shape()

void bitsim::sensors::backends::IMUBackendBase::add_visual_shape ( const std::unordered_map< std::string, std::any > & shape_properties)
overridevirtual

Draw the IMU as a small box on the body. The properties are x_length, y_length, z_length (float_t) and chrono::ChColor.

Implements bitsim::sensors::backends::SensorBackendBase.

◆ create()

std::shared_ptr< IMUBackendBase > bitsim::sensors::backends::IMUBackendBase::create ( const std::string & backend_type)
static

Create a backend by the name a robot file gives it.

Parameters
backend_typeSIMULATION (or CHRONO) for an IMU simulated with Chrono, MQTT for a real one on a board
Exceptions
std::runtime_errorIf the type is unknown, or bitsim was built without what the backend needs

◆ load()

void bitsim::sensors::backends::IMUBackendBase::load ( const nlohmann::json & j)
virtual

Read the settings of the IMU from its section of a robot or sensor file, all optional:

  • frame_pos: [x, y, z], where it is on the body [m]
  • update_rate, readings per second [1/s]

Backends read their own keys as well

Reimplemented in bitsim::sensors::backends::CHRONO_IMUBackend, and bitsim::sensors::backends::MQTT_IMUBackend.

◆ load_from_json()

void bitsim::sensors::backends::IMUBackendBase::load_from_json ( const std::string & filename)
overridevirtual

Read the settings from a JSON file, see load().

Implements bitsim::sensors::backends::SensorBackendBase.

◆ position()

const Position & bitsim::sensors::backends::IMUBackendBase::position ( ) const
inlinenoexcept
Returns
Where the IMU is on the body [m]. Its axes are the body's

◆ sensor_units()

std::string bitsim::sensors::backends::IMUBackendBase::sensor_units ( ) const
inlineoverridevirtual
Returns
M/S^2 and RAD/S: the units of the accelerometer and the gyroscope

Reimplemented from bitsim::sensors::backends::SensorBackendBase.

◆ set_position()

void bitsim::sensors::backends::IMUBackendBase::set_position ( const Position & position)
inlinenoexcept

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