ESC control via Proprietary CAN message (Ardurover running on Raspberry Pi)

Hi everyone,

For a rover with traction ESCs which must be commanded with proprietary CAN messages, what is the best approach? We are running Ardurover on Raspberry Pi.

Our initial plan is to configure ArduRover to transmit DroneCan, then, write a Python service running on the Raspberry Pi which listens to ArduRover’s DroneCan messages and translates/sends proprietary CAN messages. Not the most efficient perhaps (Ardurover will be transmitting CAN messages which are received and acted upon by another process on the same host after all) but modular and easily debuggable.

Is there a better approach? Would an ArduPilot Lua script be able to hook into an internal event or message with the commanded ESC speeds and write raw custom CAN frames efficiently? Does a LUA script even make sense given that we’re running on a Raspberry Pi?

We’d rather not maintain a custom fork of Ardurover, so we’d rather not implement in C++. But if there’s a compelling reason to, then we will.

Thank you for any advice or thoughts!!!

A Lua script is almost certainly more than adequate. I wrote a rather complex CAN driver for some industrial drivers that ran at 20+ Hz very effectively. A less complex protocol would see even better performance.

Thanks for your quick response, and Happy New Year!

So LUA scripts are supported for Ardurover running on a RPi?

How best should the LUA script capture (or be notified of) the commanded ESC values for left and right motor? Should we just periodically poll each channel using get_output_pwm(output_function)?

Chris

Yes, scripting should be supported. You can check as to whether SCR_ENABLE appears in the params, but I’m fairly certain it should. You can use the SRV_Channels:get_output_scaled() binding for the left and right throttle functions (those functions may need to be assigned to unused channels for the binding to work).

Alternatively, if you wish to forego Lua and write a driver service, you can use MavLink messaging to capture throttle state at up to ~50Hz.

In your view is one approach (LUA script vs MAVLink client) inherently more or less robust /stable than the other?

My experience with Linux-run ArduPilot is not deep enough to give an opinion there. I’d start with Lua and see how it goes.

Up and running, here are can0_stats.txt

tx_requests: 159
tx_rejected: 0
tx_overflow: 0
tx_confirmed: 2
tx_success: 4
tx_timedout: 122
rx_received: 159
rx_errors: 0
num_downs: 0
num_rx_poll_req: 2528
num_tx_poll_req: 0
num_poll_waits: 0
num_poll_tx_events: 0
num_poll_rx_events: 0

We are working through trying to figure out why most messages timeout.