|
bitsim
Model, simulate, estimate and control robots in C++
|
Ubuntu 24.04 is the reference platform. The CI builds bitsim there with the same scripts this page uses, so they are known to work.
| Dependency | Needed for | Installed by |
|---|---|---|
| CMake 3.20 or newer, a C++20 compiler | everything | ci/install_deps.sh |
| Boost 1.74 or newer, Eigen3 | everything | ci/install_deps.sh |
| spdlog 1.9 or newer | logging, see Logging | ci/install_deps.sh |
| OpenCV | ENABLE_OPENCV | ci/install_deps.sh |
| Paho MQTT C and C++ | ENABLE_MQTT | ci/install_deps.sh, built from source |
| GoogleTest | ENABLE_TESTS | ci/install_deps.sh |
| Project Chrono with its Irrlicht module | ENABLE_CHRONO, BITSIM_IRRLICHT | ci/build_chrono.sh |
bitsim also uses nlohmann/json and HTTPRequest, which are included in src/bitsim/extern.
Install everything except Chrono with
bitsim needs a specific commit of Chrono's main branch; the 9.0.1 release lacks the CMake targets and API that bitsim uses. To build that commit, first install the packages Chrono needs and then build it under a prefix of your choice:
--with-chrono-deps also patches /usr/include/irrlicht/irrXML.h, which does not compile as C++20.
Skip this section and configure with -DENABLE_CHRONO=OFF if you do not need the simulations.
--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, see bitsim 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. Run the tests with LSAN_OPTIONS=suppressions=ci/lsan.supp |
bitsim logs with spdlog, through bitsim/utils/logger.h, to standard error. A message is written with the stream operator, so anything that has an operator<< can be logged:
The messages go to named loggers: bitsim logs to bitsim, bitrl to bitrl, and BITSIM_LOG_TO("mylib", bitsim::log::Level::info) to a logger of your own. Every logger writes info and above unless told otherwise, at run time with
or, without changing the code, with the SPDLOG_LEVEL environment variable: SPDLOG_LEVEL=warn for every logger, SPDLOG_LEVEL=warn,bitrl=debug for warnings except from bitrl. A message below the level of its logger is not formatted, so it costs almost nothing. spdlog is only used inside the library, so projects that use bitsim do not need its headers.
If CMake finds a fmt other than the one spdlog was built with, the build fails in spdlog's headers. Anaconda on the PATH is a common cause: pass -Dfmt_DIR=/usr/lib/x86_64-linux-gnu/cmake/fmt.
bitsim/utils/concurrency/parallel.h runs independent work on several threads: parallel_for(begin, end, f) calls f(i) for every index, and parallel_map(n, f) returns f(0), ..., f(n - 1) in index order, so the results do not depend on the number of threads. Both use a pool of threads, default_thread_pool(), that starts as many threads as the machine has cores, or BITSIM_NUM_THREADS if that environment variable is set:
Each task should write only to what is its own, and draw its random numbers from its own generator; task_seed(seed, i) gives every task an unrelated seed. ThreadPool and ConcurrentQueue, in the same directory, are the building blocks, for code that needs its own threads.
Without -DCMAKE_INSTALL_PREFIX bitsim installs into its source tree, install/opt for a Release build and install/dbg for a Debug build. Under the prefix you get
| Path | What |
|---|---|
| lib/libbitsimlib.so | the library |
| include/bitsim/ | the headers, with the generated bitsim_config.h and bitsim_version.h |
| share/bitsim/ | the robot, sensor and world definitions: robots/, sensors/, worlds/ |
| lib/cmake/bitsim/ | the CMake package |
Configure the project with -DCMAKE_PREFIX_PATH=$HOME/opt/bitsim, and add the Chrono prefix to it if bitsim was built with Chrono, for example -DCMAKE_PREFIX_PATH="$HOME/opt/bitsim;$HOME/opt/chrono". bitsim::bitsim brings the include directories, the compile definitions and the libraries bitsim needs. The package also sets bitsim_WITH_CHRONO, bitsim_WITH_IRRLICHT, bitsim_WITH_MQTT and bitsim_WITH_OPENCV to say what bitsim was built with, and bitsim_DATA_DIR to the installed definitions.
bitsim::consts::ROBOTS_DIR, SENSORS_DIR and WORLDS_DIR point into the directory returned by bitsim::consts::data_dir(). It is