Skip to content

Commit

Permalink
feat: custom wingflex simulation (#7980)
Browse files Browse the repository at this point in the history
* first issue

* reverser assembly

* added tests

* changelog

* temp

* added controller state machine

* works

* reverse thrust simulation

* poc reverse thrust

* removed msfs reversers

* animation

* adjustments

* based on engine thrust from msfs

* added torque effect

* clean

* export sensors

* update ecam REV info

* removed unused reverser template files

* proto

* refactor wobbling physics

* cleanup

* fix merge

* powering valves from elec

* reinstate file include

* clean up

* update gear test with elec power

* comment

* added missing compression var

* first flex proto

* remove debug

* reverser_n namings

* lift modifier

* clean println

* change sounds simvars

* correct left/right spread

* added flaps read

* Added aft cone flex on a380

* added dev var for tuning

* trying low damping

* added lateral offset gain

* remove useless pub

* cleanup

* folder structure

* added right wing animation outputs

* refactor flex file structure

* refactor file structure

* added aft flex in test

* added test bed

* added tests

* more lift tests

* adding dynamic lift based on surfaces

* testing

* new animations

* non linear and assymetrical stiffness

* aoa condition

* lift spread edit

* remove aoa protection

* tuning

* clean up

* Added flap effect on lift spread

* added vibration generation

* rotational calculations

* removed plane acceleration from wing nodes

* Wing flex impacts now ok

* start refactor 380 flex system

* centralized vibration generator

* tuned engine wobble from pylons accels

* cleaning

* remove print

* cleaning

* dev

* last tuning

* lower no lift speed

* moved engine wobble to flex dir

* Clippy

* changelog

* default mass

* lint

* Comments

* clean up

* Update run.sh

* update test to write in deg per sec as per msfs

* lint

* lint

* printn removed

* clippy

* unused test

* Added weight on wheels ratio simvar for sound

* gear weight from 0 to 1

* changelog

* revert run sh changes

* revert run sh

* revert lto option

* lint

* update after merge

* fix after merge

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/engine_wobble.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* lint

* ratio default

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* fix bracket

* default()

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* simplified calc

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* added :0 index for clarity

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* Update fbw-common/src/wasm/systems/systems/src/structural_flex/wing_flex.rs

Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>

* nightmare in progress

* Trait for surfaces positions

* solve issues with references

* Use new fuel payload system

* Move A380 structs

* Default impl

---------

Co-authored-by: 2hwk <15316958+2hwk@users.noreply.github.com>
Co-authored-by: Pascal Störzbach <Gurgel100@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 16, 2023
1 parent c3755f7 commit c001a97
Show file tree
Hide file tree
Showing 20 changed files with 2,741 additions and 118 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,21 @@ async fn systems(mut gauge: msfs::Gauge) -> Result<(), Box<dyn Error>> {
.provides_named_variable("FSDT_GSX_NUMPASSENGERS_DEBOARDING_TOTAL")?
.provides_named_variable("FSDT_GSX_BOARDING_CARGO_PERCENT")?
.provides_named_variable("FSDT_GSX_DEBOARDING_CARGO_PERCENT")?
.provides_aircraft_variable(
"ROTATION ACCELERATION BODY X",
"radian per second squared",
0,
)?
.provides_aircraft_variable(
"ROTATION ACCELERATION BODY Y",
"radian per second squared",
0,
)?
.provides_aircraft_variable(
"ROTATION ACCELERATION BODY Z",
"radian per second squared",
0,
)?
.with_aspect(|builder| {
builder.copy(
Variable::aircraft("APU GENERATOR SWITCH", "Bool", 0),
Expand Down
4 changes: 4 additions & 0 deletions fbw-a380x/src/wasm/systems/a380_systems/src/fuel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ impl FuelPayload for A380Fuel {
fn fore_aft_center_of_gravity(&self) -> f64 {
self.fore_aft_center_of_gravity()
}

fn tank_mass(&self, t: usize) -> Mass {
self.fuel_system.tank_mass(t)
}
}
impl FuelCG for A380Fuel {
fn center_of_gravity(&self) -> Vector3<f64> {
Expand Down
98 changes: 75 additions & 23 deletions fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use systems::{
AirbusElectricPumpId, AirbusEngineDrivenPumpId, DelayedFalseLogicGate,
DelayedPulseTrueLogicGate, DelayedTrueLogicGate, ElectricalBusType, ElectricalBuses,
EngineFirePushButtons, GearWheel, HydraulicColor, LandingGearHandle, LgciuInterface,
LgciuWeightOnWheels, ReservoirAirPressure, SectionPressure,
LgciuWeightOnWheels, ReservoirAirPressure, SectionPressure, SurfacesPositions,
},
simulation::{
InitContext, Read, Reader, SimulationElement, SimulationElementVisitor, SimulatorReader,
Expand Down Expand Up @@ -738,15 +738,15 @@ impl A380ElevatorFactory {
/// Builds an aileron control surface body for A380-800
fn a380_elevator_body(
init_drooped_down: bool,
is_outter: bool,
is_outer: bool,
) -> LinearActuatedRigidBodyOnHingeAxis {
let size = if is_outter {
let size = if is_outer {
Vector3::new(9., 0.405, 2.23)
} else {
Vector3::new(5., 0.405, 2.49)
};

let mass = if is_outter {
let mass = if is_outer {
Mass::new::<kilogram>(243.)
} else {
Mass::new::<kilogram>(189.)
Expand Down Expand Up @@ -786,9 +786,9 @@ impl A380ElevatorFactory {
context: &mut InitContext,
init_drooped_down: bool,
powered_by: Option<ElectricalBusType>,
is_outter: bool,
is_outer: bool,
) -> HydraulicLinearActuatorAssembly<2> {
let elevator_body = Self::a380_elevator_body(init_drooped_down, is_outter);
let elevator_body = Self::a380_elevator_body(init_drooped_down, is_outer);

let elevator_actuator_outboard =
Self::a380_elevator_actuator(context, &elevator_body, None);
Expand Down Expand Up @@ -834,10 +834,10 @@ impl A380ElevatorFactory {
)
}

fn new_a380_elevator_aero_model(is_outter: bool) -> AerodynamicModel {
let body = Self::a380_elevator_body(true, is_outter);
fn new_a380_elevator_aero_model(is_outer: bool) -> AerodynamicModel {
let body = Self::a380_elevator_body(true, is_outer);

let area_coeff = if is_outter {
let area_coeff = if is_outer {
Ratio::new::<ratio>(0.723)
} else {
Ratio::new::<ratio>(0.822)
Expand Down Expand Up @@ -2007,11 +2007,11 @@ impl A380Hydraulic {
}

pub fn left_elevator_aero_torques(&self) -> (Torque, Torque) {
self.left_elevator.aerodynamic_torques_outter_inner()
self.left_elevator.aerodynamic_torques_outer_inner()
}

pub fn right_elevator_aero_torques(&self) -> (Torque, Torque) {
self.right_elevator.aerodynamic_torques_outter_inner()
self.right_elevator.aerodynamic_torques_outer_inner()
}

pub fn up_down_rudder_aero_torques(&self) -> (Torque, Torque) {
Expand Down Expand Up @@ -2802,6 +2802,31 @@ impl A380Hydraulic {
&self.gear_system
}
}
impl SurfacesPositions for A380Hydraulic {
fn left_ailerons_positions(&self) -> &[f64] {
self.left_aileron.positions()
}

fn right_ailerons_positions(&self) -> &[f64] {
self.right_aileron.positions()
}

fn left_spoilers_positions(&self) -> &[f64] {
self.left_spoilers.positions()
}

fn right_spoilers_positions(&self) -> &[f64] {
self.right_spoilers.positions()
}

fn left_flaps_position(&self) -> f64 {
self.flap_system.left_position()
}

fn right_flaps_position(&self) -> f64 {
self.flap_system.right_position()
}
}
impl SimulationElement for A380Hydraulic {
fn accept<T: SimulationElementVisitor>(&mut self, visitor: &mut T) {
self.engine_driven_pump_1a.accept(visitor);
Expand Down Expand Up @@ -6021,7 +6046,7 @@ struct AileronAssembly {
position_mid_id: VariableIdentifier,
position_in_id: VariableIdentifier,

positions: [Ratio; 3],
positions: [f64; 3],
aerodynamic_models: [AerodynamicModel; 3],
}
impl AileronAssembly {
Expand All @@ -6031,7 +6056,7 @@ impl AileronAssembly {
outward_hydraulic_assembly: HydraulicLinearActuatorAssembly<2>,
middle_hydraulic_assembly: HydraulicLinearActuatorAssembly<2>,
inward_hydraulic_assembly: HydraulicLinearActuatorAssembly<2>,
aerodynamic_model_outter: AerodynamicModel,
aerodynamic_model_outer: AerodynamicModel,
aerodynamic_model_middle: AerodynamicModel,
aerodynamic_model_inner: AerodynamicModel,
) -> Self {
Expand Down Expand Up @@ -6065,9 +6090,9 @@ impl AileronAssembly {
context.get_identifier("HYD_AIL_RIGHT_INWARD_DEFLECTION".to_owned())
}
},
positions: [Ratio::new::<ratio>(0.); 3],
positions: [0.; 3],
aerodynamic_models: [
aerodynamic_model_outter,
aerodynamic_model_outer,
aerodynamic_model_middle,
aerodynamic_model_inner,
],
Expand Down Expand Up @@ -6102,9 +6127,15 @@ impl AileronAssembly {
],
);

self.positions[idx] = self.hydraulic_assemblies[idx].position_normalized();
self.positions[idx] = self.hydraulic_assemblies[idx]
.position_normalized()
.get::<ratio>();
}
}

fn positions(&self) -> &[f64; 3] {
&self.positions
}
}
impl SimulationElement for AileronAssembly {
fn accept<T: SimulationElementVisitor>(&mut self, visitor: &mut T) {
Expand All @@ -6114,9 +6145,9 @@ impl SimulationElement for AileronAssembly {
}

fn write(&self, writer: &mut SimulatorWriter) {
writer.write(&self.position_out_id, self.positions[0].get::<ratio>());
writer.write(&self.position_mid_id, self.positions[1].get::<ratio>());
writer.write(&self.position_in_id, self.positions[2].get::<ratio>());
writer.write(&self.position_out_id, self.positions[0]);
writer.write(&self.position_mid_id, self.positions[1]);
writer.write(&self.position_in_id, self.positions[2]);
}
}

Expand All @@ -6136,7 +6167,7 @@ impl ElevatorAssembly {
id: ActuatorSide,
outward_hydraulic_assembly: HydraulicLinearActuatorAssembly<2>,
inward_hydraulic_assembly: HydraulicLinearActuatorAssembly<2>,
aerodynamic_model_outter: AerodynamicModel,
aerodynamic_model_outer: AerodynamicModel,
aerodynamic_model_inner: AerodynamicModel,
) -> Self {
Self {
Expand All @@ -6159,7 +6190,7 @@ impl ElevatorAssembly {
},

positions: [Ratio::new::<ratio>(0.); 2],
aerodynamic_models: [aerodynamic_model_outter, aerodynamic_model_inner],
aerodynamic_models: [aerodynamic_model_outer, aerodynamic_model_inner],
}
}

Expand Down Expand Up @@ -6196,8 +6227,8 @@ impl ElevatorAssembly {
}
}

// Returns aerodynamic torques for (outter,inner) control surfaces
fn aerodynamic_torques_outter_inner(&self) -> (Torque, Torque) {
// Returns aerodynamic torques for (outer,inner) control surfaces
fn aerodynamic_torques_outer_inner(&self) -> (Torque, Torque) {
(
self.hydraulic_assemblies[0].aerodynamic_torque(),
self.hydraulic_assemblies[1].aerodynamic_torque(),
Expand Down Expand Up @@ -6378,6 +6409,10 @@ impl SpoilerElement {

self.position = self.hydraulic_assembly.position_normalized();
}

fn position(&self) -> f64 {
self.position.get::<ratio>()
}
}
impl SimulationElement for SpoilerElement {
fn accept<T: SimulationElementVisitor>(&mut self, visitor: &mut T) {
Expand All @@ -6394,6 +6429,7 @@ impl SimulationElement for SpoilerElement {
struct SpoilerGroup {
spoilers: [SpoilerElement; 8],
hydraulic_controllers: [SpoilerController; 8],
spoiler_positions: [f64; 8],
}
impl SpoilerGroup {
fn new(context: &mut InitContext, spoiler_side: &str, spoilers: [SpoilerElement; 8]) -> Self {
Expand All @@ -6409,6 +6445,7 @@ impl SpoilerGroup {
SpoilerController::new(context, spoiler_side, 7),
SpoilerController::new(context, spoiler_side, 8),
],
spoiler_positions: [0.; 8],
}
}

Expand Down Expand Up @@ -6458,11 +6495,26 @@ impl SpoilerGroup {
&self.hydraulic_controllers[7],
green_section.pressure_downstream_leak_valve(),
);

self.spoiler_positions = [
self.spoilers[0].position(),
self.spoilers[1].position(),
self.spoilers[2].position(),
self.spoilers[3].position(),
self.spoilers[4].position(),
self.spoilers[5].position(),
self.spoilers[6].position(),
self.spoilers[7].position(),
];
}

fn actuator(&mut self, spoiler_idx: usize) -> &mut impl Actuator {
self.spoilers[spoiler_idx].actuator()
}

fn positions(&self) -> &[f64; 8] {
&self.spoiler_positions
}
}
impl SimulationElement for SpoilerGroup {
fn accept<T: SimulationElementVisitor>(&mut self, visitor: &mut T) {
Expand Down
Loading

0 comments on commit c001a97

Please sign in to comment.