Skip to content

Commit

Permalink
feat(hyd): changed gear lever mechanism / added gear door drag (#7390)
Browse files Browse the repository at this point in the history
(Rebase Fix: cherry-picked from commit 248fe73)
  • Loading branch information
crocket63 authored and frankkopp committed Jan 22, 2023
1 parent 7fcf7e6 commit 10520e4
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ use msfs::sim_connect;
use msfs::{sim_connect::SimConnect, sim_connect::SIMCONNECT_OBJECT_ID_USER};

use systems_wasm::aspects::{
EventToVariableMapping, MsfsAspectBuilder, ObjectWrite, VariableToEventMapping,
VariableToEventWriteOn, VariablesToObject,
EventToVariableMapping, MsfsAspectBuilder, ObjectWrite, VariablesToObject,
};
use systems_wasm::{set_data_on_sim_object, Variable};

pub(super) fn gear(builder: &mut MsfsAspectBuilder) -> Result<(), Box<dyn Error>> {
// Read gear demand from all sim sim events and mask them
let gear_set_set_event_id = builder.event_to_variable(
builder.event_to_variable(
"GEAR_SET",
EventToVariableMapping::EventDataRaw,
Variable::aspect("GEAR_LEVER_POSITION_REQUEST"),
Variable::named("GEAR_LEVER_POSITION_REQUEST"),
|options| options.mask(),
)?;

Expand All @@ -29,37 +28,30 @@ pub(super) fn gear(builder: &mut MsfsAspectBuilder) -> Result<(), Box<dyn Error>
}
},
),
Variable::aspect("GEAR_LEVER_POSITION_REQUEST"),
Variable::named("GEAR_LEVER_POSITION_REQUEST"),
|options| options.mask(),
)?;

builder.event_to_variable(
"GEAR_UP",
EventToVariableMapping::Value(0.),
Variable::aspect("GEAR_LEVER_POSITION_REQUEST"),
Variable::named("GEAR_LEVER_POSITION_REQUEST"),
|options| options.mask(),
)?;

builder.event_to_variable(
"GEAR_DOWN",
EventToVariableMapping::Value(1.),
Variable::aspect("GEAR_LEVER_POSITION_REQUEST"),
Variable::named("GEAR_LEVER_POSITION_REQUEST"),
|options| options.mask(),
)?;

// Feedback the gear event to the sim
builder.variable_to_event_id(
Variable::aspect("GEAR_HANDLE_POSITION"),
VariableToEventMapping::EventDataRaw,
VariableToEventWriteOn::Change,
gear_set_set_event_id,
);

// GEAR POSITION FEEDBACK TO SIM
builder.variables_to_object(Box::new(GearPosition {
nose_position: 1.,
left_position: 1.,
right_position: 1.,
gear_handle_position: 1.,
}));

Ok(())
Expand All @@ -78,6 +70,10 @@ struct GearPosition {
#[name = "GEAR RIGHT POSITION"]
#[unit = "Percent over 100"]
right_position: f64,

#[name = "GEAR HANDLE POSITION"]
#[unit = "Percent over 100"]
gear_handle_position: f64,
}

impl VariablesToObject for GearPosition {
Expand All @@ -86,13 +82,30 @@ impl VariablesToObject for GearPosition {
Variable::named("GEAR_CENTER_POSITION"),
Variable::named("GEAR_LEFT_POSITION"),
Variable::named("GEAR_RIGHT_POSITION"),
Variable::named("GEAR_DOOR_CENTER_POSITION"),
Variable::named("GEAR_DOOR_LEFT_POSITION"),
Variable::named("GEAR_DOOR_RIGHT_POSITION"),
]
}

fn write(&mut self, values: Vec<f64>) -> ObjectWrite {
self.nose_position = values[0] / 100.;
self.left_position = values[1] / 100.;
self.right_position = values[2] / 100.;
const GEAR_POSITION_FOR_FAKE_DOOR_DRAG: f64 = 0.10;

let gear_deployed = values[0] > 5. || values[1] > 5. || values[2] > 5.;
let door_opened = values[3] > 10. || values[4] > 10. || values[5] > 10.;

// If doors are deployed we fake gear going down a bit to get some door drag effect from the sim
if door_opened && !gear_deployed {
self.nose_position = (values[3] / 100.).min(GEAR_POSITION_FOR_FAKE_DOOR_DRAG);
self.left_position = (values[4] / 100.).min(GEAR_POSITION_FOR_FAKE_DOOR_DRAG);
self.right_position = (values[5] / 100.).min(GEAR_POSITION_FOR_FAKE_DOOR_DRAG);
} else {
self.nose_position = values[0] / 100.;
self.left_position = values[1] / 100.;
self.right_position = values[2] / 100.;
}

self.gear_handle_position = if gear_deployed { 1. } else { 0. };

ObjectWrite::default()
}
Expand Down

0 comments on commit 10520e4

Please sign in to comment.