@@ -842,56 +842,10 @@ float AirspeedModule::get_synthetic_airspeed(float throttle)
842842
843843void AirspeedModule::update_throttle_filter (hrt_abstime now)
844844{
845- if (_vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING) {
845+ if (_vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING
846+ && _time_now_usec - _tecs_status.timestamp < 20_ms) {
846847
847- float throttle_sp;
848-
849- // We have two options for getting the throttle value:
850- // - tecs_status.throttle_sp
851- // - higher level, without battery scaling
852- // - only available in fixed wing
853- // - vehicle_thrust_setpoint_0
854- // - lower level, with battery scaling
855- // - available also in transitions
856-
857- // The filtered throttle value is used for both synthetic
858- // airspeed estimation and airspeed failure detection.
859-
860- // For failure detection, we must to use the TECS throttle
861- // setpoint to correctly compare against the TECS trim throttle.
862-
863- // For synthetic airspeed, the TECS setpoint is also
864- // preferred, because it more closely matches what the vehicle
865- // does -- when the battery depletes and we command higher
866- // thrust to compensate for it the vehicle does not
867- // accelerate.
868-
869- // However, to ensure horizontal aiding during VTOL transitions
870- // (preventing optical flow failsafes), we fall back to the raw
871- // vehicle_thrust_setpoint when TECS is not active.
872-
873- if (_time_now_usec - _tecs_status.timestamp < 20_ms) {
874-
875- throttle_sp = _tecs_status.throttle_sp ;
876-
877- } else {
878-
879- vehicle_thrust_setpoint_s vehicle_thrust_setpoint_0{};
880- _vehicle_thrust_setpoint_0_sub.copy (&vehicle_thrust_setpoint_0);
881-
882- throttle_sp = vehicle_thrust_setpoint_0.xyz [0 ];
883-
884- if (_vehicle_status.is_vtol ) {
885- // Use the total thrust vector length (otherwise
886- // needs special handling for tailsitters and
887- // tiltrotors)
888- throttle_sp = sqrtf (vehicle_thrust_setpoint_0.xyz [0 ] * vehicle_thrust_setpoint_0.xyz [0 ] +
889- vehicle_thrust_setpoint_0.xyz [1 ] * vehicle_thrust_setpoint_0.xyz [1 ] +
890- vehicle_thrust_setpoint_0.xyz [2 ] * vehicle_thrust_setpoint_0.xyz [2 ]);
891-
892- }
893-
894- }
848+ const float throttle_sp = _tecs_status.throttle_sp ;
895849
896850 const float dt = static_cast <float >(now - _t_last_throttle_fw) * 1e-6f ;
897851 _t_last_throttle_fw = now;
@@ -902,6 +856,15 @@ void AirspeedModule::update_throttle_filter(hrt_abstime now)
902856 } else {
903857 _throttle_sp_filtered.update (throttle_sp, dt);
904858 }
859+
860+ } else {
861+
862+ // If we are not in fixed wing or no recent TECS sample exists
863+ // (e.g. in transitions), get_synthetic_airspeed might still be
864+ // called. Regardless of the flight phase estimation it will ALWAYS
865+ // give trim airspeed if we reset the filter to trim throttle here.
866+
867+ _throttle_sp_filtered.update (_param_fw_thr_trim.get ());
905868 }
906869}
907870
0 commit comments