From e33d42e659b29c607b3c52e92adf6bb5cfe0872f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 13 Jan 2019 14:07:36 +1100 Subject: [PATCH] SITL: added simulated battery for quadplane needed for motor interference for mag --- libraries/SITL/SIM_Frame.cpp | 15 +++++++++++++++ libraries/SITL/SIM_Frame.h | 3 +++ libraries/SITL/SIM_Motor.cpp | 15 +++++++++++++++ libraries/SITL/SIM_Motor.h | 4 ++++ libraries/SITL/SIM_QuadPlane.cpp | 13 +++++++++++++ 5 files changed, 50 insertions(+) diff --git a/libraries/SITL/SIM_Frame.cpp b/libraries/SITL/SIM_Frame.cpp index 4034f3c7a5..607cb89420 100644 --- a/libraries/SITL/SIM_Frame.cpp +++ b/libraries/SITL/SIM_Frame.cpp @@ -243,3 +243,18 @@ void Frame::calculate_forces(const Aircraft &aircraft, aircraft.rand_normal(0, 1)) * accel_noise * noise_scale; } + +// calculate current and voltage +void Frame::current_and_voltage(const Aircraft::sitl_input &input, float &voltage, float ¤t) +{ + voltage = 0; + current = 0; + for (uint8_t i=0; icalculate_forces(*this, input, quad_rot_accel, quad_accel_body); + // estimate voltage and current + frame->current_and_voltage(input, battery_voltage, battery_current); + + float throttle; + if (reverse_thrust) { + throttle = filtered_servo_angle(input, 2); + } else { + throttle = filtered_servo_range(input, 2); + } + // assume 20A at full fwd throttle + throttle = fabsf(throttle); + battery_current += 20 * throttle; + rot_accel += quad_rot_accel; accel_body += quad_accel_body;