ardupilot/ArduPlane/sensors.pde

76 lines
1.7 KiB
Plaintext
Raw Normal View History

// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
static void init_barometer(void)
{
gcs_send_text_P(SEVERITY_LOW, PSTR("Calibrating barometer"));
2012-12-04 18:22:21 -04:00
barometer.calibrate();
gcs_send_text_P(SEVERITY_LOW, PSTR("barometer calibration complete"));
}
static void init_rangefinder(void)
{
rangefinder.init();
}
/*
read the rangefinder and update height estimate
*/
static void read_rangefinder(void)
{
rangefinder.update();
if (should_log(MASK_LOG_SONAR))
Log_Write_Sonar();
rangefinder_height_update();
}
2013-08-28 09:37:07 -03:00
/*
ask airspeed sensor for a new value
*/
static void read_airspeed(void)
{
if (airspeed.enabled()) {
airspeed.read();
if (should_log(MASK_LOG_IMU)) {
Log_Write_Airspeed();
}
calc_airspeed_errors();
}
}
static void zero_airspeed(void)
{
2012-12-04 18:22:21 -04:00
airspeed.calibrate();
gcs_send_text_P(SEVERITY_LOW,PSTR("zero airspeed calibrated"));
}
2013-09-29 09:54:39 -03:00
// read_battery - reads battery voltage and current and invokes failsafe
// should be called at 10hz
static void read_battery(void)
{
2013-09-29 09:54:39 -03:00
battery.read();
compass.set_current(battery.current_amps());
2012-08-16 21:50:15 -03:00
if (!usb_connected && battery.exhausted(g.fs_batt_voltage, g.fs_batt_mah)) {
low_battery_event();
}
}
// read the receiver RSSI as an 8 bit number for MAVLink
// RC_CHANNELS_SCALED message
void read_receiver_rssi(void)
{
2014-01-29 20:29:35 -04:00
// avoid divide by zero
if (g.rssi_range <= 0) {
receiver_rssi = 0;
}else{
rssi_analog_source->set_pin(g.rssi_pin);
float ret = rssi_analog_source->voltage_average() * 255 / g.rssi_range;
receiver_rssi = constrain_int16(ret, 0, 255);
}
}