The firmware for the LeoCore controller running inside Leo Rover.
The main functionalities include:
- velocity commands for the robot,
- velocity and PWM commands for individual wheels,
- battery voltage feedback,
- wheel states (position, velocity, torque, PWM duty) feedback,
- odometry feedback (calculated from wheel encoders),
- feedback from the IMU sensor.
The project is written for CMake and uses Nix to provide a development shell which includes all the necessary tools to build, flash and debug the firmware. The low-level code is generated by the STM32CubeMX tool.
The firmware also uses rcl+rclc as a client library with Micro XRCE-DDS as a middleware to expose its functionalities on ROS topics, services and parameters. For the documentation of the ROS API, visit [Leo Rover Specification].
- Nix package manager (version 2.28 or later) with Flakes enabled
- (optional) direnv and nix-direnv for automatic loading of the development shell
- (optional) Visual Studio Code with the workspace recommended extensions for development and debugging
To enter the development shell, run:
nix develop -Lv
If you are using direnv and nix-direnv, you can just run:
direnv allow
From now on, the development shell will be automatically loaded when you enter the project directory.
If you are using Visual Studio Code, make sure you have nix-direnv configured, install workspace recommended extensions (type @recommended in the extensions view) and reload the window. The development environment will be automatically loaded when you open the project.
If using a terminal, run:
cmake --preset default
Note
This will configure the project and create a build directory. This can take a while the first time as the Micro-ROS libraries are downloaded and built as part of this step.
Then run:
cmake --build --preset Release
The firmware will be built and the output will be in the build/Release
directory.
If using Visual Studio Code, you can use the built-in CMake tools to build the project.
- Open the command palette (Ctrl+Shift+P) and type
CMake: Configure
. - Wait for the configuration to finish.
- Open the command palette again and type
CMake: Build
.
Alternatively, you can use workspace-defined task to build the project.
- Open the command palette (Ctrl+Shift+P) and type
Tasks: Run Task
. - Select
Release build
from the list of tasks.
Connect the ST-Link to the pins on the LeoCore debug pin header.
Then run the following command to flash the firmware:
openocd -f openocd.cfg -c "program build/Release/leocore_firmware.elf verify reset exit"
If you are using Visual Studio Code, you can use workspace-defined task to flash the firmware.
- Open the command palette (Ctrl+Shift+P) and type
Tasks: Run Task
. - Select
Release flash
from the list of tasks.
To start a debugging session in Visual Studio Code, run the Debug Firmware
launch configuration (from the Run and Debug view).
Upload the build/Release/leocore_firmware.bin
to Leo Rover, then, on the robot, run:
ros2 run leo_fw flash leocore_firmware.bin
To expose the Micro-ROS node to the ROS2 network, you need to run the Micro-ROS Agent on RPi. Build the package using colcon and then run:
ros2 run micro_ros_agent micro_ros_agent serial -D /dev/serial0 -b 460800
The appropriate version of the STM32CubeMX tool is provided in the cubemx
nix development shell. To enter the shell, run:
export NIXPKGS_ALLOW_UNFREE=1
nix develop --impure .#cubemx
Now you can run the STM32CubeMX tool:
stm32cubemx
Open the leocore.ioc
project, make the changes and click GENERATE CODE
.