3 #ifdef HAL_PERIPH_ENABLE_IMU
4 #include <dronecan_msgs.h>
6 extern const AP_HAL::HAL
&hal
;
9 update CAN magnetometer
11 void AP_Periph_FW::can_imu_update(void)
14 // we need to delay by a ms value as hal->schedule->delay_microseconds_boost
15 // used in wait_for_sample() takes uint16_t
16 const uint32_t delay_ms
= 1000U / g
.imu_sample_rate
;
17 hal
.scheduler
->delay(delay_ms
);
20 // sleep for a bit to avoid flooding the CPU
21 hal
.scheduler
->delay_microseconds(100);
30 uavcan_equipment_ahrs_RawIMU pkt
{};
33 imu
.get_delta_velocity(tmp
, pkt
.integration_interval
);
34 pkt
.accelerometer_integral
[0] = tmp
.x
;
35 pkt
.accelerometer_integral
[1] = tmp
.y
;
36 pkt
.accelerometer_integral
[2] = tmp
.z
;
38 imu
.get_delta_angle(tmp
, pkt
.integration_interval
);
39 pkt
.rate_gyro_integral
[0] = tmp
.x
;
40 pkt
.rate_gyro_integral
[1] = tmp
.y
;
41 pkt
.rate_gyro_integral
[2] = tmp
.z
;
43 tmp
= imu
.get_accel();
44 pkt
.accelerometer_latest
[0] = tmp
.x
;
45 pkt
.accelerometer_latest
[1] = tmp
.y
;
46 pkt
.accelerometer_latest
[2] = tmp
.z
;
49 pkt
.rate_gyro_latest
[0] = tmp
.x
;
50 pkt
.rate_gyro_latest
[1] = tmp
.y
;
51 pkt
.rate_gyro_latest
[2] = tmp
.z
;
53 uint8_t buffer
[UAVCAN_EQUIPMENT_AHRS_RAWIMU_MAX_SIZE
];
54 uint16_t total_size
= uavcan_equipment_ahrs_RawIMU_encode(&pkt
, buffer
, !canfdout());
55 canard_broadcast(UAVCAN_EQUIPMENT_AHRS_RAWIMU_SIGNATURE
,
56 UAVCAN_EQUIPMENT_AHRS_RAWIMU_ID
,
57 CANARD_TRANSFER_PRIORITY_HIGH
,
62 #endif // HAL_PERIPH_ENABLE_IMU