Serial over DroneCAN support


We now support adding extra serial ports to your flight controller using a DroneCAN adapter. You can add up to 3 new serial ports per CAN bus.
On the hardware side you can use any AP_Periph device that supports a serial port. It must be running the latest development AP_Periph firmware. A good example is the MatekL431 adapter board shown in the above photo which has a convenient 6 pin JST-GH 1.25 mm connector for serial connections.
In the above example I have connected a mRo SiK 915 MHz radio to the MatekL431 adapter, which in turn is connected to CAN1 on a CubeOrange.
To configure, you use CAN_D1_UC_SER_EN to 1 and you will then get the following parameters on a parameter refresh:

You can see I have configured the first DroneCAN virtual serial port a MAVLink (CAN_D1_UC_S1_PRO is 2) and it is connecting to serial port 2 on CAN node 125. Serial port 2 is the port on the MatekL431 node that would normally be used for serial devices (eg. rangefinder, GPS etc).
In this example Iā€™m adding a telemetry radio, but you can use this with almost any serial device supported by ArduPilot, and can also use it with lua scripts to add new protocols.
You should be careful about using too much bandwidth on your CAN bus. With the default of 1MBit bxCAN we can do at most 430 kBit/sec of data on the CAN bus. You should use this new capabilitity for lower bandwidth devices.
Power Warning
It would be very easy to exceed the power supply capabilities of your CAN bus with a setup like this. For telemetry radios and any other device that can take a significant amount of current you should use a dedicated CAN bus power supply. A good example is this one from Holybro:

See CAN Hub ā€“ Holybro Store for details.
4.4.x Backport
This feature is part of the 4.5.x development series, but it is availble as a backport to 4.4.x if needed:
DroneCAN: serial over CAN backport for 4.4.x by tridge Ā· Pull Request #25599 Ā· ArduPilot/ardupilot Ā· GitHub

9 Likes

Is the #define MAVLINK_COMM_NUM_BUFFERS 5 still there, so the maximum number of mavlink ports has remained 5 (including USB)?

It is 5 at the moment, 7 if you have networking enabled. We should probably raise that to 7 if you have CAN enabled.
Cheers, Tridge

2 Likes

Does it support RTS/CTS?

not yet, but it will do when we add SERIALn_OPTIONS and SERIALn_RTSCTS on the periph node

3 Likes

Hi,
where i can find how the serial port data packeted and sent over dronecan?
My telemetry has a canbus transceiver, i can read all the packets on the bus.
I want to read from can on the air unit and send the data on uart on the ground.
The documentation i found lack most infos.
Thank you

It is transmitted using the uavcan.tunnel.Targetted message.
the DSDL is here:

2 Likes

Hello Andrew,

This sounds really interesting, iā€™m running out of ports on the Cube Orange and would love to try it out!

Could you create a build for me? Iā€™m running the 4.4.3 copter firmware :slight_smile:

start with ground testing using master (ie. ā€˜latestā€™ firmware). I also have a backport to 4.4.x that I could build for you, but first check the feature works for you with master

1 Like

The feature is working with the Matek AP_PERIPH CAN NODE L431, on the 4.5.0-dev firmware :slight_smile:

2 Likes

Iā€™m not too sure about how to build the firmware. If you are able to build me a copter 4.4.3 firmware with the feature included, i would be happy to share some user experience :smiley:

Can thr port handle option 23, RCInput? I am finding that the routine to locate a receiver completes before the CAN UART appears in the system? I want to use crossfire protocol with two way telemetry. Thanks.

This PR adds UARTn_OPTIONS and UARTn_RTSCTS to AP_Periph, so you can do inverted RX/TX pins, half duplex etc. That will make a wider range of RC protocols possible over CAN

2 Likes

Awesome, thanks for your work!
Iā€™m wondering how the feature works. I guess that once you have RTS/CTS flow control enabled, the autopilot can decrease stream rates to adapt for actual telemetry radio data rate. Shouldnā€™t there be some kind of signaling between autopilot and CAN node to inform the autopilot to change telemetry rates or so?
Also, could you please point me to the code where the actual RTS/CTS logic is implemented on the autopilot itself?

1 Like

@tridge just checking. This feature doesnā€™t mean that I can send/receive mavlink messages over CAN, right? I.e. I canā€™t use a CAN physical connection between a companion computer and my autopilot and send/receive MAVLink messages between the two over the CAN link, right?

This is a skidsteer rover. My companion computer (RPi) is on CAN, and the Pixhawk 6C is on CAN, and my ESCs are on CAN. My Pixhawk is successfully commanding traction motors using throttleleft & throttleright signals over CAN to the ESCs. But I still need a USB/UART connection between companion computer and Pixhawk so that the companion computer can talk MAVLink to Ardurover. That USB/UART connection isnā€™t as robust as CAN due to EMI and occasional USB-to-serial glitches on the RaspberryPi.

Thought Iā€™d ask

you can do MAVLink over CAN, yes

you would need a small python script on the RPi to map the CAN tunnelled serial to a UDP or TCP connection for a GCS to connect to. I havenā€™t written a script like that yet, but it is certainly possible.

I have shared a example script in this post, it is working good, doing Mavlink over CAN