AP_Scripting: add CircuitStatus DroneCAN battery driver#33763
Conversation
maps uavcan.equipment.power.CircuitStatus circuits onto scripting battery monitor instances, giving per-circuit voltage and current monitoring from CAN power distribution nodes
sends a CircuitStatus message per active battery backend with circuit_id of the instance number plus one, allowing testing of the CircuitStatus lua driver
adds periph_board to the quadplane-can frame so restart_SITL_frame spawns the AP_Periph companion, driver script install helpers and a plane test checking that scripting monitors fed from CircuitStatus match a DroneCAN reference monitor on the same periph battery
|
Is there an actual device/product that can use this? we could add into the wiki |
CircuitStatus is used by quite a few devices, its a generic DroneCAN way of reporting a voltage and current. I've seen it on quite a few devices, although the motivation for this work was for a HFE EFI setup on a large quadplane. |
|
|
||
| The script uses the following parameters: | ||
|
|
||
| ## DCS_NUM_CIRCUITS |
There was a problem hiding this comment.
This should be nested more deeply
| This driver should be loaded by placing the lua script in the | ||
| APM/SCRIPTS directory on the microSD card, which can be done either |
There was a problem hiding this comment.
Probably not. Probably should be built into ROMFS on systems advanced enough to use it.
| #endif | ||
| void can_battery_update(); | ||
| void can_battery_send_cells(uint8_t instance); | ||
| #if CONFIG_HAL_BOARD == HAL_BOARD_SITL |
There was a problem hiding this comment.
| #if CONFIG_HAL_BOARD == HAL_BOARD_SITL | |
| #if AP_PERIPH_CAN_CIRCUIT_SENDING_ENABLED |
.... make that new define dependent on AP_PERIPH_BATTERY_ENABLED at the very least
| void can_battery_send_cells(uint8_t instance); | ||
| #if CONFIG_HAL_BOARD == HAL_BOARD_SITL | ||
| void can_circuit_status_update(); | ||
| #endif |
There was a problem hiding this comment.
| #endif | |
| #endif // AP_PERIPH_CAN_CIRCUIT_SENDING_ENABLED |
useful for conflict resolution - several bugs fixed recently because this wasn't done
| struct { | ||
| uint32_t last_read_ms; | ||
| uint32_t last_can_send_ms; | ||
| #if CONFIG_HAL_BOARD == HAL_BOARD_SITL |
There was a problem hiding this comment.
| #if CONFIG_HAL_BOARD == HAL_BOARD_SITL | |
| #if AP_PERIPH_CAN_CIRCUIT_SENDING_ENABLED |
etc
| for _, h in ipairs(handles) do | ||
| -- drain all pending messages | ||
| while true do | ||
| local payload, _ = h:check_message() |
There was a problem hiding this comment.
We're dropping information about the source here. Meaning circuitstatus id must be unique on the bus. Worth documenting, at least.
Summary
Adds a lua driver for the DroneCAN uavcan.equipment.power.CircuitStatus message, mapping individual circuits onto ArduPilot battery monitor instances, with SITL support and an autotest.
Classification & Testing (check all that apply and add your own)
The new QuadPlane.CircuitStatusScript autotest boots the quadplane-can frame with the driver installed and checks that two scripting monitors fed from CircuitStatus match a DroneCAN reference monitor on the same periph battery for both voltage and current, which also covers the float16 decoding.
Description
This allows per-circuit voltage and current from a CAN power distribution board to be monitored, logged and reported as batteries.
The number of circuits is set with DCS_NUM_CIRCUITS, which dynamically creates DCSx_CIRCUIT_ID and DCSx_BATT_IDX parameters mapping each circuit_id to a battery monitor instance with BATTn_MONITOR=29 (scripting). Circuit mappings are picked up at runtime, only DCS_NUM_CIRCUITS needs a reboot.
To enable testing, the SITL AP_Periph build now sends a CircuitStatus message per active battery backend, and the quadplane-can frame gained a periph_board entry so restart_SITL_frame() can spawn the periph companion in autotests (sim_vehicle.py already defaulted to sitl_periph_universal for this frame).
Tested in SITL and on a CubeOrangePlus with HFE engine which has 3 CircuitStatus messages