PX4-Autopilot icon indicating copy to clipboard operation
PX4-Autopilot copied to clipboard

Initial Cannode PWM Support

Open AlexKlimaj opened this issue 2 years ago • 5 comments

This PR adds initial support for Cannode PWM adapters such as the ARK CANnode.

https://arkelectron.com/product/ark-cannode/

All the basic pieces are in place. The individual PWM_MAIN params on the node need to be setup for the desired PWM output behavior. FUNC as well as MIN, MAX, DISARM, etc.

Then using the control allocator on the flight controller, setup the motor/servo outputs to use UAVCAN. One caveat is that COM_PREARM_MODE needs to be set on the flight controller for the actuator test to work through QGC to the cannode output.

UAVCAN_PUB_ARM on the flight controller needs to be enabled for the cannode outputs to work.

dshot is running but does not appear to work.

https://review.px4.io/plot_app?log=f89c1a70-f969-4493-adf8-86f1715dcd55

AlexKlimaj avatar May 30 '22 20:05 AlexKlimaj

I think we need to handle both ESCs and Actuators. https://github.com/dronecan/DSDL/tree/master/uavcan/equipment/actuator

dagar avatar Jun 01 '22 17:06 dagar

I think we need to handle both ESCs and Actuators. https://github.com/dronecan/DSDL/tree/master/uavcan/equipment/actuator

dagar avatar Jun 01 '22 17:06 dagar

Added publishing actuator status. Need to figure out the flight controller side of publishing the setpoints. Then I need to add the subscribers to the node.

AlexKlimaj avatar Jun 13 '22 04:06 AlexKlimaj

This needs retesting since the mixer purge.

AlexKlimaj avatar Sep 15 '22 18:09 AlexKlimaj

This needs retesting since the mixer purge.

The entire rc.interface can be purged now and replaced with just starting the output modules.

dagar avatar Sep 15 '22 18:09 dagar

Hi @AlexKlimaj

I've rebased to master and tried it on my UCANS32K1 board but I'm getting no output on my PWM channels. I've hooked it up to a FMU and enabled UAVCAN_PUB_ARM on the FMU and sub on the node.

NuttShell (NSH) NuttX-10.0.0
nsh> pwm_out status
pwm_out: cycle: 83 events, 1758us elapsed, 21.18us avg, min 15us max 223us 23.182us rms
pwm_out: interval: 83 events, 292773.99us avg, min 292us max 300082us 32894.711us rms
INFO  [mixer_module] Param prefix: PWM_MAIN
control latency: 0 events, 0us elapsed, 0.00us avg, min 0us max 0us 0.000us rms
Channel Configuration:
Channel 0: func:   0, value: 0, failsafe: 900, disarmed: 900, min: 1000, max: 2000
Channel 1: func:   0, value: 0, failsafe: 900, disarmed: 900, min: 1000, max: 2000
Timer 0: rate: 400 channels: 1
Timer 1: rate: 400 channels: 0
nsh> listener actuator_servos

TOPIC: actuator_servos
 actuator_servos
    timestamp: 52348336 (0.002170 seconds ago)
    timestamp_sample: 52348336 (0 us before timestamp)
    control: [0.0599, 0.0599, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]
nsh>

Could you describe a procedure to test this?

PetervdPerk-NXP avatar Oct 26 '22 15:10 PetervdPerk-NXP

Hi @AlexKlimaj

I've rebased to master and tried it on my UCANS32K1 board but I'm getting no output on my PWM channels. I've hooked it up to a FMU and enabled UAVCAN_PUB_ARM on the FMU and sub on the node.

NuttShell (NSH) NuttX-10.0.0
nsh> pwm_out status
pwm_out: cycle: 83 events, 1758us elapsed, 21.18us avg, min 15us max 223us 23.182us rms
pwm_out: interval: 83 events, 292773.99us avg, min 292us max 300082us 32894.711us rms
INFO  [mixer_module] Param prefix: PWM_MAIN
control latency: 0 events, 0us elapsed, 0.00us avg, min 0us max 0us 0.000us rms
Channel Configuration:
Channel 0: func:   0, value: 0, failsafe: 900, disarmed: 900, min: 1000, max: 2000
Channel 1: func:   0, value: 0, failsafe: 900, disarmed: 900, min: 1000, max: 2000
Timer 0: rate: 400 channels: 1
Timer 1: rate: 400 channels: 0
nsh> listener actuator_servos

TOPIC: actuator_servos
 actuator_servos
    timestamp: 52348336 (0.002170 seconds ago)
    timestamp_sample: 52348336 (0 us before timestamp)
    control: [0.0599, 0.0599, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]
nsh>

Could you describe a procedure to test this?

@PetervdPerk-NXP For bench testing, you need to enable COM_PREARM_MODE to get the dronecan arming message to send. Then you can use the actuator test commands in QGC.

AlexKlimaj avatar Oct 26 '22 20:10 AlexKlimaj

Hi @AlexKlimaj

I've enabled COM_PREARM_MODE on FMU and added following debugging print to ArmingStatus.hpp

+        printf("actuator_armed %i\n",
+                      actuator_armed.armed);

And I see that the node receives the arming message actuator_armed 1 And also actuator_servos gets updated but it seems to it doesn't get into the PWM subsystem.

TOPIC: actuator_armed
 actuator_armed
    timestamp: 50856922 (0.078972 seconds ago)
    armed: True
    prearmed: False
    ready_to_arm: False
    lockdown: False
    manual_lockdown: False
    force_failsafe: False
    in_esc_calibration_mode: False

nsh>

TOPIC: actuator_servos
 actuator_servos
    timestamp: 191708218 (0.001585 seconds ago)
    timestamp_sample: 191708218 (0 us before timestamp)
    control: [0.4399, -0.1400, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]

Do I need to configure something in the PWM subsystem to get this to work?

Question do you need control_allocator to get this to work?

PetervdPerk-NXP avatar Oct 28 '22 12:10 PetervdPerk-NXP

@PetervdPerk-NXP Did you setup the PWM_MAIN_TIMX and PWM_MAIN_FUNCX parameters on the node?

AlexKlimaj avatar Oct 31 '22 18:10 AlexKlimaj

@AlexKlimaj Setting PWM_MAIN_FUNCX solved it for me. Tested on my UCANS32K1 board and this PR seems to be working fine for me. @dagar can we get this in?

PetervdPerk-NXP avatar Nov 02 '22 07:11 PetervdPerk-NXP

Is there any timeline to when we can expect this to be merged? I would appreciate the functionality.

TorbjornHouge avatar Mar 06 '23 13:03 TorbjornHouge

If we add parameters or kconfig options for the new subscribers (so they aren't on by default) we could merge this immediately.

dagar avatar Mar 06 '23 14:03 dagar

Hi. I have attempted to enable "uavcannode" in kconfig (I assume this is the way it is planned to be activated, please correct me if I am wrong). I am using Cygwin in Windows.

When running "make cubepilot_cubeorange_default" after saving and exiting Kconfig interface, I get a bunch of errors. The conclusion when make finishes is this:

-- Configuring incomplete, errors occurred! See also "/cygdrive/c/PX4/home/PX4-Autopilot/build/cubepilot_cubeorange_default/CMakeFiles/CMakeOutput.log". See also "/cygdrive/c/PX4/home/PX4-Autopilot/build/cubepilot_cubeorange_default/CMakeFiles/CMakeError.log". Error: /cygdrive/c/PX4/home/PX4-Autopilot/build/cubepilot_cubeorange_default is not a directory make: *** [Makefile:227: cubepilot_cubeorange_default] Error 1

But there are also some errors of the type

add_library cannot create target "uavcan" because another target with the same name already exists. The existing target is a static library created in source directory

TorbjornHouge avatar Mar 22 '23 08:03 TorbjornHouge

@TorbjornHouge On the flight controller side you don't build in uavcannode. It just uses uavcan.

AlexKlimaj avatar Mar 22 '23 16:03 AlexKlimaj

Thanks @AlexKlimaj, I am starting to understand then

TorbjornHouge avatar Mar 23 '23 12:03 TorbjornHouge

From the investigation here: https://github.com/PX4/PX4-Autopilot/pull/21230#issuecomment-1483754432, I have identified this PR as the cause of start of Jenkins hardware rack CI failures.

Failure mode: with the error message 'Failsafe task activated' when gps stop is commanded, only for 5 out of 8 board targets. I think we should tackle this in the 1.14 release :thinking: @dagar

junwoo091400 avatar Mar 25 '23 07:03 junwoo091400

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/ark-cannode-actuator-setup/37211/2

DronecodeBot avatar Mar 12 '24 17:03 DronecodeBot