Skip to content

Commit

Permalink
feat(hyd): faster core hydraulics solver (flybywiresim#7635)
Browse files Browse the repository at this point in the history
  • Loading branch information
crocket63 authored and Eearslya committed Jan 4, 2023
1 parent fe3568f commit 412bd04
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 276 deletions.
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
190 changes: 80 additions & 110 deletions src/systems/a320_systems/src/hydraulic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,14 @@ use systems::{
AutoOffFaultPushButton, AutoOnFaultPushButton, MomentaryOnPushButton, MomentaryPushButton,
},
shared::{
interpolation,
low_pass_filter::LowPassFilter,
random_from_normal_distribution, random_from_range,
update_iterator::{FixedStepLoop, MaxStepLoop},
AdirsDiscreteOutputs, AirbusElectricPumpId, AirbusEngineDrivenPumpId,
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,
AirbusElectricPumpId, AirbusEngineDrivenPumpId, 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 @@ -1423,9 +1421,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 @@ -1542,13 +1538,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 @@ -1564,11 +1554,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 @@ -1785,19 +1771,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 @@ -1811,11 +1784,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 @@ -1916,11 +1893,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 @@ -1981,72 +2017,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 @@ -10525,7 +10495,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

0 comments on commit 412bd04

Please sign in to comment.