2011-09-08 22:29:39 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
// Sensors are not available in HIL_MODE_ATTITUDE
|
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
|
|
|
|
|
|
|
void ReadSCP1000(void) {}
|
|
|
|
|
|
|
|
static void init_barometer(void)
|
|
|
|
{
|
2012-06-19 23:26:58 -03:00
|
|
|
barometer.calibrate(mavlink_delay);
|
|
|
|
ahrs.set_barometer(&barometer);
|
|
|
|
gcs_send_text_P(SEVERITY_LOW, PSTR("barometer calibration complete"));
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
2012-06-19 23:26:58 -03:00
|
|
|
// filter altitude from the barometer with a 0.3 low pass
|
|
|
|
// filter
|
|
|
|
static LowPassFilterInt32 altitude_filter(0.3);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-06-19 23:26:58 -03:00
|
|
|
// read the barometer and return the updated altitude in centimeters
|
|
|
|
// above the calibration altitude
|
|
|
|
static int32_t read_barometer(void)
|
|
|
|
{
|
|
|
|
barometer.read();
|
|
|
|
return altitude_filter.apply(((int32_t)barometer.get_altitude() * 100.0));
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// in M/S * 100
|
|
|
|
static void read_airspeed(void)
|
|
|
|
{
|
2012-07-15 22:21:50 -03:00
|
|
|
airspeed.read();
|
2011-09-08 22:29:39 -03:00
|
|
|
calc_airspeed_errors();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void zero_airspeed(void)
|
|
|
|
{
|
2012-07-15 22:21:50 -03:00
|
|
|
airspeed.calibrate(mavlink_delay);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HIL_MODE != HIL_MODE_ATTITUDE
|
|
|
|
|
|
|
|
static void read_battery(void)
|
|
|
|
{
|
2012-01-15 19:10:28 -04:00
|
|
|
if(g.battery_monitoring == 0) {
|
|
|
|
battery_voltage1 = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-29 08:51:05 -03:00
|
|
|
if(g.battery_monitoring == 3 || g.battery_monitoring == 4) {
|
|
|
|
static AP_AnalogSource_Arduino bat_pin(BATTERY_PIN_1);
|
|
|
|
battery_voltage1 = BATTERY_VOLTAGE(bat_pin.read_average());
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
if(g.battery_monitoring == 4) {
|
2012-06-29 08:51:05 -03:00
|
|
|
static AP_AnalogSource_Arduino current_pin(CURRENT_PIN_1);
|
|
|
|
current_amps1 = CURRENT_AMPS(current_pin.read_average());
|
2012-01-15 19:10:28 -04:00
|
|
|
current_total1 += current_amps1 * (float)delta_ms_medium_loop * 0.0002778; // .0002778 is 1/3600 (conversion to hours)
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#if BATTERY_EVENT == ENABLED
|
2012-01-15 19:10:28 -04:00
|
|
|
if(battery_voltage1 < LOW_VOLTAGE) low_battery_event();
|
|
|
|
if(g.battery_monitoring == 4 && current_total1 > g.pack_capacity) low_battery_event();
|
2011-09-08 22:29:39 -03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|