In this article we will extend functionality of a UAVCAN node from previous tutorial. For pragmatic purposes we will make something that can be used - UAVCAN to RCPWM converter.
Our goal is to make Zubax Babel act as UAVCAN node and receive RCPWM values via CAN and then convert them to RCPWM signal.
Couple words about RCPWM. RCPWM is the most widespread way of interaction in hobby RC world. All servos and almost all motor controllers support it(and there are lots and lots of other devices that communicate this way). Without doubt it is very old, slow and limited interface and today it must be replaced with something better like UAVCAN. But this is legacy and we have to deal with it. From physical standpoint RCPWM is just PWM signal with period of 20mS and the infromation is coded in pulse widthm which may vary from 1 mS to 2 mS with neutral value 1.5 mS. To generate that we will use timers that are available on Zubax Babel according to datasheet where we can find detailed pinout:
We will use TIM12_CH1, TIM12_CH2, TIM3_CH1, TIM3_CH2, TIM3_CH3, TIM3_CH4, utilizing all available pins.
We will base our project on the code from Basic tutorial end add lacking functions. Firstly we should add support of a new message type to
shouldAcceptTransfer and its appropriate handler to
We added support of
UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID, message that contains all values needed to generate RCPWM signal. UAVCAN GUI Tool starts to broadcast these messages when ESC Management panel is opened.
Now its handler's turn, where RCPWM values are passed to MCU timers
And that's it. Now its time to open UAVCAN GUI Tool and go to
ESC Management panel
Our device supports up to six channels, so increase number of channels and try moving sliders.
If you connect oscilloscope Babel you may see something like this:
Or you may connect servos and see them moving after the slider in ESC panel.