Skip to content

Repository files navigation

DriveBrain Software

This repo contains the main executable that runs on the Drivebrain embedded computer on HyTech Racing's cars. This code is deployed as a systemd service onto the car within HyTech's Raspberry Pi NixOS description. This service handles, among other things:

  • high-performance control algorithm execution from both hand written c++ and MATLAB Simulink generated code c++
  • car state estimation via both hand written c++ and MATLAB Simulink generated code c++
  • Vectornav INS communication via Vectornav's driver
  • live telemetry and data recording of all on-car inter-board communications (CAN and Ethernet mostly)
  • car-level parameter servicing of all previously listed components via the integrated Foxglove websocket server

This is an active rewrite of an older iteration of Drivebrain, which you can find here.

Linux/MacOS Development

This guide explains how to build the DriveBrain using the provided Docker cross-compilation environment.

Prerequisites

  • Docker installed on your system
  • Local clone of the DriveBrain repository

Building the Software

0. Build the dockerfile (you only need to do this once)

Run the following command to build the dockerfile:

docker build -t kkittur/drivebrain_cross_compile .

It may take a few minutes.

1. Enter the Docker Container

Run the following command to start and enter the Docker container with the necessary volumes mounted:

docker compose run dev

Alternatively, if you want to enter a modified container for whatever reason, you can run:

# running with modified memory and cpu limits
docker run -it \
  --mount type=volume,source=drivebrain_conan-cache,target=/root/.conan2 \
  --mount type=bind,source="$(pwd)",target=/app \
  --memory=16g \
  --cpus=4 \ 
  -w /app \
  kkittur/drivebrain_cross_compile /bin/bash 

and pass in whatever flags you see fit.

2. Run the Build Script

Inside the container, execute:

./build_script.sh

This script will build the DriveBrain software using the cross-compilation toolchain for the target platform. The first time you run it, it will take some time because it needs to compile all the dependencies. However, future builds past the first one take <1 minute because dependencies are cached.

Unit Tests

Unit tests have to be compiled to your native architecture if you actually want to see them run. To do this, you can pass in the --test flag in the build script.

./build_script.sh --test

and the project along with its unit tests will be compiled and ran.

Notes

  • Make sure the build script has execute permissions: chmod +x build_script.sh.
  • The build artifacts will be generated inside an autogenerated folder that's handled by Docker. You can access these artifacts for debugging by using docker volume inspect.

Windows Development

Overview

Docker Desktop on Windows already runs inside a lightweight Linux VM (WSL2), so the container itself is fast. The one thing that is slow is file access across the Windows/Linux boundary. If the repo lives on a Windows path like C:\Users\you\..., every file the build touches is read and written over that boundary, and dependency-heavy steps (Conan, CMake, the Python venv) drop from sub-second to minutes.

The Conan cache is already a Docker named volume, so it stays fast regardless. The fix for everything else is to keep the source on the Linux side of the boundary too. Clone the repo into the WSL2 filesystem, not into C:.

Prerequisites

  • Docker Desktop installed, with the WSL2 backend
  • A real Ubuntu WSL distro (Docker's own docker-desktop distro does not count)

0. Install WSL2 and Ubuntu (one time)

In PowerShell:

wsl --install -d Ubuntu

Reboot if prompted. On first launch it asks you to create a Linux username and password. Then make Ubuntu the default so a plain wsl never drops you into Docker's distro as root:

wsl --set-default Ubuntu

Confirm it worked:

wsl -l -v

Ubuntu should be listed as VERSION 2.

1. Enable Docker's WSL integration (one time)

Docker Desktop → Settings → Resources → WSL Integration. Turn on integration with your default distro, and toggle Ubuntu on. Apply & Restart.

2. Clone the repo inside WSL (one time)

Enter wsl with the command wsl -d Ubuntu in powershell. Then run:

cd ~
git clone <drivebrain-remote-url> drivebrain
cd drivebrain

3. Build and run

The rest is identical to the Linux/macOS instructions above, run from inside the Ubuntu shell at ~/drivebrain:

docker build -t kkittur/drivebrain_cross_compile .   # once
docker compose run dev
./build_script.sh

About

Software for HyTech's driverless, vehicle control, and DAQ module.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages