2012-03-03 00:49:38 -04:00
|
|
|
//
|
2012-03-11 05:00:39 -03:00
|
|
|
// Simple test for the AP_AHRS interface
|
2012-03-03 00:49:38 -04:00
|
|
|
//
|
|
|
|
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2015-10-20 10:37:24 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2016-10-04 05:07:21 -03:00
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.h>
|
2017-03-10 22:45:55 -04:00
|
|
|
#include <GCS_MAVLink/GCS_Dummy.h>
|
2019-05-01 13:56:48 -03:00
|
|
|
#include <AP_RangeFinder/AP_RangeFinder.h>
|
2019-05-07 00:47:32 -03:00
|
|
|
#include <AP_Logger/AP_Logger.h>
|
2019-06-14 00:15:53 -03:00
|
|
|
#include <AP_GPS/AP_GPS.h>
|
2019-06-26 23:37:09 -03:00
|
|
|
#include <AP_Baro/AP_Baro.h>
|
2021-02-09 10:09:51 -04:00
|
|
|
#include <AP_ExternalAHRS/AP_ExternalAHRS.h>
|
|
|
|
#include <AP_Vehicle/AP_Vehicle.h>
|
2012-12-18 06:27:50 -04:00
|
|
|
|
2017-04-13 08:29:38 -03:00
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2012-03-03 00:49:38 -04:00
|
|
|
|
2017-08-28 21:45:57 -03:00
|
|
|
|
2017-12-12 21:06:11 -04:00
|
|
|
static AP_SerialManager serial_manager;
|
2019-05-07 00:47:32 -03:00
|
|
|
AP_Int32 logger_bitmask;
|
|
|
|
static AP_Logger logger{logger_bitmask};
|
2012-03-23 02:27:37 -03:00
|
|
|
|
2021-02-09 10:09:51 -04:00
|
|
|
class DummyVehicle : public AP_Vehicle {
|
2016-11-30 04:59:11 -04:00
|
|
|
public:
|
2021-07-20 10:04:20 -03:00
|
|
|
AP_AHRS ahrs{AP_AHRS::FLAG_ALWAYS_USE_EKF};
|
2021-02-09 10:09:51 -04:00
|
|
|
bool set_mode(const uint8_t new_mode, const ModeReason reason) override { return true; };
|
|
|
|
uint8_t get_mode() const override { return 1; };
|
|
|
|
void get_scheduler_tasks(const AP_Scheduler::Task *&tasks, uint8_t &task_count, uint32_t &log_bit) override {};
|
|
|
|
void init_ardupilot() override {};
|
|
|
|
void load_parameters() override {};
|
|
|
|
void init() {
|
|
|
|
BoardConfig.init();
|
|
|
|
ins.init(100);
|
|
|
|
ahrs.init();
|
|
|
|
}
|
|
|
|
|
2016-11-30 04:59:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static DummyVehicle vehicle;
|
2012-03-03 00:49:38 -04:00
|
|
|
|
2016-11-30 04:59:11 -04:00
|
|
|
// choose which AHRS system to use
|
2018-03-11 04:21:02 -03:00
|
|
|
// AP_AHRS_DCM ahrs = AP_AHRS_DCM::create(barometer, gps);
|
2021-07-20 10:04:20 -03:00
|
|
|
auto &ahrs = vehicle.ahrs;
|
2012-03-03 00:49:38 -04:00
|
|
|
|
|
|
|
void setup(void)
|
|
|
|
{
|
2021-02-09 10:09:51 -04:00
|
|
|
vehicle.init();
|
2015-02-03 02:56:54 -04:00
|
|
|
serial_manager.init();
|
2021-02-09 10:09:51 -04:00
|
|
|
AP::compass().init();
|
2021-07-25 21:32:10 -03:00
|
|
|
if (!AP::compass().read()) {
|
2012-11-14 12:10:15 -04:00
|
|
|
hal.console->printf("No compass detected\n");
|
2012-08-17 02:40:30 -03:00
|
|
|
}
|
2021-02-09 10:09:51 -04:00
|
|
|
AP::gps().init(serial_manager);
|
2012-03-03 00:49:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop(void)
|
|
|
|
{
|
2012-08-17 02:40:30 -03:00
|
|
|
static uint16_t counter;
|
|
|
|
static uint32_t last_t, last_print, last_compass;
|
2015-11-19 23:06:43 -04:00
|
|
|
uint32_t now = AP_HAL::micros();
|
2012-08-17 02:40:30 -03:00
|
|
|
float heading = 0;
|
|
|
|
|
|
|
|
if (last_t == 0) {
|
|
|
|
last_t = now;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
last_t = now;
|
|
|
|
|
2017-04-13 08:29:38 -03:00
|
|
|
if (now - last_compass > 100 * 1000UL &&
|
2021-02-09 10:09:51 -04:00
|
|
|
AP::compass().read()) {
|
|
|
|
heading = AP::compass().calculate_heading(ahrs.get_rotation_body_to_ned());
|
2012-08-17 02:40:30 -03:00
|
|
|
// read compass at 10Hz
|
|
|
|
last_compass = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
ahrs.update();
|
|
|
|
counter++;
|
|
|
|
|
2012-11-14 12:10:15 -04:00
|
|
|
if (now - last_print >= 100000 /* 100ms : 10hz */) {
|
2012-08-17 02:40:30 -03:00
|
|
|
Vector3f drift = ahrs.get_gyro_drift();
|
2015-10-25 17:10:41 -03:00
|
|
|
hal.console->printf(
|
2015-10-24 18:45:41 -03:00
|
|
|
"r:%4.1f p:%4.1f y:%4.1f "
|
|
|
|
"drift=(%5.1f %5.1f %5.1f) hdg=%.1f rate=%.1f\n",
|
2024-01-12 08:40:22 -04:00
|
|
|
(double)ToDeg(ahrs.get_roll()),
|
|
|
|
(double)ToDeg(ahrs.get_pitch()),
|
|
|
|
(double)ToDeg(ahrs.get_yaw()),
|
2017-04-13 08:29:38 -03:00
|
|
|
(double)ToDeg(drift.x),
|
|
|
|
(double)ToDeg(drift.y),
|
|
|
|
(double)ToDeg(drift.z),
|
2021-02-09 10:09:51 -04:00
|
|
|
(double)(AP::compass().use_for_yaw() ? ToDeg(heading) : 0.0f),
|
2017-04-13 08:29:38 -03:00
|
|
|
(double)((1.0e6f * counter) / (now-last_print)));
|
2012-08-17 02:40:30 -03:00
|
|
|
last_print = now;
|
|
|
|
counter = 0;
|
|
|
|
}
|
2012-03-03 00:49:38 -04:00
|
|
|
}
|
2012-11-14 12:10:15 -04:00
|
|
|
|
2019-06-19 21:43:52 -03:00
|
|
|
const struct AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
|
2017-03-10 22:45:55 -04:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
GCS_Dummy _gcs;
|
2017-02-23 02:49:26 -04:00
|
|
|
|
2012-11-14 12:10:15 -04:00
|
|
|
AP_HAL_MAIN();
|