Skip to content
pockermanPublic

About

Environments and various utilities for reinforcement learning with C++

Topics

Resources

Contributing

Stars

17 stars

Watchers

1 watching

Forks

Repository files navigation

Build bitsim

bitsim

bitsim is a C++20 library to model, simulate, estimate and control robots, from the maths of frames and kinematics to a simulated robot that drives with real motors and a real camera. The documentation is here. Reinforcement learning, its environments included, is in bitrl, which builds on bitsim.

A simulated robot following a line An extended Kalman filter fusing the robot's sensors
A differential drive robot in Chrono follows a line with its infrared elements and drives around boxes it hears with its ultrasonic sensor. Example An extended Kalman filter fuses the encoders, the IMU, the infrared elements, the camera and two sonars: odometry (magenta) drifts, the filter (cyan) stays on the true path (yellow). Example
Line following with a camera on a Raspberry Pi A simulated quadrotor flown with RC sticks
Hardware in the loop: the simulated robot follows the line with the frames of a real camera on a Raspberry Pi, streamed over HTTP. Example A quadrotor flown from the laptop's keyboard with RC stick commands, through an angle mode flight controller. Example
An arm following a straight line with inverse kinematics A rapidly exploring random tree planning a path
A three joint arm in Chrono moves its tip along a straight line, with the joint angles from inverse kinematics at every step; the grey arms are the other solutions for the same point. Example A rapidly exploring random tree plans across a warehouse; its path is shortened and compared with A* on an occupancy grid. Example
Theta* planning a path at any angle on an occupancy grid EKF-SLAM mapping posts while dead reckoning drifts
Grid planners side by side on one warehouse: breadth-first search, Dijkstra, A* and, here, Theta*, whose path leaves the grid and cuts across at any angle. Example EKF-SLAM maps the posts of a warehouse from range and bearing sightings while working out where the robot is: dead reckoning (red) drifts through the wall, SLAM (blue) stays on the true path (green). Example
A fixed wing aircraft taking off and landing under its autopilot
A fixed wing aircraft with a 6-DOF aerodynamic model takes off, flies a circuit of waypoints under an autopilot designed from its linearised dynamics, and lands on the glide slope with a flare and braking; the takeoff and the landing are shown at twice real speed. Example

What is in it

Area What bitsim has
Frames and kinematics rotations, frames, Denavit–Hartenberg forward and inverse kinematics of planar and spatial arms, differential drive kinematics
Dynamics differential drive, bicycle and quadrotor models with their Jacobians, a 6-DOF fixed wing aircraft with its landing gear, its trim and its flight modes, a double pendulum
Trajectories and planning time scaling, waypoint trajectories; on occupancy grids breadth-first search, Dijkstra, A* and any-angle Theta*; RRT; a world of box obstacles that both kinds of planner share
Mapping occupancy grids built from range scans, each cell the probability that it is occupied; landmark maps built with EKF-SLAM, with landmark ids or by data association on the Mahalanobis distance
Sensors ultrasonic, infrared reflectance, IMU, a downward camera, MJPEG camera streams and wheel encoders, each simulated or real over MQTT
Actuators and boards DC and BLDC motors, Arduino boards over USB, WiFi and MQTT, RC links
Simulation robots and rigid bodies in Project Chrono, drawn with Irrlicht
Parallel and distributed a thread pool and parallel loops; robots simulated by participants in several processes, in lockstep or keeping pace with real robots; co-simulation of coupled subsystems, loose or strong, in one process or several
Estimation odometry, gyro heading, Kalman and extended Kalman filters, a filter that fuses every sensor of the robot, EKF-SLAM
Control PID and PI controllers, a line follower, a quadrotor flight controller, a fixed wing autopilot that takes off, flies waypoints and lands

A real sensor or motor and its simulated twin have the same interface, so the code that drives a simulated robot drives a real one too.

Examples

The examples go through the library in order, from its basic types to robots on real hardware: frames and rotations, kinematics, trajectories, mapping and motion planning, sensors and actuators, simulation, state estimation, hardware in the loop, control, parallel computing, distributed simulation and co-simulation. They are listed in examples/examples.md, and each has a page that explains it.

Build

Ubuntu 24.04 is the reference platform. ci/install_deps.sh installs the dependencies and ci/build_chrono.sh <prefix> builds the supported Project Chrono commit. The full instructions are in doc/install.md.

cmake -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON
cmake --build build --parallel 4
ctest --test-dir build --output-on-failure

--parallel with no number runs as many compilers as it likes. Each file that includes Chrono or Irrlicht takes 1 to 1.5 GB to compile, so on a machine with 16 GB give it a number, 4 or fewer.

Option Default Description
ENABLE_CHRONO ON Project Chrono simulation. Add -DCMAKE_PREFIX_PATH=<prefix> for a non-system install
ENABLE_MQTT ON Paho MQTT support
ENABLE_OPENCV ON OpenCV support
ENABLE_EXAMPLES ON Build the examples
ENABLE_TESTS OFF Build the tests
BITSIM_IRRLICHT ON Irrlicht visualization. Requires ENABLE_CHRONO
BITSIM_LOG ON Compile in the library's log messages. Their level is set at run time, see logging
BITSIM_WERROR OFF Treat warnings as errors in Debug builds
BITSIM_SANITIZE OFF Build with AddressSanitizer and UndefinedBehaviorSanitizer

With ENABLE_TESTS=ON, ctest -L examples runs every example that needs no hardware, server or window.

Contributing

Commits follow Conventional Commits and releases are made from them automatically. See CONTRIBUTING.md.

About

Environments and various utilities for reinforcement learning with C++

Topics

Resources

Contributing

Stars

17 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages