Hi, I am currently working on a redundancy system with the CubeOrange Flight Controller where we have another separate microcontroller that does other systems control in our UAV. Currently, I am trying to write a LUA script that would allow data to be collected in a more compact manner and then republished into the CAN bus of our system. A simple setup that would allow me to replicate what we have on the drone is basically the following:
List of peripherals
- Flight Controller (running scripting interface)
- Here4 GPS
- Benewake TF03
- canable (USB-CAN)
Since the latest firmware, ardupilot now supports Benewake CAN which is really useful for our other microcontroller to be able to access sonar range data through the CAN Bus. As of now, I am indeed able to retrieve the Benewake CAN data when I set it up as follows:
Test 1 setup
- CAN Bus isolated (CAN1 and CAN2 port not connected onto the same CAN Bus)
- CAN1 port consists of DroneCAN and Benewake CAN
- CAN2 port consists of only Scripting interface which publishes CAN message with an ID of 0x1
- Both CAN port is setup to use the first driver
Results
- When the usbcan is plugged into the CAN1 bus, I am getting data from the Benewake CAN of ID 0x3 along with some DroneCAN msg data
- CAN2 bus only has DroneCAN msg data (although I did not configure DroneCAN on 2nd bus). No CAN from ID 0x1 being published here
Test 2 setup
- CAN Bus isolated (CAN1 and CAN2 port not connected onto the same CAN Bus)
- CAN1 port consists of DroneCAN and Benewake CAN
- CAN2 port consists of only Scripting interface which publishes CAN message with an ID of 0x1
- CAN1 port is using first driver, CAN2 port is using second driver
Results
- When the usbcan is plugged into the CAN1 bus, I am getting data from the Benewake CAN of ID 0x3 along with some DroneCAN msg data
- Only custom CAN data from the scripting interface appears on CAN2 bus. No DroneCAN data.
Test 3 setup
- CAN Bus isolated (CAN1 and CAN2 port not connected onto the same CAN Bus)
- CAN1 port consists of DroneCAN and Benewake CAN
- CAN2 port consists of only Scripting interface which publishes CAN message with an ID of 0x1
- CAN1 port is using first driver, CAN2 port is using third driver
Results
- When the usbcan is plugged into the CAN1 bus, I am getting data from the Benewake CAN of ID 0x3 along with some DroneCAN msg data
- No CAN Data at all on the CAN2 bus!
From the following set of test, only Test 2 setup works for my scripting interface which is really promising. Since, the point of this test is so that the other microcontroller is able to read both Benewake TF03 data as well as the scripting interface CAN data, it needs to be on the same CAN Bus. So, this next setup would allow me to do so:
In this setup, I maintained the successful test 2 setup with the only difference being that I plugged everything into a single CAN Hub. This essentially means that now CAN1 and CAN2 port are both on the same CAN Bus.
I then plugged my usbcan onto the CAN Bus and here, I managed to get everything to work on the same CAN Bus as seen in the screenshot below
So, with all of that said, I have a few questions in mind to further understand this issue:
- Whats the difference between the first, second and third driver? When should I consider using the third driver?
- Why does scripting not work using first driver on CAN2 port?
- Why is it that in first test setup, I am getting DroneCAN data although I did not enable DroneCAN and instead, CAN_D2_PROTOCOL is explicitly set to Scripting (10) interface?
- I have not managed to get this working yet, but is it possible for me to use the scripting interface to read non-DroneCAN data (e.g. CAN data with an 11 bit ID)? I looked into the LUA docs, but it seems as though it could not read non-DroneCAN data or I might be doing it wrong. The ID data type is also specified as uint32_t which means that it might have only expected 29-bit ID.
Just in case it helps, here is my physical setup
Thanks in advanced!