diff --git a/libraries/SITL/SIM_Sailboat.cpp b/libraries/SITL/SIM_Sailboat.cpp index 060a2fb183b85..cbd96e1607e7d 100644 --- a/libraries/SITL/SIM_Sailboat.cpp +++ b/libraries/SITL/SIM_Sailboat.cpp @@ -43,6 +43,7 @@ Sailboat::Sailboat(const char *frame_str) : steering_angle_max(35), turning_circle(1.8) { + motor_connected = (strcmp(frame_str, "sailboat-motor") == 0); } // calculate the lift and drag as values from 0 to 1 @@ -222,9 +223,9 @@ void Sailboat::update(const struct sitl_input &input) // throttle force (for motor sailing) // gives throttle force == hull drag at 10m/s float throttle_force = 0.0f; - uint16_t throttle_in = input.servos[THROTTLE_SERVO_CH]; - if (throttle_in > 900 && throttle_in < 2100) { - throttle_force = (throttle_in-1500) * 0.1f; + if (motor_connected) { + const uint16_t throttle_out = constrain_int16(input.servos[THROTTLE_SERVO_CH], 1000, 2000); + throttle_force = (throttle_out-1500) * 0.1f; } // accel in body frame due acceleration from sail and deceleration from hull friction diff --git a/libraries/SITL/SIM_Sailboat.h b/libraries/SITL/SIM_Sailboat.h index dd26862bc95c3..fc121cf8bc1e7 100644 --- a/libraries/SITL/SIM_Sailboat.h +++ b/libraries/SITL/SIM_Sailboat.h @@ -69,6 +69,7 @@ class Sailboat : public Aircraft { Vector3f wave_gyro; // rad/s float wave_heave; // m/s/s float wave_phase; // rads + bool motor_connected; // true if this frame has a motor }; } // namespace SITL