I am working on integrating px4 with a freeRTOS system using UAVCAN. I have downloaded the latest firmware from git repository. I found an existing example of UAVCAN with esc. I have few questions regarding it.
From uavcan_main.cpp , two functions in esc.cpp is getting called. First function being
*void UavcanEscController::update_outputs(float outputs, unsigned num_outputs) which is working fine.
The other function being
void UavcanEscController::esc_status_sub_cb(const uavcan::ReceivedDataStructureuavcan::equipment::esc::Status &msg)
which is not getting executed at all. Am I missing any particular esc driver over here? if so, can someone please point me in the right direction.
Because when I built it, I build it with only uavcan driver and not with uavcanesc driver.
Is the above scenario is related to build and debug configurations?? cause i am not facing any error while building but the settings are not clearly mentioned for this in the documentation.
Is the above scenario happening cause of missing uavcan driver or esc driver cause I have written a similar function
which has a new CAN message. But this function is also not getting executed like the above one inside esc.cpp
Is it becasue of the hardware dependency ? Cause I use qGroundControl and I have enabled “UAVCAN settings” and others as well. But When I initiate command
“uavcan start” only update_outputs function from point 1 is getting executed ignoring esc_status_sub_cb from point 1.
Any pointers would be highly helpful. I tried all troubleshooting and looking into forums i could. But I am missing a file or a patch which I am not able to figure out.
Thanks and Regards
I’m not sure exactly where you see esc_status_sub_cb being called, at least from the latest PX4 drivers/uavcan/actuators/esc.cpp file. The callback function gets setup in the init() function of UavcanEscController class and then the uORB topic gets copied in uavcan_main.cpp.
If I understand correctly, the uavcanesc driver is the driver for setting up an actual ESC device. Are you trying to set up this device as an ESC or are you trying to connect an ESC to it?
If you are trying to interface with another ESC, you need to make sure the UAVCAN ESC is publishing the status message.
Thank you for your reply. Yes, what you mentioned is correct.
void esc_status_sub_cb(const uavcan::ReceivedDataStructure uavcan::equipment::esc::Status> &msg); is a call-back function which gets setup in init()function of UavcanEscController class.
The application I am working on is, I am trying to get an input to px4 using uavcan from an external hardware device(a freeRTOS system). But I was not able to understand how to do it, so I looked into esc.cpp and esc.hpp files.
- I created a new CAN message called TesteReceive with a uint8_t variable inside it under uavcan/libuavcan/dsdl/uavcan/equipment folder.
- I also created my own teste_actuator.cpp and teste_actuator.hpp files under actuator folder like how it is done for ESC.
- Inside teste_actuator.cpp I created a function called
(const uavcan::ReceivedDataStructure uavcan::equipment::teste::TesteReceive> &msg) which would look for incoming messages in the CAN port and display it. I also made this function as callback function and I am calling it from uavcan_main.cpp. [UavcanTeste is class like how UavcanEscController class is for ESC ]
But this function is never getting executed when I connect the can port of pixhawk with external freeRTOS system. I placed print statements inside this function but not working.
How do I make px4 receive an external input from other hardware using uavcan? i apologize if I am not making my explanation clear.
Any comments would help me a lot.
Thanks and Regards
Are you sure that you are broadcasting the uavcan.equipment.esc.Status message?
If you have an SLCAN adapter, I would recommend using the UAVCAN GUI tool to monitor the messages on the CAN bus with your FreeRTOS node working. This will let you know whether there is an issue with receiving the message or sending the message.
If you don’t have an SLCAN node such as the Zubax Babel, I would highly recommend getting one as the UAVCAN GUI tool is indispensable when developing a UAVCAN application.
I’m going to ping @PavelKirienko, he might be able to help here.
Thank you for your inputs. Yes, I have placed an order for SLCAN adapter. I will check with adapter and get back if I have any issues.
Thanks and Regards
Thank you for your inputs.
(types nervously - this is meant to help not offend).
If you have a Pixhawk for bench testing, you can use ArduPilot as an slcan or serial adapter these days, and avoid the need for a babel or ftdi when testing/configuring peripherals. It’s a pretty handy feature…
I’m not sure it’s documented, but is available in Master and Beta Missionplanner.
Yes, I tried with ardupilot but I was facing difficulty during testing since I am new to this. But, I would give it a try again. Thank you for your inputs.
Thanks and Regards
I think you misunderstood: the problem you have isn’t related to the flight stack. You can set a serial option to slcan in ArduPilot (Master), including the USB port. That enables use of the Pixhawk itself as an slcan adapter. Once you have the peripherals set up, use whatever flight stack you wish.
Yeah!! I think I got it now. So, irrespective of the flight stack i use i can setup a serial connection to slcan in ardupilot to check whether hardfault or where my code is failing.
I also noticed one thing in my code. I created a new DSDL file to send a data from pixhawk board to an external device(a freeRTOS system). I chose a new datatype id say 760 like this 760.SendData.uavcan which has an uint8 variable whose value will be updated every second [similar like how is written for esc 1030.RawCommand.uavcan]
Am I proceeding in a right manner? Is there any restrictions on how should I choose datatype id? I wish I had more understanding in above things.
Yes, but I think there are some guidelines on which id’s are for custom use and which are part of the UAVCAN master. Check out the vendor-specific data types section here.
This is only a convention, but could prevent possible future conflicts. As long as nothing else is using 760 (I didn’t find any in a quick search of the standard data types page), it should work; it’s just not best practice.
Do you have this data type defined on both the Pixhawk and your custom device?
Also, you will need to put this definition in the DSDL for the UAVCAN GUI tool in order to properly interpret it using the bus monitor. There are instructions for how to do that here. Have you had any success in reading the message with the UAVCAN GUI tool?
Thank you for your inputs .
yes, I checked the guidelines like you mentioned. Since 760 was not previously used by firmware, I used it. I would be modifying it once I successfully complete this project. Yes, I have mentioned the data type in both pixhawk and my custom device.
I have placed an order for SLCAN adapter, I am yet to receive it. !
In the meantime, I tried something different. I connected my CAN high and low pins between these two devices to oscilloscope to verify if there are any signal changes.I could see signal lines when I initiate “uavcan start” .
But my custom device is not able to receive the value properly! It used FlexCAN. I am not sure why!!I am making required code changes now to make it work.
Thanks and Regards
I tried testing it through SLCAN adapter. When I run my “uavcan start” command,
“Discovery not possible”- Local node is configured as an anonymous node. I tried loading different files but error persists.
Finally I received “Node failure” error and terminated.
I. I have created a data Type ID - 760
2. I have not mentioned any node id.
Am I missing something? Would be helpful if you could help me
Have you tried to give your node an actual ID? I never run my nodes as anonymous, so I can’t help you with that.
I usually get the error you show in the screenshot when I unplug the SLCAN adapter or it somehow becomes disconnected. That just says that the SLCAN adapter is not working right. Does the UAVCAN tool work without your device connected?
I tried setting a node ID for example 127 and many others. Still same. I am not able to fetch any data!
I even took a fresh patch from Git and tried to check with SLCAN adapter but could not visualize any results.
This is the screenshot for that:
No, UAVCAN tool did not work when my device is not connected.
I read through the documentation again. I am confused at two places.
- How do I choose the local node ID field in UAVCAN GUI tool. It takes vales from 0 to 127?
- The SLCAN adapter I am using is Zubax Babel. Does it support Pixhawk4 board ? Cause there is something else called Zubax GNSS. https://kb.zubax.com/display/MAINKB/Using+Zubax+GNSS+with+PX4+autopilots
From their documentation page : https://shop.titaneliteinc.com/index.php?route=product/product&product_id=987
Devices which are known to support UAVCAN peripherals:
• Pixhawk Autopilot Series (both PX4 and APM firmware): Pixhawk, Pixhawk 2 (Cube), Pixhawk 3 Pro, Pixhawk 4, Pixracer
Now I am not sure where there it is Zubax babel or zubax GNSS with pixhawk 4 board!
any pointers is much helpful? I am struck in same place for a long time!!
Thanks and Regards
Thank you for the help. I was able to visualize something now. With respect to the things you mentioned above.
Yes, 127 was not used by anything else. I checked the protocol files. I used 127 as such.
yes, babel worked fine now.
yes, the baud rate is same as 115200 for my pixhawk and Babel.
Yes, I was trying in a wrong way. i did not do any coding in firmware to make the param fetch. I was trying in a wrong manner.
the bus monitor worked like a charm. I was so naive to miss these days. From my pixhawk I am sending data(integer) through CAN ID as 760 and I was able to see this in bus monitor.
I could see the CAN ID as 1002F801 but my data type shows as <unknown message 760> [unlike this format uavcan.equipment.teste.TesteCommand (the location for the file)] like how its showing up in example. Is it gonna be a problem ?
Many thanks for your valuable inputs.
I’m not sure what you are getting at. Is the data hex as you expect?
You definitely need to figure out how to get the GUI tool to recognize your custom command. I haven’t actually done that myself, but there are tutorials on the UAVCAN website on how to do that. It should be pretty straightforward. I think you have to specify the path to your file when you launch the GUI tool.
Yes, data hex is as expected.
Now I am able to send data from px4 and received data in px4 as well. Could see the values in Bus monitor during send and receive.
But I am not able to print and display the received values in qgroundControl. I have used a simple uorb function to subscribe and display the data. its not working properly.
Any other ways to show the received data in qgroundControl?