Skip to content

UBCSailbot/PLRS-IMU

Repository files navigation

Polaris IMU

CI License C++23 RP2040

This repository contains the IMU firmware for Polaris.

Setup

This project's toolchain is based on PlatformIO, configured for the RP2040.

Nix

A dev shell is provided in flake.nix. If you use direnv, it will load automatically when you enter the directory. Otherwise:

nix develop

Linux

Install Nix using the Determinate installer:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
mkdir -p ~/.config/nix/
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf

Then install direnv through Nix (the apt package is too old to support use flake):

nix profile add nixpkgs#direnv
echo '# Direnv shell hook'
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
exec bash
direnv allow

macOS

Install Nix using the Determinate installer:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
mkdir -p ~/.config/nix/
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf

Then install direnv through Nix:

nix profile add nixpkgs#direnv
echo '# Direnv shell hook'
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
exec zsh
direnv allow

Windows

The recommended path is WSL2 with Ubuntu 24.04. Install WSL2 from PowerShell:

wsl --install -d Ubuntu-24.04

Once in WSL, follow the Linux instructions above.

For flashing, the RP2040 needs to be forwarded from Windows into WSL using usbipd-win:

usbipd list                  # find the RP2040 bus ID
usbipd bind --busid <id>
usbipd attach --wsl --busid <id>

Set up Git and GitHub

Skip this section if you've already configured git and your GitHub credentials.

Configure Git:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git config --global core.autocrlf false # Very important you don't miss this on WSL!

Configure the gh Helper (For Logging Into GitHub):

Linux:

sudo apt update && sudo apt install gh

macOS:

brew install gh

Then authenticate:

gh auth login

Build, test, and flash

make test    # host Unity tests
make build   # build firmware
make upload  # flash the RP2040
make format  # clang-format all sources in-place

Run make with no arguments to list all targets.

Python sim

A Python harness at sim/ runs the C++ EKF offline for visualization and tuning; the same filter that ships on the RP2040 runs in the sim, so tuning values transfer faithfully.

make tui drops into an arrow-key picker; choose a view, then a scenario.

Timeseries: truth, measurements, EKF estimate, and open-loop gyro integration per channel, residuals with a +/-1 sigma band below:

Sinusoidal scenario with EKF tracking truth inside its +/-1 sigma band

Mounting: the calibration geometry from tuning.toml:

Mounting view showing a tilted IMU triad and offset GNSS baseline

Simulate: animated 3D boat (truth, EKF estimate, raw IMU), rendered as a GIF. A static pose filmstrip is available via --view pose:

Final frame of the 3D boat animation showing truth, EKF estimate, and IMU raw hulls

make tui                                        # interactive picker
make tui SCENARIO=wave_tack VIEW=timeseries     # skip the picker
make sim-test                                   # pytest suite
make sim-format                                 # ruff format + check

Noise, EKF, and calibration flags are available on the direct CLI; see cd sim && uv run python -m plrs_sim sim --help.

Git hooks

Pre-push hooks are tracked in hooks/ and mirror the CI checks (clang-format

  • native tests). If you use direnv, they are installed automatically when you enter the directory. Without direnv, install them once manually:
ln -sf ../../hooks/pre-push .git/hooks/pre-push

Coding style

See CONTRIBUTING.md.

Overview

The goal is heading accuracy of ≤2° on Polaris by fusing IMU and GNSS measurements through a Kalman filter (likely an Extended Kalman Filter given time constraints).

Reference Projects

TinyEKF: Lightweight C/C++ Extended Kalman Filter.

Tuning

Filter tuning lives in tuning.toml, shared by the firmware and the sim. See docs/tuning.md for theory, datasheet-derived starting values, and the record-and-replay workflow.

Hardware

MCU: Raspberry Pi RP2040

MEMS IMU (accelerometer, gyroscope, magnetometer): Xsens MTi-3-5A-T

GNSS kit (dual antenna): Septentrio mosaic-go H

Firmware

FreeRTOS

Roadmap

Milestone Issues
Python Logger Serial capture script, log format, replay utility
Python EKF Sim pybind11 bindings, synthetic data generator, sim runner, plotter
HIL Testing On-device test suite, PIO Remote agent, CI integration

License

GNU General Public License v3.0

About

Polaris' IMU Sensor Fusion Project

Resources

License

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors