diff --git a/sw/airborne/arch/chibios/modules/uavcan/uavcan.c b/sw/airborne/arch/chibios/modules/uavcan/uavcan.c index 38d2a6bffa..9c0fee744d 100644 --- a/sw/airborne/arch/chibios/modules/uavcan/uavcan.c +++ b/sw/airborne/arch/chibios/modules/uavcan/uavcan.c @@ -58,9 +58,7 @@ struct uavcan_iface_t uavcan1 = { .thread_tx_wa_size = sizeof(uavcan1_tx_wa), .node_id = UAVCAN_CAN1_NODE_ID, .transfer_id = 0, - .initialized = false, - .cnt_act_raw = 0, - .cnt_act_cmd = 0 + .initialized = false }; #endif @@ -86,9 +84,7 @@ struct uavcan_iface_t uavcan2 = { .thread_tx_wa_size = sizeof(uavcan2_tx_wa), .node_id = UAVCAN_CAN2_NODE_ID, .transfer_id = 0, - .initialized = false, - .cnt_act_raw = 0, - .cnt_act_cmd = 0 + .initialized = false }; #endif diff --git a/sw/airborne/arch/chibios/modules/uavcan/uavcan.h b/sw/airborne/arch/chibios/modules/uavcan/uavcan.h index 46898c837c..2920324034 100644 --- a/sw/airborne/arch/chibios/modules/uavcan/uavcan.h +++ b/sw/airborne/arch/chibios/modules/uavcan/uavcan.h @@ -51,9 +51,6 @@ struct uavcan_iface_t { uint8_t transfer_id; bool initialized; - - uint16_t cnt_act_raw; - uint16_t cnt_act_cmd; }; /** Generic uavcan callback definition */ @@ -82,4 +79,4 @@ void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_eve void uavcan_broadcast(struct uavcan_iface_t *iface, uint64_t data_type_signature, uint16_t data_type_id, uint8_t priority, const void *payload, uint16_t payload_len); -#endif /* MODULES_UAVCAN_ARCH_H */ \ No newline at end of file +#endif /* MODULES_UAVCAN_ARCH_H */ diff --git a/sw/airborne/modules/actuators/actuators_uavcan.c b/sw/airborne/modules/actuators/actuators_uavcan.c index d538de07e4..5b862399a9 100644 --- a/sw/airborne/modules/actuators/actuators_uavcan.c +++ b/sw/airborne/modules/actuators/actuators_uavcan.c @@ -454,14 +454,9 @@ void actuators_uavcan_commit(struct uavcan_iface_t *iface, int16_t *values, uint offset += 14; } - iface->cnt_act_raw++; - if(iface->cnt_act_raw >= ACTUATORS_UAVCAN_RAW_DIV) { - iface->cnt_act_raw = 0; - - // Broadcast the raw command message on the interface - uavcan_broadcast(iface, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID, - CANARD_TRANSFER_PRIORITY_HIGH, buffer, (offset + 7) / 8); - } + // Broadcast the raw command message on the interface + RunOnceEvery(ACTUATORS_UAVCAN_RAW_DIV, uavcan_broadcast(iface, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID, + CANARD_TRANSFER_PRIORITY_HIGH, buffer, (offset + 7) / 8)); } /** @@ -493,12 +488,7 @@ void actuators_uavcan_cmd_commit(struct uavcan_iface_t *iface, int16_t *values, offset += 16; } - iface->cnt_act_cmd++; - if(iface->cnt_act_cmd >= ACTUATORS_UAVCAN_CMD_DIV) { - iface->cnt_act_cmd = 0; - - // Broadcast the raw command message on the interface - uavcan_broadcast(iface, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_ID, - CANARD_TRANSFER_PRIORITY_HIGH, buffer, (offset + 7) / 8); - } + // Broadcast the raw command message on the interface + RunOnceEvery(ACTUATORS_UAVCAN_CMD_DIV, uavcan_broadcast(iface, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_ID, + CANARD_TRANSFER_PRIORITY_HIGH, buffer, (offset + 7) / 8)); }