Skip to content

Commit

Permalink
feat: introduce a380_systems and a380_systems_wasm projects (flybywir…
Browse files Browse the repository at this point in the history
…esim#7482)

* chore: formatting

* cargo fmt

* don't borrow ref that is immediately dereferenced

* remove file added by accident

Co-authored-by: David Walschots <[email protected]>
Co-authored-by: crocket63 <[email protected]>
Co-authored-by: Miquel Juhe <[email protected]>
Co-authored-by: Andreas Guther <[email protected]>
Co-authored-by: BBK <[email protected]>
Co-authored-by: lukecologne <[email protected]>
Co-authored-by: Pascal Störzbach <[email protected]>
Co-authored-by: Michael Corcoran <[email protected]>
Co-authored-by: Benedict Etzel <[email protected]>
Co-authored-by: Johan Bouveng <[email protected]>
Co-authored-by: Tyler Knox <[email protected]>
Co-authored-by: omrygin <[email protected]>
Co-authored-by: Shaye Garg <[email protected]>
Co-authored-by: Erick Torres <[email protected]>
  • Loading branch information
15 people authored Sep 17, 2022
1 parent 9a216df commit 8e287a1
Show file tree
Hide file tree
Showing 28 changed files with 21,819 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
members = [
"src/systems/a320_systems",
"src/systems/a320_systems_wasm",
"src/systems/a380_systems",
"src/systems/a380_systems_wasm",
"src/systems/systems",
"src/systems/systems_wasm",
"src/systems/a320_hydraulic_simulation_graphs",
Expand Down
2 changes: 1 addition & 1 deletion igniter.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default new TaskOfTasks('a32nx', [
new ExecTask('model','node src/model/build.js', ['src/model', 'flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/model']),
new ExecTask('fmgc','npm run build:fmgc', ['src/fmgc', 'flybywire-aircraft-a320-neo/html_ui/JS/fmgc']),
new ExecTask('systems', [
'cargo build --target wasm32-wasi --release',
'cargo build -p a320_systems_wasm --target wasm32-wasi --release',
'wasm-opt -O3 -o flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/systems.wasm target/wasm32-wasi/release/a320_systems_wasm.wasm',
], ['src/systems', 'Cargo.lock', 'Cargo.toml', 'flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/systems.wasm']),
new ExecTask('systems-autopilot', [
Expand Down
15 changes: 15 additions & 0 deletions src/systems/a380_systems/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "a380_systems"
version = "0.1.0"
authors = ["FlyByWire Simulations"]
edition = "2018"

[dependencies]
uom = "0.33.0"
rand = "0.8.0"
nalgebra = "0.25.0"
ntest = "0.7.2"
systems = { path = "../systems" }

[dev-dependencies]
rstest = "0.10.0"
157 changes: 157 additions & 0 deletions src/systems/a380_systems/src/air_conditioning.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
use systems::{
accept_iterable,
air_conditioning::{
acs_controller::{Pack, PackFlowController},
cabin_air::CabinZone,
AirConditioningSystem, DuctTemperature, PackFlow, PackFlowControllers, ZoneType,
},
pressurization::PressurizationOverheadPanel,
shared::{
Cabin, ElectricalBusType, EngineBleedPushbutton, EngineCorrectedN1, EngineFirePushButtons,
EngineStartState, GroundSpeed, LgciuWeightOnWheels, PackFlowValveState, PneumaticBleed,
},
simulation::{InitContext, SimulationElement, SimulationElementVisitor, UpdateContext},
};
use uom::si::{f64::*, mass_rate::kilogram_per_second, volume::cubic_meter};

pub(super) struct A380AirConditioning {
a380_cabin: A380Cabin,
a380_air_conditioning_system: AirConditioningSystem<3>,
}

impl A380AirConditioning {
pub fn new(context: &mut InitContext) -> Self {
let cabin_zones: [ZoneType; 3] =
[ZoneType::Cockpit, ZoneType::Cabin(1), ZoneType::Cabin(2)];

Self {
a380_cabin: A380Cabin::new(context),
a380_air_conditioning_system: AirConditioningSystem::new(
context,
cabin_zones,
vec![
ElectricalBusType::DirectCurrent(1),
ElectricalBusType::AlternatingCurrent(1),
],
vec![
ElectricalBusType::DirectCurrent(2),
ElectricalBusType::AlternatingCurrent(2),
],
),
}
}

pub fn update(
&mut self,
context: &UpdateContext,
adirs: &impl GroundSpeed,
engines: [&impl EngineCorrectedN1; 2],
engine_fire_push_buttons: &impl EngineFirePushButtons,
pneumatic: &(impl EngineStartState + PackFlowValveState + PneumaticBleed),
pneumatic_overhead: &impl EngineBleedPushbutton,
pressurization: &impl Cabin,
pressurization_overhead: &PressurizationOverheadPanel,
lgciu: [&impl LgciuWeightOnWheels; 2],
) {
self.a380_air_conditioning_system.update(
context,
adirs,
engines,
engine_fire_push_buttons,
pneumatic,
pneumatic_overhead,
pressurization,
pressurization_overhead,
lgciu,
);
self.a380_cabin.update(
context,
&self.a380_air_conditioning_system,
&self.a380_air_conditioning_system,
pressurization,
);
}
}

impl PackFlowControllers<3> for A380AirConditioning {
fn pack_flow_controller(&self, pack_id: Pack) -> PackFlowController<3> {
self.a380_air_conditioning_system
.pack_flow_controller(pack_id)
}
}

impl SimulationElement for A380AirConditioning {
fn accept<T: SimulationElementVisitor>(&mut self, visitor: &mut T) {
self.a380_cabin.accept(visitor);
self.a380_air_conditioning_system.accept(visitor);

visitor.visit(self);
}
}

struct A380Cabin {
cabin_zone: [CabinZone<2>; 3],
}

impl A380Cabin {
// TODO: Improve volume according to specs
const A380_CABIN_VOLUME_CUBIC_METER: f64 = 200.; // m3
const A380_COCKPIT_VOLUME_CUBIC_METER: f64 = 10.; // m3

fn new(context: &mut InitContext) -> Self {
Self {
cabin_zone: [
CabinZone::new(
context,
ZoneType::Cockpit,
Volume::new::<cubic_meter>(Self::A380_COCKPIT_VOLUME_CUBIC_METER),
2,
None,
),
CabinZone::new(
context,
ZoneType::Cabin(1),
Volume::new::<cubic_meter>(Self::A380_CABIN_VOLUME_CUBIC_METER / 2.),
0,
Some([(1, 6), (7, 13)]),
),
CabinZone::new(
context,
ZoneType::Cabin(2),
Volume::new::<cubic_meter>(Self::A380_CABIN_VOLUME_CUBIC_METER / 2.),
0,
Some([(14, 21), (22, 29)]),
),
],
}
}

fn update(
&mut self,
context: &UpdateContext,
duct_temperature: &impl DuctTemperature,
pack_flow: &impl PackFlow,
pressurization: &impl Cabin,
) {
let flow_rate_per_cubic_meter: MassRate = MassRate::new::<kilogram_per_second>(
pack_flow.pack_flow().get::<kilogram_per_second>()
/ (Self::A380_CABIN_VOLUME_CUBIC_METER + Self::A380_COCKPIT_VOLUME_CUBIC_METER),
);
for zone in self.cabin_zone.iter_mut() {
zone.update(
context,
duct_temperature,
flow_rate_per_cubic_meter,
pressurization,
);
}
}
}

impl SimulationElement for A380Cabin {
fn accept<T: SimulationElementVisitor>(&mut self, visitor: &mut T) {
accept_iterable!(self.cabin_zone, visitor);

visitor.visit(self);
}
}
Loading

0 comments on commit 8e287a1

Please sign in to comment.