diff --git a/libraries/SITL/SIM_Aircraft.h b/libraries/SITL/SIM_Aircraft.h index 7d14528d9b..11a4c5f17b 100644 --- a/libraries/SITL/SIM_Aircraft.h +++ b/libraries/SITL/SIM_Aircraft.h @@ -174,7 +174,7 @@ protected: const float FEET_TO_METERS = 0.3048f; const float KNOTS_TO_METERS_PER_SECOND = 0.51444f; - bool on_ground() const; + virtual bool on_ground() const; // returns height above ground level in metres float hagl() const; // metres diff --git a/libraries/SITL/SIM_Submarine.cpp b/libraries/SITL/SIM_Submarine.cpp index 740972c14a..1611e5e302 100644 --- a/libraries/SITL/SIM_Submarine.cpp +++ b/libraries/SITL/SIM_Submarine.cpp @@ -20,6 +20,8 @@ #include #include "Frame_Vectored.h" +#include + using namespace SITL; static Thruster vectored_thrusters[] = @@ -37,7 +39,7 @@ Submarine::Submarine(const char *home_str, const char *frame_str) : Aircraft(home_str, frame_str), frame(NULL) { - frame_height = 0.1; + frame_height = 0.0; ground_behavior = GROUND_BEHAVIOR_NONE; } @@ -45,19 +47,34 @@ Submarine::Submarine(const char *home_str, const char *frame_str) : void Submarine::calculate_forces(const struct sitl_input &input, Vector3f &rot_accel, Vector3f &body_accel) { rot_accel = Vector3f(0,0,0); - body_accel = Vector3f(0,0,0); + + // slight positive buoyancy + body_accel = Vector3f(0,0,-GRAVITY_MSS * 1.1); + for (int i = 0; i < 6; i++) { Thruster t = vectored_thrusters[i]; int16_t pwm = input.servos[t.servo]; float output = 0; if (pwm < 2000 && pwm > 1000) { - output = (pwm - 1500) / 400.0f; // range -1~1 + output = (pwm - 1500) / 400.0; // range -1~1 } - body_accel += t.linear * output * 1.2 * GRAVITY_MSS; + // 2.5 scalar for approximate real-life performance of T200 thruster + body_accel += t.linear * output * 2.5; + rot_accel += t.rotational * output; } + // Limit movement at the surface of the water + if (position.z < 0 && body_accel.z < 0) { + body_accel.z = GRAVITY_MSS; + } + + // Limit movement at the sea floor + if (position.z > 100 && body_accel.z > -GRAVITY_MSS) { + body_accel.z = -GRAVITY_MSS; + } + float terminal_rotation_rate = 10.0; if (terminal_rotation_rate > 0) { // rotational air resistance @@ -94,3 +111,11 @@ void Submarine::update(const struct sitl_input &input) // update magnetic field update_mag_field_bf(); } + +/* + return true if we are on the ground +*/ +bool Submarine::on_ground() const +{ + return false; +} diff --git a/libraries/SITL/SIM_Submarine.h b/libraries/SITL/SIM_Submarine.h index 49549035a1..f470076be0 100644 --- a/libraries/SITL/SIM_Submarine.h +++ b/libraries/SITL/SIM_Submarine.h @@ -41,7 +41,11 @@ public: return new Submarine(home_str, frame_str); } + protected: + + bool on_ground() const override; + // calculate rotational and linear accelerations void calculate_forces(const struct sitl_input &input, Vector3f &rot_accel, Vector3f &body_accel); Frame *frame;