Using libcanard for DroneCAN

Libcanard is a minimal implementation of the DroneCAN protocol stack in C for resource-constrained applications.

Setting up libcanard

Generate DSDL Code:

DroneCAN requires us to build the header and source files for managing, encoding, and decoding messages. To do this, we will be following the instructions in https://github.com/dronecan/dronecan_dsdlc

  1. Install pip by installing python

  2. Install the necessary dependencies pip install empy==3.3.4 and pip install expect

  3. Clone https://github.com/dronecan/dronecan_dsdlc , https://github.com/dronecan/pydronecan , https://github.com/dronecan/DSDL , and https://github.com/dronecan/libcanard next to each other

  4. Run python dronecan_dsdlc/dronecan_dsdlc.py -O <output directory> <list of namespace dirs>. In our case, to build everything, run python dronecan_dsdlc/dronecan_dsdlc.py -O dsdlc_generated DSDL/uavcan DSDL/ardupilot DSDL/com DSDL/cuav/equipment/power DSDL/dronecan DSDL/mppt DSDL/tests

  5. The DSDL headers and source files are now generated. Copy these files into your repository and include <dronecan_msgs.h> which will be generated to include all of the other header files

Including the library and relevant drivers:

To use the libcanard library you only need to add the canard.c, canard.h, and canard_internals.h files from https://github.com/dronecan/libcanard into your repository. However, it is beneficial to also use a driver. The drivers provided in their repository are a good example, but the STM32 library they provide unfortunately uses specific register addresses instead of the HAL library which makes it possibly not compatible with all STM32 boards. We rewrote their STM32 driver with HAL which can be found in https://github.com/UWARG/efs-kitchen-sinks/tree/Canard_Base/CAN-ESC . The canard_stm32_driver.c and canard_stm32_driver.h files are the only ones you would need to copy to your repository, with the rest of the code acting as an example for how to use the driver.

Using libcanard

WIP