Skip to content

Commit

Permalink
fix(a380x/air cond): wasm crash during rapid decompression (flybywire…
Browse files Browse the repository at this point in the history
…sim#9543)

* fix: wasm crash during decompression

* docs: changelog

* fix: comments in update_ambient_conditions in cpiom_b
  • Loading branch information
mjuhe authored Nov 24, 2024
1 parent a526ab6 commit ebb7cca
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
1. [A32NX] Fixed appearance of FCU decals on MSFS2024 - @tracernz (Mike)
1. [FMS] Fixed issue with airport loading timing out on MSFS2024 - @tracernz (Mike)
1. [A32NX] Fixed APU fire detection - @tracernz (Mike)
1. [A380X/COND] Fix wasm crash during rapid decompression - @mjuhe (Miquel Juhe)

## 0.12.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,11 @@ impl<C: PressurizationConstants> CabinPressureControlSystemApplication<C> {
&& (altimeter_setting.unwrap_or_default().get::<hectopascal>() - Air::P_0).abs()
> f64::EPSILON)
{
altimeter_setting.unwrap()
if altimeter_setting.unwrap() == Pressure::default() {
Pressure::new::<hectopascal>(Air::P_0)
} else {
altimeter_setting.unwrap()
}
} else {
Pressure::new::<hectopascal>(Air::P_0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<const ENGINES: usize> PackFlowController<ENGINES> {

if self.should_open_fcv {
self.pid
.change_setpoint(pack_flow_demand.get::<kilogram_per_second>());
.change_setpoint(pack_flow_demand.get::<kilogram_per_second>().max(0.));
self.pid.next_control_output(
self.pack_flow.get::<kilogram_per_second>(),
Some(context.delta()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub(super) struct A380AirConditioningSystem {
}

impl A380AirConditioningSystem {
const CAB_FAN_DESIGN_FLOW_RATE_L_S: f64 = 550.; // litres/sec
const CAB_FAN_DESIGN_FLOW_RATE_L_S: f64 = 1250.; // litres/sec

fn new(context: &mut InitContext, cabin_zones: &[ZoneType; 18]) -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ impl ZoneController {
pressurization: &impl CabinAltitude,
zone_measured_temperature: ThermodynamicTemperature,
) -> ThermodynamicTemperature {
let altitude_correction: f64 =
pressurization.altitude().get::<foot>() * Self::K_ALTITUDE_CORRECTION_DEG_PER_FEET;
let altitude_correction: f64 = pressurization.altitude().get::<foot>().max(0.)
* Self::K_ALTITUDE_CORRECTION_DEG_PER_FEET;
let corrected_selected_temp: f64 =
self.zone_selected_temperature.get::<kelvin>() + altitude_correction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
ControllablePneumaticValve, PneumaticContainer, PneumaticPipe, PneumaticValveSignal,
},
shared::{
arinc429::Arinc429Word, low_pass_filter::LowPassFilter, AverageExt, CabinSimulation,
arinc429::Arinc429Word, low_pass_filter::LowPassFilter, AverageExt, CabinSimulation, Clamp,
ConsumePower, ControllerSignal, ElectricalBusType, ElectricalBuses,
},
simulation::{
Expand Down Expand Up @@ -534,10 +534,15 @@ impl CabinFan {
let mass_flow: f64 = (self.outlet_air.pressure().get::<pascal>()
* self.design_flow_rate.get::<cubic_meter_per_second>())
/ (Air::R * self.outlet_air.temperature().get::<kelvin>());
let max_mass_flow = mass_flow * Self::FAN_EFFICIENCY;
// If we have flow demand calculated, we assign this directly to the fan flow
// This is a simplification, we could model the fans, send the signal and read the output
recirculation_flow_demand
.unwrap_or(MassRate::new::<kilogram_per_second>(mass_flow) * Self::FAN_EFFICIENCY)
.unwrap_or(MassRate::new::<kilogram_per_second>(max_mass_flow))
.clamp(
MassRate::default(),
MassRate::new::<kilogram_per_second>(max_mass_flow),
)
}

pub fn has_fault(&self) -> bool {
Expand Down

0 comments on commit ebb7cca

Please sign in to comment.