Skip to content

Commit

Permalink
Fix the hack with a hack
Browse files Browse the repository at this point in the history
  • Loading branch information
crocket63 authored and aguther committed Mar 28, 2024
1 parent 4721b8a commit bbbefac
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/reversers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Error>> {
// 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.,
Expand Down
27 changes: 20 additions & 7 deletions fbw-common/src/wasm/systems/systems/src/engine/reverser_thrust.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
}
Expand All @@ -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(),
}
}
Expand All @@ -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::<kilogram>() > 0. {
-total_force / context.total_weight()
} else {
Acceleration::default()
};
self.plane_delta_acceleration_due_to_reverse_thrust =
if context.total_weight().get::<kilogram>() > 0. {
-total_force / context.total_weight()
} else {
Acceleration::default()
};

self.plane_delta_speed_due_to_reverse_thrust = Velocity::new::<meter_per_second>(
acceleration.get::<meter_per_second_squared>() * context.delta_as_secs_f64(),
self.plane_delta_acceleration_due_to_reverse_thrust
.get::<meter_per_second_squared>()
* context.delta_as_secs_f64(),
);

let total_dissimetry =
Expand Down Expand Up @@ -138,5 +145,11 @@ impl SimulationElement for ReverserForce {
self.dissimetry_acceleration
.get::<radian_per_second_squared>(),
);

writer.write(
&self.reverser_delta_accel_id,
self.plane_delta_acceleration_due_to_reverse_thrust
.get::<foot_per_second_squared>(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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()),
Expand Down

0 comments on commit bbbefac

Please sign in to comment.