mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-04 23:18:28 -04:00
51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
/*
|
|
* AP_Compass_HIL.cpp - Arduino Library for HIL model of HMC5843 I2C Magnetometer
|
|
* Code by James Goppert. DIYDrones.com
|
|
*
|
|
* This library is free software; you can redistribute it and / or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*/
|
|
|
|
|
|
#include <AP_HAL.h>
|
|
#include "AP_Compass_HIL.h"
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
// Public Methods //////////////////////////////////////////////////////////////
|
|
|
|
bool AP_Compass_HIL::read()
|
|
{
|
|
// get offsets
|
|
Vector3f ofs = _offset.get();
|
|
|
|
// get motor compensation
|
|
_motor_offset = _motor_compensation.get() * _throttle_pct;
|
|
|
|
// return last values provided by setHIL function
|
|
mag_x = _hil_mag.x + ofs.x + _motor_offset.x;
|
|
mag_y = _hil_mag.y + ofs.y + _motor_offset.y;
|
|
mag_z = _hil_mag.z + ofs.z + _motor_offset.z;
|
|
|
|
// values set by setHIL function
|
|
last_update = hal.scheduler->micros(); // record time of update
|
|
return true;
|
|
}
|
|
|
|
// Update raw magnetometer values from HIL data
|
|
//
|
|
void AP_Compass_HIL::setHIL(float _mag_x, float _mag_y, float _mag_z)
|
|
{
|
|
_hil_mag.x = _mag_x;
|
|
_hil_mag.y = _mag_y;
|
|
_hil_mag.z = _mag_z;
|
|
healthy = true;
|
|
}
|
|
|
|
void AP_Compass_HIL::accumulate(void)
|
|
{
|
|
// nothing to do
|
|
}
|