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

A differential-drive robot in Chrono: a chassis, two driven wheels and a ball caster. Each driven wheel has an actuators::DCMotor. More...

#include <diff_drive_robot.h>

Classes

struct  RobotData
class  RobotSensorManager

Public Types

enum  Wheel : uint_t { LEFT = 0 , RIGHT = 1 }
 The wheels, in the order of the motors. More...
using json = nlohmann::json

Public Member Functions

 CHRONO_DiffDriveRobot ()=default
 Constructor.
void load (const std::filesystem::path &filename)
 Load the robot details form the specified filename.
void load (const json &j)
 Load the robot details form the specified json structure.
uint_t n_wheel_motors () const noexcept
void set_motor (uint_t m, std::shared_ptr< actuators::DCMotor > motor)
 Replace the motor of a wheel. The wheel is reconnected to the chassis to match the backend of the motor.
std::shared_ptr< actuators::DCMotor > get_motor (uint_t m) const
void set_motor_speed (uint_t m, real_t speed)
 Set the target speed of the m-th wheel [rad/s] m=0 => left motor m=1 => right motor.
void set_motor_speed (real_t speed)
 Set both wheels to the same target speed [rad/s].
void set_speed (real_t speed)
 Drive straight at the given speed [m/s].
void set_velocity (real_t v, real_t omega)
 Drive with a forward speed v [m/s] and a turning rate omega [rad/s], positive to the left.
void update (real_t dt)
 Advance the motors by dt and pass their output to the wheels. Call it before every DoStepDynamics(dt).
real_t wheel_angle (uint_t m) const
real_t wheel_torque (uint_t m) const
const CHRONO_RobotPose & get_pose () const
std::shared_ptr< chrono::ChBody > get_chassis () const
std::shared_ptr< chrono::ChBody > get_wheel (uint_t m) const
chrono::ChVector3d axle_center () const
real_t heading () const
void set_world_pose (real_t x, real_t y, real_t yaw)
 Move the whole robot so that its axle centre is at (x, y) and it faces yaw. Its height does not change. Use it before the simulation starts: it moves the bodies without changing their velocities.
std::shared_ptr< sensors::UltrasonicSensor > get_sonar () const noexcept
std::shared_ptr< sensors::UltrasonicSensor > get_rear_sonar () const noexcept
std::shared_ptr< sensors::InfraredSensor > get_line_sensor () const noexcept
std::shared_ptr< sensors::IMUSensor > get_imu () const noexcept
void set_floor (sensors::backends::CHRONO_InfraredBackend::Floor floor)
 Set the floor that a simulated line-sensor looks at.
std::shared_ptr< sensors::DownwardCamera > get_camera () const noexcept
cv::Mat camera_view (const sensors::FloorImage &floor) const
 What the robot's camera sees of the given floor where the robot is now.
const RobotData & get_data () const noexcept
void add_to_sys (chrono::ChSystemNSC &sys) const
RobotSensorManager & get_sensor_manager ()
void set_world_position (const chrono::ChVector3d &position)
 Explicitly set the world position of the chassis. It moves the chassis only, not the wheels; use set_world_pose to move the robot.
void set_world_position (const std::array< real_t, 3 > &position)
 Explicitly set the world position of the chassis. It moves the chassis only, not the wheels; use set_world_pose to move the robot.

Detailed Description

A differential-drive robot in Chrono: a chassis, two driven wheels and a ball caster. Each driven wheel has an actuators::DCMotor.

How a motor turns its wheel depends on its backend. A simulated motor produces a torque, and Chrono moves the wheel. A real motor on a board has already turned, so Chrono turns the wheel to the angle it reports, and the contact with the ground moves the robot. Either way, call update(dt) before every DoStepDynamics(dt).

The motors come from the "motors" section of the robot file. Without one, or to use real motors, attach them with set_motor() before or after add_to_sys().

Member Typedef Documentation

◆ json

Member Enumeration Documentation

◆ Wheel

The wheels, in the order of the motors.

Enumerator
LEFT 
RIGHT 

Constructor & Destructor Documentation

◆ CHRONO_DiffDriveRobot()

Member Function Documentation

◆ add_to_sys()

void bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::add_to_sys ( chrono::ChSystemNSC & sys) const

Add the components of this robot to the given chrono::ChSystemNSC

Parameters
sys

◆ axle_center()

Returns
The point halfway between the wheels, in world coordinates. The robot turns on the spot around it

◆ camera_view()

cv::Mat bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::camera_view ( const sensors::FloorImage & floor) const

What the robot's camera sees of the given floor where the robot is now.

◆ get_camera()

std::shared_ptr< sensors::DownwardCamera > bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_camera ( ) const
inlinenoexcept
Returns
The camera that looks down at the floor ahead, read from the front-camera sensor of the robot file. Null if the robot has none

◆ get_chassis()

std::shared_ptr< chrono::ChBody > bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_chassis ( ) const
inline
Returns
The chassis of the robot

◆ get_data()

Returns
The data read from the robot file

◆ get_imu()

std::shared_ptr< sensors::IMUSensor > bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_imu ( ) const
inlinenoexcept
Returns
The accelerometer and gyroscope on the chassis, the imu of the robot file. Null if the robot has none

◆ get_line_sensor()

std::shared_ptr< sensors::InfraredSensor > bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_line_sensor ( ) const
inlinenoexcept
Returns
The infrared elements that look at the floor, the line-sensor of the robot file. Null if the robot has none

◆ get_motor()

std::shared_ptr< actuators::DCMotor > bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_motor ( uint_t m) const
Returns
The motor of a wheel. m = 0 is the left and m = 1 the right

◆ get_pose()

const CHRONO_RobotPose & bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_pose ( ) const
inline

Get the pose of the robot

◆ get_rear_sonar()

std::shared_ptr< sensors::UltrasonicSensor > bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_rear_sonar ( ) const
inlinenoexcept
Returns
The ultrasonic sensor that looks behind, the rear-sonar of the robot file. Null if the robot has none

◆ get_sensor_manager()

Read/write reference to the senosr manager for this robot

Returns

◆ get_sonar()

std::shared_ptr< sensors::UltrasonicSensor > bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_sonar ( ) const
inlinenoexcept
Returns
The ultrasonic sensor that looks ahead, the front-sonar of the robot file. Null if the robot has none

◆ get_wheel()

std::shared_ptr< chrono::ChBody > bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::get_wheel ( uint_t m) const
Returns
A wheel of the robot. m = 0 is the left and m = 1 the right

◆ heading()

Returns
The direction the robot faces, as the angle from the world x axis about the z axis [rad]

◆ load() [1/2]

Load the robot details form the specified json structure.

◆ load() [2/2]

void bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::load ( const std::filesystem::path & filename)

Load the robot details form the specified filename.

◆ n_wheel_motors()

Returns
The number of wheel motors this robot has

◆ set_floor()

Set the floor that a simulated line-sensor looks at.

Exceptions
std::logic_errorIf the robot has no line-sensor, or its backend is not SIMULATION

◆ set_motor()

void bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::set_motor ( uint_t m,
std::shared_ptr< actuators::DCMotor > motor )

Replace the motor of a wheel. The wheel is reconnected to the chassis to match the backend of the motor.

◆ set_motor_speed() [1/2]

Set both wheels to the same target speed [rad/s].

◆ set_motor_speed() [2/2]

Set the target speed of the m-th wheel [rad/s] m=0 => left motor m=1 => right motor.

◆ set_speed()

Drive straight at the given speed [m/s].

◆ set_velocity()

Drive with a forward speed v [m/s] and a turning rate omega [rad/s], positive to the left.

◆ set_world_pose()

Move the whole robot so that its axle centre is at (x, y) and it faces yaw. Its height does not change. Use it before the simulation starts: it moves the bodies without changing their velocities.

Parameters
xThe x coordinate of the axle centre [m]
yThe y coordinate of the axle centre [m]
yawThe heading, see heading() [rad]

◆ set_world_position() [1/2]

void bitsim::rb::bitsim_chrono::CHRONO_DiffDriveRobot::set_world_position ( const chrono::ChVector3d & position)

Explicitly set the world position of the chassis. It moves the chassis only, not the wheels; use set_world_pose to move the robot.

Parameters
position

◆ set_world_position() [2/2]

Explicitly set the world position of the chassis. It moves the chassis only, not the wheels; use set_world_pose to move the robot.

Parameters
position

◆ update()

Advance the motors by dt and pass their output to the wheels. Call it before every DoStepDynamics(dt).

◆ wheel_angle()

Returns
The angle of a wheel relative to the chassis, as Chrono has it [rad]

◆ wheel_torque()

Returns
The torque on a wheel, as Chrono has it [N m]

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