Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/AP_Periph/imu.cpp
Views: 1798
#include "AP_Periph.h"12#ifdef HAL_PERIPH_ENABLE_IMU3#include <dronecan_msgs.h>45extern const AP_HAL::HAL &hal;67/*8update CAN magnetometer9*/10void AP_Periph_FW::can_imu_update(void)11{12while (true) {13// we need to delay by a ms value as hal->schedule->delay_microseconds_boost14// used in wait_for_sample() takes uint16_t15const uint32_t delay_ms = 1000U / g.imu_sample_rate;16hal.scheduler->delay(delay_ms);1718if (delay_ms == 0) {19// sleep for a bit to avoid flooding the CPU20hal.scheduler->delay_microseconds(100);21}2223imu.update();2425if (!imu.healthy()) {26continue;27}2829uavcan_equipment_ahrs_RawIMU pkt {};3031Vector3f tmp;32imu.get_delta_velocity(tmp, pkt.integration_interval);33pkt.accelerometer_integral[0] = tmp.x;34pkt.accelerometer_integral[1] = tmp.y;35pkt.accelerometer_integral[2] = tmp.z;3637imu.get_delta_angle(tmp, pkt.integration_interval);38pkt.rate_gyro_integral[0] = tmp.x;39pkt.rate_gyro_integral[1] = tmp.y;40pkt.rate_gyro_integral[2] = tmp.z;4142tmp = imu.get_accel();43pkt.accelerometer_latest[0] = tmp.x;44pkt.accelerometer_latest[1] = tmp.y;45pkt.accelerometer_latest[2] = tmp.z;4647tmp = imu.get_gyro();48pkt.rate_gyro_latest[0] = tmp.x;49pkt.rate_gyro_latest[1] = tmp.y;50pkt.rate_gyro_latest[2] = tmp.z;5152uint8_t buffer[UAVCAN_EQUIPMENT_AHRS_RAWIMU_MAX_SIZE];53uint16_t total_size = uavcan_equipment_ahrs_RawIMU_encode(&pkt, buffer, !canfdout());54canard_broadcast(UAVCAN_EQUIPMENT_AHRS_RAWIMU_SIGNATURE,55UAVCAN_EQUIPMENT_AHRS_RAWIMU_ID,56CANARD_TRANSFER_PRIORITY_HIGH,57&buffer[0],58total_size);59}60}61#endif // HAL_PERIPH_ENABLE_IMU626364