From c169bafa6fa02f2c93c56a08cbf5eb640c1a24ef Mon Sep 17 00:00:00 2001 From: Crocket63 Date: Mon, 25 Mar 2024 19:40:09 +0100 Subject: [PATCH] Fix the hack with a hack --- .github/CHANGELOG.md | 1 + .../a320_systems_wasm/src/reversers.rs | 13 ++++++++- .../systems/src/engine/reverser_thrust.rs | 27 ++++++++++++++----- .../systems/src/simulation/update_context.rs | 7 +++-- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 26b731253970..9ffee6253746 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -77,6 +77,7 @@ 1. [LIGHTS] Movement of landing lights now requires power and position is output into LVAR - @Maximilian-Reuter 1. [CDU] Fix auto weight and balance import on INIT B during GSX boarding not using the target values - @Maximilian-Reuter 1. [FAC] Improve sideslip estimation - @lukecologne (luke) +1. [MISC] Fixed wrong msfs plane acceleration during reverser use causing autobrake wrong brake inputs - @Crocket63 (crocket) 1. [ATHR/FADEC] Improved reverse thrust limit - @aguther (Andreas Guther) ## 0.11.0 diff --git a/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/reversers.rs b/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/reversers.rs index decfda0bf902..838031c63159 100644 --- a/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/reversers.rs +++ b/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/reversers.rs @@ -3,10 +3,21 @@ use std::error::Error; use msfs::sim_connect; use msfs::{sim_connect::SimConnect, sim_connect::SIMCONNECT_OBJECT_ID_USER}; -use systems_wasm::aspects::{MsfsAspectBuilder, ObjectWrite, VariablesToObject}; +use systems_wasm::aspects::{ExecuteOn, MsfsAspectBuilder, ObjectWrite, VariablesToObject}; use systems_wasm::{set_data_on_sim_object, Variable}; pub(super) fn reversers(builder: &mut MsfsAspectBuilder) -> Result<(), Box> { + // We recreate a long accel including the reverser accel that we pass to systems (else MSFS acceleration is not consistent with ingame acceleration when we modify plane velocity) + builder.map_many( + ExecuteOn::PreTick, + vec![ + Variable::aircraft("ACCELERATION BODY Z", "Feet per second squared", 0), + Variable::aspect("REVERSER_DELTA_ACCEL"), + ], + |values| values[0] + values[1], + Variable::aspect("ACCELERATION_BODY_Z_WITH_REVERSER"), + ); + builder.variables_to_object(Box::new(ReverserThrust { velocity_z: 0., angular_acc_y: 0., diff --git a/fbw-common/src/wasm/systems/systems/src/engine/reverser_thrust.rs b/fbw-common/src/wasm/systems/systems/src/engine/reverser_thrust.rs index 0b4717c99e3e..1431d95de615 100644 --- a/fbw-common/src/wasm/systems/systems/src/engine/reverser_thrust.rs +++ b/fbw-common/src/wasm/systems/systems/src/engine/reverser_thrust.rs @@ -1,5 +1,5 @@ use uom::si::{ - acceleration::meter_per_second_squared, + acceleration::{foot_per_second_squared, meter_per_second_squared}, angular_acceleration::radian_per_second_squared, f64::*, force::newton, @@ -65,10 +65,12 @@ impl ReverserThrust { pub struct ReverserForce { reverser_delta_speed_id: VariableIdentifier, reverser_angular_accel_id: VariableIdentifier, + reverser_delta_accel_id: VariableIdentifier, reversers: [ReverserThrust; 2], plane_delta_speed_due_to_reverse_thrust: Velocity, + plane_delta_acceleration_due_to_reverse_thrust: Acceleration, dissimetry_acceleration: AngularAcceleration, } @@ -80,9 +82,11 @@ impl ReverserForce { reverser_delta_speed_id: context.get_identifier("REVERSER_DELTA_SPEED".to_owned()), reverser_angular_accel_id: context .get_identifier("REVERSER_ANGULAR_ACCELERATION".to_owned()), + reverser_delta_accel_id: context.get_identifier("REVERSER_DELTA_ACCEL".to_owned()), reversers: [ReverserThrust::new(); 2], plane_delta_speed_due_to_reverse_thrust: Velocity::default(), + plane_delta_acceleration_due_to_reverse_thrust: Acceleration::default(), dissimetry_acceleration: AngularAcceleration::default(), } } @@ -99,14 +103,17 @@ impl ReverserForce { let total_force = self.reversers[0].current_thrust() + self.reversers[1].current_thrust(); - let acceleration = if context.total_weight().get::() > 0. { - -total_force / context.total_weight() - } else { - Acceleration::default() - }; + self.plane_delta_acceleration_due_to_reverse_thrust = + if context.total_weight().get::() > 0. { + -total_force / context.total_weight() + } else { + Acceleration::default() + }; self.plane_delta_speed_due_to_reverse_thrust = Velocity::new::( - acceleration.get::() * context.delta_as_secs_f64(), + self.plane_delta_acceleration_due_to_reverse_thrust + .get::() + * context.delta_as_secs_f64(), ); let total_dissimetry = @@ -138,5 +145,11 @@ impl SimulationElement for ReverserForce { self.dissimetry_acceleration .get::(), ); + + writer.write( + &self.reverser_delta_accel_id, + self.plane_delta_acceleration_due_to_reverse_thrust + .get::(), + ); } } diff --git a/fbw-common/src/wasm/systems/systems/src/simulation/update_context.rs b/fbw-common/src/wasm/systems/systems/src/simulation/update_context.rs index 68ef269ee7f9..3ef58b808464 100644 --- a/fbw-common/src/wasm/systems/systems/src/simulation/update_context.rs +++ b/fbw-common/src/wasm/systems/systems/src/simulation/update_context.rs @@ -290,7 +290,10 @@ impl UpdateContext { pub(crate) const VERTICAL_SPEED_KEY: &'static str = "VELOCITY WORLD Y"; pub(crate) const ACCEL_BODY_X_KEY: &'static str = "ACCELERATION BODY X"; pub(crate) const ACCEL_BODY_Y_KEY: &'static str = "ACCELERATION BODY Y"; - pub(crate) const ACCEL_BODY_Z_KEY: &'static str = "ACCELERATION BODY Z"; + + // Acceleration that includes the reverser acceleration added by our systems to msfs + pub(crate) const ACCEL_BODY_Z_KEY: &'static str = "ACCELERATION_BODY_Z_WITH_REVERSER"; + pub(crate) const WIND_VELOCITY_X_KEY: &'static str = "AMBIENT WIND X"; pub(crate) const WIND_VELOCITY_Y_KEY: &'static str = "AMBIENT WIND Y"; pub(crate) const WIND_VELOCITY_Z_KEY: &'static str = "AMBIENT WIND Z"; @@ -457,7 +460,7 @@ impl UpdateContext { local_vertical_speed_id: context.get_identifier("VELOCITY BODY Y".to_owned()), accel_body_x_id: context.get_identifier("ACCELERATION BODY X".to_owned()), accel_body_y_id: context.get_identifier("ACCELERATION BODY Y".to_owned()), - accel_body_z_id: context.get_identifier("ACCELERATION BODY Z".to_owned()), + accel_body_z_id: context.get_identifier("ACCELERATION_BODY_Z_WITH_REVERSER".to_owned()), wind_velocity_x_id: context.get_identifier("AMBIENT WIND X".to_owned()), wind_velocity_y_id: context.get_identifier("AMBIENT WIND Y".to_owned()), wind_velocity_z_id: context.get_identifier("AMBIENT WIND Z".to_owned()),