bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
Robots

bitsim has robots of two kinds:

  • a robot in Project Chrono, a rigid body model that drives on a floor, bumps into boxes and carries sensors and motors: CHRONO_DiffDriveRobot, a differential drive robot built from a robot file;
  • vehicle models, the equations of motion of a vehicle, which step without a physics engine: a differential drive, a bicycle model, a quadrotor and a fixed wing aircraft.

The Chrono robot is the one the simulation, estimation and hardware in the loop examples drive; the models are for planning, estimation and control, where the equations themselves are what matters.

The robots at a glance

Robot What it is Needs Examples
CHRONO_DiffDriveRobot a chassis, two driven wheels with DC motors and a ball caster, in Chrono, with its sensors ENABLE_CHRONO A differential drive robot in Chrono, Following a line with infrared sensors and avoiding obstacles, Sensor fusion with an extended Kalman filter, A differential drive robot with real motors
DiffDriveDynamics the motion of a differential drive in the plane, with its Jacobians for a Kalman filter nothing The kinematics of a differential drive, Extended Kalman filtering
BicycleVehicleModelDynamics the kinematic bicycle model of a car-like vehicle nothing
QuadrotorDynamics the 6-DOF rigid body dynamics of a quadrotor, driven by the speeds of its four rotors nothing The dynamics of a quadrotor, Flying a simulated quadrotor from the laptop
FixedWingDynamics the 6-DOF flight dynamics of a fixed wing aircraft with a propeller and a landing gear nothing A fixed wing UAV: trim, stability, autopilot, takeoff and landing

The differential drive robot in Chrono

CHRONO_DiffDriveRobot is a chassis, two driven wheels and a ball caster. Each driven wheel has a DCMotor, see Actuators, and the robot carries the sensors of Sensors. It is loaded from a robot file, added to a Chrono system, and then driven step by step:

chrono::ChSystemNSC system;
// ... gravity, the collision system, the floor
CHRONO_DiffDriveRobot robot;
robot.load(std::filesystem::path(bitsim::consts::ROBOTS_DIR + "/bitsim_diff_drive_robot.json"));
robot.set_world_pose(0.0, 0.0, 0.0); // the axle centre at (x, y), facing yaw [rad]
robot.add_to_sys(system);
const double dt = 0.002;
for (int i = 0; i < 2000; ++i)
{
robot.set_velocity(0.3, 0.2); // forward speed [m/s] and turning rate [rad/s], positive left
robot.update(dt); // run the motors and pass their output to the wheels
system.DoStepDynamics(dt);
}
const auto centre = robot.axle_center();
const auto heading = robot.heading();
A differential-drive robot in Chrono: a chassis, two driven wheels and a ball caster....
Definition diff_drive_robot.h:52
void load(const std::filesystem::path &filename)
Load the robot details form the specified filename.
Definition diff_drive_robot.cpp:239
const std::string ROBOTS_DIR
Path to robots definitions.
Definition bitsim_consts.h:42
  • set_velocity(v, omega) turns a forward speed and a turning rate into a target speed for each wheel's motor; set_speed(v) drives straight, and set_motor_speed(m, speed) sets one wheel's motor directly.
  • update(dt) runs the motors and passes their output to the wheels. Call it before every DoStepDynamics(dt). A simulated motor puts its torque on its wheel, and a real one turns its wheel to the angle it reports, see Actuators; either way the contact with the floor moves the robot.
  • get_pose(), axle_center() and heading() give where the robot is; get_chassis() and get_wheel(m) give its Chrono bodies.
  • get_sonar(), get_rear_sonar(), get_line_sensor(), get_imu() and get_camera() give its sensors, and set_floor() the floor that the line sensor looks at.
  • set_motor(m, motor) replaces a wheel's motor, for example with a real one.

The robot file

The robot file, robots/bitsim_diff_drive_robot.json, describes the robot. Its sections:

Section What
name the name of the robot
robot-data max_speed, the largest speed of a wheel on the ground [m/s], wheel_radius, wheel_width, axle_length, the distance between the wheels, and caster_wheel_radius, all in m, and the density of the parts [kg/m³]
material the friction and the restitution of the contacts
chassis the size of the chassis along x, y and z, chassis_x to chassis_z, and the position of its centre of mass
left-wheel, right-wheel, caster-wheel where each wheel is, relative to the chassis
motors the backend of the wheel motors, SIMULATION, and their parameters, see Actuators
sensors the sensors and their backends, see Sensors

The chassis, motors and sensors sections have a description that says what their values mean. A changed copy of the file makes a different robot. The examples load the one in robots/ with bitsim::consts::ROBOTS_DIR, or bitsim::consts::build_robot_file_path("bitsim_diff_drive_robot.json"); both are in data_dir(): the directory in the BITSIM_DATA_DIR environment variable if it is set, otherwise the source tree bitsim was built from if it is still there, and otherwise the files an installed bitsim put in share/bitsim.

The vehicle models

The vehicle models are the equations of motion of a vehicle, with no physics engine: each takes the state and the inputs and steps them forward.

The differential drive. DiffDriveDynamics moves the centre of the axle at \((x, y)\), facing \(\theta\). In its default version, V1, the input is the speed \(v\) and the turning rate \(\omega\), and over a step the robot drives an exact arc; with no errors that is exact for a constant \(v\) and \(\omega\). It also gives the Jacobians of the step with respect to the state and to the errors, which is what an extended Kalman filter needs, as in Extended Kalman filtering. Its other versions take a forward Euler step, V2 with \(v\) and \(\omega\) and V3 with the speeds of the two wheels.

The bicycle model. BicycleVehicleModelDynamics is the kinematic bicycle model of a car-like vehicle: its position and heading, a wheelbase \(L\) between the front and the rear wheels, and the speed and the steering angle as inputs.

The quadrotor. QuadrotorDynamics is the rigid body dynamics of a quadrotor in a plus layout, driven by the speeds of its four rotors: the thrust \(k_1 \omega_i^2\) of each rotor, the torques of their differences about the three axes, and the drag torque \(k_2 \omega_i^2\) of each rotor about its axis. QuadrotorFlightController flies it in angle mode, from the sticks of a radio transmitter, which Flying a simulated quadrotor from the laptop takes from the laptop's keyboard.

The fixed wing aircraft. FixedWingDynamics is the 6-DOF flight dynamics of a small fixed wing aircraft, after Beard and McLain's Small Unmanned Aircraft: air data with wind, lift that stalls, drag, the side force and the moments, a propeller driven by a DC motor, and a landing gear on the ground. A fixed wing UAV: trim, stability, autopilot, takeoff and landing trims it, designs an autopilot from its linearised dynamics, and flies it from takeoff to landing.