|
|
|
@ -1055,6 +1055,9 @@ void AP_Periph_FW::pwm_irq_handler(uint8_t pin, bool pin_state, uint32_t timesta
@@ -1055,6 +1055,9 @@ void AP_Periph_FW::pwm_irq_handler(uint8_t pin, bool pin_state, uint32_t timesta
|
|
|
|
|
uint32_t width = timestamp - pwm_hardpoint.last_ts_us; |
|
|
|
|
if (width > 500 && width < 2500) { |
|
|
|
|
pwm_hardpoint.pwm_value = width; |
|
|
|
|
if (width > pwm_hardpoint.highest_pwm) { |
|
|
|
|
pwm_hardpoint.highest_pwm = width; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
pwm_hardpoint.last_state = pin_state; |
|
|
|
@ -1065,11 +1068,17 @@ void AP_Periph_FW::pwm_hardpoint_update()
@@ -1065,11 +1068,17 @@ void AP_Periph_FW::pwm_hardpoint_update()
|
|
|
|
|
{ |
|
|
|
|
uint32_t now = AP_HAL::millis(); |
|
|
|
|
// send at 10Hz
|
|
|
|
|
if (now - pwm_hardpoint.last_send_ms >= 100) { |
|
|
|
|
void *save = hal.scheduler->disable_interrupts_save(); |
|
|
|
|
uint16_t value = pwm_hardpoint.highest_pwm; |
|
|
|
|
pwm_hardpoint.highest_pwm = 0; |
|
|
|
|
hal.scheduler->restore_interrupts(save); |
|
|
|
|
float rate = g.hardpoint_rate; |
|
|
|
|
rate = constrain_float(rate, 10, 100); |
|
|
|
|
if (value > 0 && now - pwm_hardpoint.last_send_ms >= 1000U/rate) { |
|
|
|
|
pwm_hardpoint.last_send_ms = now; |
|
|
|
|
uavcan_equipment_hardpoint_Command cmd {}; |
|
|
|
|
cmd.hardpoint_id = g.hardpoint_id; |
|
|
|
|
cmd.command = pwm_hardpoint.pwm_value; |
|
|
|
|
cmd.command = value; |
|
|
|
|
|
|
|
|
|
uint8_t buffer[UAVCAN_EQUIPMENT_HARDPOINT_COMMAND_MAX_SIZE]; |
|
|
|
|
uint16_t total_size = uavcan_equipment_hardpoint_Command_encode(&cmd, buffer); |
|
|
|
|