Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hyd): faster core hydraulics solver #7635

Merged
merged 15 commits into from
Dec 30, 2022
Merged
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
1. [ADIRU] Implemented wind speed computation from TAS/GS/HDG - @tracernz (Mike)
1. [FMGC] Show proper transition names and final approach slope from AAU1 - @tracernz (Mike)
1. [FMGC] Don't accept blank input or / for hold distance - @tracernz (Mike)
1. [HYD] Faster core hydraulics solver - @Crocket63 (crocket)
1. [ATSU] Fix LSK6L not returning to ATSU DATALINK page in ATC MENU - @BravoMike99 (Bruno_pt99#5802)
1. [HYD] Trimmable physical assemblies - @Crocket63 (crocket)
1. [HYD] Simulation of the rudder mechanical assembly and yaw dampers - @Crocket63 (crocket)
Expand Down
188 changes: 79 additions & 109 deletions src/systems/a320_systems/src/hydraulic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ use systems::{
AutoOffFaultPushButton, AutoOnFaultPushButton, MomentaryOnPushButton, MomentaryPushButton,
},
shared::{
interpolation,
low_pass_filter::LowPassFilter,
random_from_normal_distribution, random_from_range,
update_iterator::{FixedStepLoop, MaxStepLoop},
AdirsDiscreteOutputs, DelayedFalseLogicGate, DelayedPulseTrueLogicGate,
DelayedTrueLogicGate, ElectricalBusType, ElectricalBuses, EmergencyElectricalRatPushButton,
EmergencyElectricalState, EmergencyGeneratorPower, EngineFirePushButtons, GearWheel,
HydraulicColor, HydraulicGeneratorControlUnit, LandingGearHandle, LgciuInterface,
LgciuWeightOnWheels, ReservoirAirPressure, SectionPressure, TrimmableHorizontalStabilizer,
interpolation, low_pass_filter::LowPassFilter, random_from_normal_distribution,
random_from_range, update_iterator::MaxStepLoop, AdirsDiscreteOutputs,
DelayedFalseLogicGate, DelayedPulseTrueLogicGate, DelayedTrueLogicGate, ElectricalBusType,
ElectricalBuses, EmergencyElectricalRatPushButton, EmergencyElectricalState,
EmergencyGeneratorPower, EngineFirePushButtons, GearWheel, HydraulicColor,
HydraulicGeneratorControlUnit, LandingGearHandle, LgciuInterface, LgciuWeightOnWheels,
ReservoirAirPressure, SectionPressure, TrimmableHorizontalStabilizer,
},
simulation::{
InitContext, Read, Reader, SimulationElement, SimulationElementVisitor, SimulatorReader,
Expand Down Expand Up @@ -1422,9 +1420,7 @@ pub(super) struct A320Hydraulic {

nose_steering: SteeringActuator,

core_hydraulic_updater: FixedStepLoop,
physics_updater: MaxStepLoop,
ultra_fast_physics_updater: MaxStepLoop,
core_hydraulic_updater: MaxStepLoop,

brake_steer_computer: A320HydraulicBrakeSteerComputerUnit,

Expand Down Expand Up @@ -1541,13 +1537,7 @@ impl A320Hydraulic {
ElectricalBusType::DirectCurrentHot(2);

// Refresh rate of core hydraulic simulation
const HYDRAULIC_SIM_TIME_STEP: Duration = Duration::from_millis(33);
// Refresh rate of max fixed step loop for fast physics
const HYDRAULIC_SIM_MAX_TIME_STEP_MILLISECONDS: Duration = Duration::from_millis(33);
// Refresh rate of max fixed step loop for fastest flight controls physics needing super stability
// and fast reacting time
const HYDRAULIC_SIM_FLIGHT_CONTROLS_MAX_TIME_STEP_MILLISECONDS: Duration =
Duration::from_millis(10);
const HYDRAULIC_SIM_TIME_STEP: Duration = Duration::from_millis(10);

pub(super) fn new(context: &mut InitContext) -> A320Hydraulic {
A320Hydraulic {
Expand All @@ -1563,11 +1553,7 @@ impl A320Hydraulic {
Ratio::new::<ratio>(0.18),
),

core_hydraulic_updater: FixedStepLoop::new(Self::HYDRAULIC_SIM_TIME_STEP),
physics_updater: MaxStepLoop::new(Self::HYDRAULIC_SIM_MAX_TIME_STEP_MILLISECONDS),
ultra_fast_physics_updater: MaxStepLoop::new(
Self::HYDRAULIC_SIM_FLIGHT_CONTROLS_MAX_TIME_STEP_MILLISECONDS,
),
core_hydraulic_updater: MaxStepLoop::new(Self::HYDRAULIC_SIM_TIME_STEP),

brake_steer_computer: A320HydraulicBrakeSteerComputerUnit::new(context),

Expand Down Expand Up @@ -1784,19 +1770,6 @@ impl A320Hydraulic {
adirs: &impl AdirsDiscreteOutputs,
) {
self.core_hydraulic_updater.update(context);
self.physics_updater.update(context);
self.ultra_fast_physics_updater.update(context);

for cur_time_step in self.physics_updater {
self.update_fast_physics(
&context.with_delta(cur_time_step),
rat_and_emer_gen_man_on,
emergency_elec,
lgcius.lgciu1(),
lgcius.lgciu2(),
adirs,
);
}

self.update_with_sim_rate(
context,
Expand All @@ -1810,11 +1783,15 @@ impl A320Hydraulic {
engine2,
);

for cur_time_step in self.ultra_fast_physics_updater {
self.update_ultra_fast_physics(&context.with_delta(cur_time_step), lgcius);
}

for cur_time_step in self.core_hydraulic_updater {
self.update_physics(
&context.with_delta(cur_time_step),
rat_and_emer_gen_man_on,
emergency_elec,
lgcius,
adirs,
);

self.update_core_hydraulics(
&context.with_delta(cur_time_step),
engine1,
Expand Down Expand Up @@ -1910,11 +1887,70 @@ impl A320Hydraulic {
self.yellow_circuit.system_section_pressure_switch() == PressureSwitchState::Pressurised
}

fn update_ultra_fast_physics(
// Updates at the same rate as the sim or at a fixed maximum time step if sim rate is too slow
fn update_physics(
&mut self,
context: &UpdateContext,
rat_and_emer_gen_man_on: &impl EmergencyElectricalRatPushButton,
emergency_elec: &(impl EmergencyElectricalState + EmergencyGeneratorPower),
lgcius: &LandingGearControlInterfaceUnitSet,
adirs: &impl AdirsDiscreteOutputs,
) {
self.forward_cargo_door.update(
context,
&self.forward_cargo_door_controller,
self.yellow_circuit.system_section(),
);

self.aft_cargo_door.update(
context,
&self.aft_cargo_door_controller,
self.yellow_circuit.system_section(),
);

self.ram_air_turbine.update_physics(
&context.delta(),
context.indicated_airspeed(),
self.blue_circuit.system_section(),
);

self.gcu.update(
context,
&self.emergency_gen,
self.blue_circuit.system_section(),
emergency_elec,
rat_and_emer_gen_man_on,
lgcius.lgciu1(),
);

self.emergency_gen.update(
context,
self.blue_circuit.system_section(),
&self.gcu,
emergency_elec,
);

self.gear_system_hydraulic_controller.update(
adirs,
lgcius.lgciu1(),
lgcius.lgciu2(),
&self.gear_system_gravity_extension_controller,
);

self.trim_assembly.update(
context,
&self.trim_controller,
&self.trim_controller,
[
self.green_circuit
.system_section()
.pressure_downstream_leak_valve(),
self.yellow_circuit
.system_section()
.pressure_downstream_leak_valve(),
],
);

self.left_aileron.update(
context,
self.aileron_system_controller.left_controllers(),
Expand Down Expand Up @@ -1975,72 +2011,6 @@ impl A320Hydraulic {
);
}

// Updates at the same rate as the sim or at a fixed maximum time step if sim rate is too slow
fn update_fast_physics(
&mut self,
context: &UpdateContext,
rat_and_emer_gen_man_on: &impl EmergencyElectricalRatPushButton,
emergency_elec: &(impl EmergencyElectricalState + EmergencyGeneratorPower),
lgciu1: &impl LgciuInterface,
lgciu2: &impl LgciuInterface,
adirs: &impl AdirsDiscreteOutputs,
) {
self.forward_cargo_door.update(
context,
&self.forward_cargo_door_controller,
self.yellow_circuit.system_section(),
);

self.aft_cargo_door.update(
context,
&self.aft_cargo_door_controller,
self.yellow_circuit.system_section(),
);

self.ram_air_turbine.update_physics(
&context.delta(),
context.indicated_airspeed(),
self.blue_circuit.system_section(),
);

self.gcu.update(
context,
&self.emergency_gen,
self.blue_circuit.system_section(),
emergency_elec,
rat_and_emer_gen_man_on,
lgciu1,
);

self.emergency_gen.update(
context,
self.blue_circuit.system_section(),
&self.gcu,
emergency_elec,
);

self.gear_system_hydraulic_controller.update(
adirs,
lgciu1,
lgciu2,
&self.gear_system_gravity_extension_controller,
);

self.trim_assembly.update(
context,
&self.trim_controller,
&self.trim_controller,
[
self.green_circuit
.system_section()
.pressure_downstream_leak_valve(),
self.yellow_circuit
.system_section()
.pressure_downstream_leak_valve(),
],
);
}

fn update_with_sim_rate(
&mut self,
context: &UpdateContext,
Expand Down Expand Up @@ -10466,7 +10436,7 @@ mod tests {
.set_cold_dark_inputs()
.start_eng1(Ratio::new::<percent>(80.))
.start_eng2(Ratio::new::<percent>(80.))
.run_waiting_for(Duration::from_millis(500));
.run_waiting_for(Duration::from_millis(1000));

assert!(!test_bed.ptu_has_fault());
assert!(!test_bed.green_edp_has_fault());
Expand Down
Loading