2012-04-30 04:17:14 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2012-05-14 12:47:08 -03:00
|
|
|
#if CONFIG_SONAR == ENABLED
|
|
|
|
static void init_sonar(void)
|
|
|
|
{
|
2012-06-13 03:29:32 -03:00
|
|
|
/*
|
2012-05-14 12:47:08 -03:00
|
|
|
#if CONFIG_SONAR_SOURCE == SONAR_SOURCE_ADC
|
|
|
|
sonar.calculate_scaler(g.sonar_type, 3.3);
|
|
|
|
#else
|
|
|
|
sonar.calculate_scaler(g.sonar_type, 5.0);
|
|
|
|
#endif
|
2012-06-13 03:29:32 -03:00
|
|
|
*/
|
2012-05-14 12:47:08 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-13 03:29:32 -03:00
|
|
|
#if LITE == DISABLED
|
|
|
|
// Sensors are not available in HIL_MODE_ATTITUDE
|
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
|
|
|
|
|
|
|
void ReadSCP1000(void) {}
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
#endif // HIL_MODE != HIL_MODE_ATTITUDE
|
2012-05-09 02:12:26 -03:00
|
|
|
#endif
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
static void read_battery(void)
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
2012-04-30 04:17:14 -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-04-30 04:17:14 -03:00
|
|
|
current_total1 += current_amps1 * (float)delta_ms_medium_loop * 0.0002778; // .0002778 is 1/3600 (conversion to hours)
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BATTERY_EVENT == ENABLED
|
|
|
|
if(battery_voltage1 < LOW_VOLTAGE) low_battery_event();
|
|
|
|
if(g.battery_monitoring == 4 && current_total1 > g.pack_capacity) low_battery_event();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|