2011-09-18 00:49:00 -03:00
|
|
|
#ifndef AP_ADC_HIL_H
|
|
|
|
#define AP_ADC_HIL_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
AP_ADC_HIL.h
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include "AP_ADC.h"
|
|
|
|
|
|
|
|
///
|
|
|
|
// A hardware in the loop model of the ADS7844 analog to digital converter
|
|
|
|
// @author James Goppert DIYDrones.com
|
|
|
|
class AP_ADC_HIL : public AP_ADC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
///
|
|
|
|
// Constructor
|
|
|
|
AP_ADC_HIL(); // Constructor
|
|
|
|
|
|
|
|
///
|
|
|
|
// Initializes sensor, part of public AP_ADC interface
|
2011-11-12 23:12:53 -04:00
|
|
|
void Init(AP_PeriodicProcess*);
|
2011-09-18 00:49:00 -03:00
|
|
|
|
|
|
|
///
|
|
|
|
// Read the sensor, part of public AP_ADC interface
|
2011-12-10 06:43:57 -04:00
|
|
|
float Ch(unsigned char ch_num);
|
2011-09-15 00:01:45 -03:00
|
|
|
|
2011-09-15 05:45:51 -03:00
|
|
|
///
|
2011-09-15 00:01:45 -03:00
|
|
|
// Read 6 sensors at once
|
2011-09-15 05:45:51 -03:00
|
|
|
uint32_t Ch6(const uint8_t *channel_numbers, uint16_t *result);
|
|
|
|
|
2012-03-03 03:31:09 -04:00
|
|
|
// see if Ch6 would block
|
|
|
|
bool new_data_available(const uint8_t *channel_numbers);
|
|
|
|
|
2011-09-15 05:45:51 -03:00
|
|
|
///
|
|
|
|
// Set the adc raw values given the current rotations rates,
|
2011-09-18 00:49:00 -03:00
|
|
|
// temps, accels, and pressures
|
|
|
|
void setHIL(int16_t p, int16_t q, int16_t r, int16_t gyroTemp,
|
|
|
|
int16_t aX, int16_t aY, int16_t aZ, int16_t diffPress);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
///
|
|
|
|
// The raw adc array
|
|
|
|
uint16_t adcValue[8];
|
|
|
|
|
2011-09-15 00:01:45 -03:00
|
|
|
// the time in milliseconds when we last got a HIL update
|
|
|
|
uint32_t last_hil_time;
|
|
|
|
|
2011-09-18 00:49:00 -03:00
|
|
|
///
|
|
|
|
// sensor constants
|
|
|
|
// constants declared in cpp file
|
|
|
|
// @see AP_ADC_HIL.cpp
|
2011-09-15 00:01:45 -03:00
|
|
|
static const uint8_t sensors[6];
|
|
|
|
static const float gyroBias[3];
|
|
|
|
static const float gyroScale[3];
|
2011-09-18 00:49:00 -03:00
|
|
|
static const float accelBias[3];
|
2011-09-15 00:01:45 -03:00
|
|
|
static const float accelScale[3];
|
|
|
|
static const int8_t sensorSign[6];
|
2011-09-18 00:49:00 -03:00
|
|
|
|
|
|
|
///
|
|
|
|
// gyro set function
|
|
|
|
// @param val the value of the gyro in milli rad/s
|
|
|
|
// @param index the axis for the gyro(0-x,1-y,2-z)
|
|
|
|
inline void setGyro(uint8_t index, int16_t val) {
|
|
|
|
int16_t temp = val * gyroScale[index] / 1000 + gyroBias[index];
|
|
|
|
adcValue[sensors[index]] = (sensorSign[index] < 0) ? -temp : temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
// accel set function
|
|
|
|
// @param val the value of the accel in milli g's
|
|
|
|
// @param index the axis for the accelerometer(0-x,1-y,2-z)
|
|
|
|
inline void setAccel(uint8_t index, int16_t val) {
|
|
|
|
int16_t temp = val * accelScale[index] / 1000 + accelBias[index];
|
2012-01-11 03:41:01 -04:00
|
|
|
adcValue[sensors[index+3]] = (sensorSign[index+3] < 0) ? -temp : temp;
|
2011-09-18 00:49:00 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
// Sets the differential pressure adc channel
|
|
|
|
// TODO: implement
|
|
|
|
void setPressure(int16_t val) {}
|
|
|
|
|
|
|
|
///
|
|
|
|
// Sets the gyro temp adc channel
|
|
|
|
// TODO: implement
|
|
|
|
void setGyroTemp(int16_t val) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|