2010-11-27 00:41:25 -04:00
|
|
|
#include "AP_ADC_HIL.h"
|
2010-11-27 20:28:01 -04:00
|
|
|
#include "WProgram.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
AP_ADC_HIL.cpp
|
|
|
|
Author: James Goppert
|
|
|
|
|
|
|
|
License:
|
|
|
|
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.
|
|
|
|
*/
|
2010-11-27 00:41:25 -04:00
|
|
|
|
2011-07-30 17:33:45 -03:00
|
|
|
const uint8_t AP_ADC_HIL::sensors[6] = {1,2,0,4,5,6};
|
2010-11-27 20:28:01 -04:00
|
|
|
const int8_t AP_ADC_HIL::sensorSign[6] = { 1, -1, -1,-1, 1, 1};
|
|
|
|
const float AP_ADC_HIL::gyroBias[3] = {1665,1665,1665};
|
|
|
|
const float AP_ADC_HIL::accelBias[3] = {2025,2025,2025};
|
|
|
|
// gyroScale = 1/[GyroGain*pi/180] GyroGains (0.4,0.41,0.41)
|
2011-07-30 17:33:45 -03:00
|
|
|
const float AP_ADC_HIL::gyroScale[3] = {143.239, 139.746, 139.746};
|
2010-11-27 20:28:01 -04:00
|
|
|
const float AP_ADC_HIL::accelScale[3] = {418,418,418}; // adcPerG
|
|
|
|
|
2010-11-27 21:58:53 -04:00
|
|
|
AP_ADC_HIL::AP_ADC_HIL()
|
2010-11-27 00:41:25 -04:00
|
|
|
{
|
2010-11-27 21:58:53 -04:00
|
|
|
// gyros set to zero for calibration
|
|
|
|
setGyro(0,0);
|
|
|
|
setGyro(1,0);
|
|
|
|
setGyro(2,0);
|
|
|
|
|
|
|
|
// accels set to zero for calibration
|
|
|
|
setAccel(0,0);
|
|
|
|
setAccel(1,0);
|
|
|
|
setAccel(2,0);
|
|
|
|
|
|
|
|
// set diff press and temp to zero
|
|
|
|
setGyroTemp(0);
|
|
|
|
setPressure(0);
|
2011-09-15 00:01:45 -03:00
|
|
|
|
|
|
|
last_hil_time = millis();
|
2010-11-27 00:41:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AP_ADC_HIL::Init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read one channel value
|
2011-09-15 00:01:45 -03:00
|
|
|
uint16_t AP_ADC_HIL::Ch(unsigned char ch_num)
|
2011-07-30 17:33:45 -03:00
|
|
|
{
|
2011-09-15 00:01:45 -03:00
|
|
|
return adcValue[ch_num];
|
2011-09-15 05:45:51 -03:00
|
|
|
}
|
2011-09-15 00:01:45 -03:00
|
|
|
|
|
|
|
// Read 6 channel values
|
2011-09-15 05:45:51 -03:00
|
|
|
uint32_t AP_ADC_HIL::Ch6(const uint8_t *channel_numbers, uint16_t *result)
|
|
|
|
{
|
2011-09-15 00:01:45 -03:00
|
|
|
for (uint8_t i=0; i<6; i++) {
|
|
|
|
result[i] = Ch(channel_numbers[i]);
|
|
|
|
}
|
|
|
|
return ((millis() - last_hil_time)*2)/5;
|
2010-11-27 00:41:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set one channel value
|
2011-05-04 16:12:27 -03:00
|
|
|
void AP_ADC_HIL::setHIL(int16_t p, int16_t q, int16_t r, int16_t gyroTemp,
|
2010-11-27 00:41:25 -04:00
|
|
|
int16_t aX, int16_t aY, int16_t aZ, int16_t diffPress)
|
|
|
|
{
|
|
|
|
// gyros
|
2010-11-27 20:28:01 -04:00
|
|
|
setGyro(0,p);
|
|
|
|
setGyro(1,q);
|
|
|
|
setGyro(2,r);
|
2010-11-27 00:41:25 -04:00
|
|
|
|
2010-11-27 20:28:01 -04:00
|
|
|
// temp
|
|
|
|
setGyroTemp(gyroTemp);
|
2010-11-27 00:41:25 -04:00
|
|
|
|
2010-11-27 20:28:01 -04:00
|
|
|
// accel
|
|
|
|
setAccel(0,aX);
|
2010-11-27 21:58:53 -04:00
|
|
|
setAccel(1,aY);
|
|
|
|
setAccel(2,aZ);
|
2010-11-27 00:41:25 -04:00
|
|
|
|
|
|
|
// differential pressure
|
2010-11-27 20:28:01 -04:00
|
|
|
setPressure(diffPress);
|
2010-11-27 00:41:25 -04:00
|
|
|
}
|