From 8dd55a85cdad228cad2c03ee1ca5f986344149f6 Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Wed, 7 Mar 2018 19:11:05 -0700 Subject: [PATCH] SITL: Create a second voltage to monitor for battery voltages --- libraries/AP_HAL_SITL/AnalogIn.cpp | 6 ++++++ libraries/AP_HAL_SITL/SITL_State.cpp | 3 +++ libraries/AP_HAL_SITL/SITL_State.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/libraries/AP_HAL_SITL/AnalogIn.cpp b/libraries/AP_HAL_SITL/AnalogIn.cpp index e02a94f96c..16c4479806 100644 --- a/libraries/AP_HAL_SITL/AnalogIn.cpp +++ b/libraries/AP_HAL_SITL/AnalogIn.cpp @@ -46,6 +46,12 @@ float ADCSource::read_latest() { case 13: return _sitlState->voltage_pin_value; + case 14: + return _sitlState->current2_pin_value; + + case 15: + return _sitlState->voltage2_pin_value; + case ANALOG_INPUT_NONE: default: return 0.0f; diff --git a/libraries/AP_HAL_SITL/SITL_State.cpp b/libraries/AP_HAL_SITL/SITL_State.cpp index e7890636e5..c537288040 100644 --- a/libraries/AP_HAL_SITL/SITL_State.cpp +++ b/libraries/AP_HAL_SITL/SITL_State.cpp @@ -464,6 +464,9 @@ void SITL_State::_simulator_servos(SITL::Aircraft::sitl_input &input) // assume 3DR power brick voltage_pin_value = ((voltage / 10.1f) / 5.0f) * 1024; current_pin_value = ((_current / 17.0f) / 5.0f) * 1024; + // fake battery2 as just a 25% gain on the first one + voltage2_pin_value = ((voltage * 0.25f / 10.1f) / 5.0f) * 1024; + current2_pin_value = ((_current * 0.25f / 17.0f) / 5.0f) * 1024; } void SITL_State::init(int argc, char * const argv[]) diff --git a/libraries/AP_HAL_SITL/SITL_State.h b/libraries/AP_HAL_SITL/SITL_State.h index fa21e32541..dde8e6b0a0 100644 --- a/libraries/AP_HAL_SITL/SITL_State.h +++ b/libraries/AP_HAL_SITL/SITL_State.h @@ -67,6 +67,8 @@ public: uint16_t airspeed_2_pin_value; // pin 2 uint16_t voltage_pin_value; // pin 13 uint16_t current_pin_value; // pin 12 + uint16_t voltage2_pin_value; // pin 15 + uint16_t current2_pin_value; // pin 14 // return TCP client address for uartC const char *get_client_address(void) const { return _client_address; }