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/libraries/AP_AHRS/examples/AHRS_Test/AHRS_Test.cpp
Views: 1800
//1// Simple test for the AP_AHRS interface2//34#include <AP_AHRS/AP_AHRS.h>5#include <AP_HAL/AP_HAL.h>6#include <AP_BoardConfig/AP_BoardConfig.h>7#include <GCS_MAVLink/GCS_Dummy.h>8#include <AP_RangeFinder/AP_RangeFinder.h>9#include <AP_Logger/AP_Logger.h>10#include <AP_GPS/AP_GPS.h>11#include <AP_Baro/AP_Baro.h>12#include <AP_ExternalAHRS/AP_ExternalAHRS.h>13#include <AP_Vehicle/AP_Vehicle.h>1415void setup();16void loop();1718const AP_HAL::HAL& hal = AP_HAL::get_HAL();192021static AP_SerialManager serial_manager;2223class DummyVehicle : public AP_Vehicle {24public:25AP_AHRS ahrs{AP_AHRS::FLAG_ALWAYS_USE_EKF};26bool set_mode(const uint8_t new_mode, const ModeReason reason) override { return true; };27uint8_t get_mode() const override { return 1; };28void get_scheduler_tasks(const AP_Scheduler::Task *&tasks, uint8_t &task_count, uint32_t &log_bit) override {};29void init_ardupilot() override {};30void load_parameters() override {};31void init() {32BoardConfig.init();33ins.init(100);34ahrs.init();35}36AP_Int32 unused_log_bitmask;37struct LogStructure log_structure[1] = {38};39const AP_Int32 &get_log_bitmask() override { return unused_log_bitmask; }4041const struct LogStructure *get_log_structures() const override {42return log_structure;43}44uint8_t get_num_log_structures() const override {45return 0;46}47};4849static DummyVehicle vehicle;5051// choose which AHRS system to use52// AP_AHRS_DCM ahrs = AP_AHRS_DCM::create(barometer, gps);53auto &ahrs = vehicle.ahrs;5455void setup(void)56{57vehicle.init();58serial_manager.init();59AP::compass().init();60if (!AP::compass().read()) {61hal.console->printf("No compass detected\n");62}63AP::gps().init();64}6566void loop(void)67{68static uint16_t counter;69static uint32_t last_t, last_print, last_compass;70uint32_t now = AP_HAL::micros();71float heading = 0;7273if (last_t == 0) {74last_t = now;75return;76}77last_t = now;7879if (now - last_compass > 100 * 1000UL &&80AP::compass().read()) {81heading = AP::compass().calculate_heading(ahrs.get_rotation_body_to_ned());82// read compass at 10Hz83last_compass = now;84}8586ahrs.update();87counter++;8889if (now - last_print >= 100000 /* 100ms : 10hz */) {90Vector3f drift = ahrs.get_gyro_drift();91hal.console->printf(92"r:%4.1f p:%4.1f y:%4.1f "93"drift=(%5.1f %5.1f %5.1f) hdg=%.1f rate=%.1f\n",94(double)ToDeg(ahrs.get_roll()),95(double)ToDeg(ahrs.get_pitch()),96(double)ToDeg(ahrs.get_yaw()),97(double)ToDeg(drift.x),98(double)ToDeg(drift.y),99(double)ToDeg(drift.z),100(double)(AP::compass().use_for_yaw() ? ToDeg(heading) : 0.0f),101(double)((1.0e6f * counter) / (now-last_print)));102last_print = now;103counter = 0;104}105}106107const struct AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {108AP_GROUPEND109};110GCS_Dummy _gcs;111112AP_HAL_MAIN();113114115