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

A simulated ultrasonic sensor: it casts rays into the Chrono world. More...

#include <chrono_ultrasound_backend.h>

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

Public Member Functions

 CHRONO_UltrasonicBackend ()
 Constructor. Attach a body with set_chrono_body() before reading; the system is the one the body is in.
 CHRONO_UltrasonicBackend (chrono::ChSystem &sys, std::shared_ptr< chrono::ChBody > body)
 Constructor.
std::vector< real_t > read_values () override
 Read the distance to the nearest obstacle.
void load (const nlohmann::json &j) override
 Read the settings, see RangeSensorBackendBase::load(). Also yaw, where the sensor points about the body's z axis [deg], 0 ahead; and reads, all optional:
void set_position (const chrono::ChVector3d &pos)
 Set the position of the sensor on its body.
const chrono::ChVector3d & position () const
void set_beam (real_t beam_angle, uint_t n_rays)
 Set the cone the sensor hears echoes from.
real_t beam_angle () const noexcept
uint_t n_rays () const noexcept
void set_yaw (real_t yaw) noexcept
 Point the sensor yaw [rad] about the body's z axis from its x axis; 0, the default, looks ahead and pi behind.
real_t yaw () const noexcept
Public Member Functions inherited from bitsim::sensors::backends::RangeSensorBackendBase
real_t max_distance () const noexcept
void set_max_distance (real_t max_distance) noexcept
 Set the maximum distance the range sensor can read.
real_t min_distance () const noexcept
void set_min_distance (real_t min_distance) noexcept
 Set the minimum distance the range sensor can read.
virtual std::string sensor_units () const
void set_sensor_units (const std::string &units)
 Set the sensor units.
void load_from_json (const std::string &filename) override
 Read the settings from a JSON file, see load().
virtual void add_visual_shape (const std::unordered_map< std::string, std::any > &shape_properties) override
 Add a visual shape for the sensor in order to be visualized with Irrlicht. Concrete classes may choose not to implement this. In this case the sensor will not be visible.
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.
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 Attributes

static const std::string BACKEND_TYPE = "SIMULATION"
 The type of the backend.

Additional Inherited Members

Static Public Member Functions inherited from bitsim::sensors::backends::RangeSensorBackendBase
static std::shared_ptr< RangeSensorBackendBase > create (const std::string &backend_type)
 Create a backend by the name a robot file gives it.
Protected Member Functions inherited from bitsim::sensors::backends::RangeSensorBackendBase
 RangeSensorBackendBase (const std::string &backend_type)
 Constructor.
real_t clamp_distance (real_t distance) const noexcept
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.
Protected Attributes inherited from bitsim::sensors::backends::SensorBackendBase
std::shared_ptr< chrono::ChBody > body_ {nullptr}
 The body on which the sensor sits.

Detailed Description

A simulated ultrasonic sensor: it casts rays into the Chrono world.

The sensor sits at position() on the body it is attached to and looks along the body's x axis. A real ultrasonic sensor hears echoes from a cone, about 15 degrees wide for an HC-SR04, so the backend casts n_rays() rays fanned across beam_angle() in the body's x-y plane and reports the nearest hit. With one ray, the default, it looks straight ahead only.

Only bodies with collision enabled reflect the rays. The body the sensor is attached to never does.

Constructor & Destructor Documentation

◆ CHRONO_UltrasonicBackend() [1/2]

bitsim::sensors::backends::CHRONO_UltrasonicBackend::CHRONO_UltrasonicBackend ( )

Constructor. Attach a body with set_chrono_body() before reading; the system is the one the body is in.

◆ CHRONO_UltrasonicBackend() [2/2]

bitsim::sensors::backends::CHRONO_UltrasonicBackend::CHRONO_UltrasonicBackend ( chrono::ChSystem & sys,
std::shared_ptr< chrono::ChBody > body )

Constructor.

Parameters
sysThe system the rays are cast in
bodyThe body the sensor is attached to

Member Function Documentation

◆ beam_angle()

real_t bitsim::sensors::backends::CHRONO_UltrasonicBackend::beam_angle ( ) const
inlinenoexcept
Returns
The full width of the cone [rad]

◆ load()

void bitsim::sensors::backends::CHRONO_UltrasonicBackend::load ( const nlohmann::json & j)
overridevirtual

Read the settings, see RangeSensorBackendBase::load(). Also yaw, where the sensor points about the body's z axis [deg], 0 ahead; and reads, all optional:

  • mounted_position or frame_pos: [x, y, z] on the body [m]
  • beam_angle: the width of the cone [deg]
  • n_rays: how many rays to cast across it

Reimplemented from bitsim::sensors::backends::RangeSensorBackendBase.

◆ n_rays()

uint_t bitsim::sensors::backends::CHRONO_UltrasonicBackend::n_rays ( ) const
inlinenoexcept
Returns
How many rays are cast across the cone

◆ position()

const chrono::ChVector3d & bitsim::sensors::backends::CHRONO_UltrasonicBackend::position ( ) const
inline
Returns
A read reference of the position of the sensor on its body

◆ read_values()

std::vector< real_t > bitsim::sensors::backends::CHRONO_UltrasonicBackend::read_values ( )
overridevirtual

Read the distance to the nearest obstacle.

Returns
One value, clamped to [min_distance(), max_distance()]
Exceptions
std::logic_errorIf no body is attached, or the body is in no system

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

◆ set_beam()

void bitsim::sensors::backends::CHRONO_UltrasonicBackend::set_beam ( real_t beam_angle,
uint_t n_rays )

Set the cone the sensor hears echoes from.

Parameters
beam_angleThe full width of the cone [rad]
n_raysHow many rays to cast across it, at least 1

◆ set_position()

void bitsim::sensors::backends::CHRONO_UltrasonicBackend::set_position ( const chrono::ChVector3d & pos)
inline

Set the position of the sensor on its body.

Parameters
pos

◆ set_yaw()

void bitsim::sensors::backends::CHRONO_UltrasonicBackend::set_yaw ( real_t yaw)
inlinenoexcept

Point the sensor yaw [rad] about the body's z axis from its x axis; 0, the default, looks ahead and pi behind.

◆ yaw()

real_t bitsim::sensors::backends::CHRONO_UltrasonicBackend::yaw ( ) const
inlinenoexcept
Returns
Where the sensor points, about the body's z axis from its x axis [rad]

Member Data Documentation

◆ BACKEND_TYPE

const std::string bitsim::sensors::backends::CHRONO_UltrasonicBackend::BACKEND_TYPE = "SIMULATION"
static

The type of the backend.


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