Skip to content

LeoRover/leocore_firmware_ros2

Repository files navigation

leocore_firmware_ros2

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].

Prerequisites

  • 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

Preparing the development environment

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.

Building

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.

  1. Open the command palette (Ctrl+Shift+P) and type CMake: Configure.
  2. Wait for the configuration to finish.
  3. Open the command palette again and type CMake: Build.

Alternatively, you can use workspace-defined task to build the project.

  1. Open the command palette (Ctrl+Shift+P) and type Tasks: Run Task.
  2. Select Release build from the list of tasks.

Flashing

Using ST-Link programmer

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.

  1. Open the command palette (Ctrl+Shift+P) and type Tasks: Run Task.
  2. 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).

Using RPi on Leo Rover

Upload the build/Release/leocore_firmware.bin to Leo Rover, then, on the robot, run:

ros2 run leo_fw flash leocore_firmware.bin

Connecting

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

Modifying STM32CubeMX configuration

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.

About

Micro-ROS-based firmware for the LeoCore controller running inside Leo Rover.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •