forked from flybywiresim/aircraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: declarative msfs aspects (flybywiresim#6427)
- Loading branch information
1 parent
e919a7b
commit 4869482
Showing
16 changed files
with
1,811 additions
and
1,328 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::error::Error; | ||
use std::time::Duration; | ||
use systems_wasm::aspects::{EventToVariableMapping, EventToVariableOptions, MsfsAspectBuilder}; | ||
use systems_wasm::Variable; | ||
|
||
pub(super) fn autobrakes(builder: &mut MsfsAspectBuilder) -> Result<(), Box<dyn Error>> { | ||
let options = |options: EventToVariableOptions| { | ||
options | ||
.leading_debounce(Duration::from_millis(1500)) | ||
.afterwards_reset_to(0.) | ||
}; | ||
|
||
builder.event_to_variable( | ||
"AUTOBRAKE_LO_SET", | ||
EventToVariableMapping::Value(1.), | ||
Variable::named("OVHD_AUTOBRK_LOW_ON_IS_PRESSED"), | ||
options, | ||
)?; | ||
builder.event_to_variable( | ||
"AUTOBRAKE_MED_SET", | ||
EventToVariableMapping::Value(1.), | ||
Variable::named("OVHD_AUTOBRK_MED_ON_IS_PRESSED"), | ||
options, | ||
)?; | ||
builder.event_to_variable( | ||
"AUTOBRAKE_HI_SET", | ||
EventToVariableMapping::Value(1.), | ||
Variable::named("OVHD_AUTOBRK_MAX_ON_IS_PRESSED"), | ||
options, | ||
)?; | ||
builder.event_to_variable( | ||
"AUTOBRAKE_DISARM", | ||
EventToVariableMapping::Value(1.), | ||
Variable::named("AUTOBRAKE_DISARM"), | ||
|options| options.afterwards_reset_to(0.), | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
use std::error::Error; | ||
use systems::shared::{from_bool, to_bool}; | ||
use systems_wasm::aspects::{ | ||
max, EventToVariableMapping, ExecuteOn, MsfsAspectBuilder, VariableToEventMapping, | ||
VariableToEventWriteOn, | ||
}; | ||
use systems_wasm::Variable; | ||
|
||
pub(super) fn brakes(builder: &mut MsfsAspectBuilder) -> Result<(), Box<dyn Error>> { | ||
builder.event_to_variable( | ||
"PARKING_BRAKES", | ||
EventToVariableMapping::CurrentValueToValue(|current_value| { | ||
from_bool(!to_bool(current_value)) | ||
}), | ||
Variable::named("PARK_BRAKE_LEVER_POS"), | ||
|options| options.mask(), | ||
)?; | ||
builder.event_to_variable( | ||
"PARKING_BRAKE_SET", | ||
EventToVariableMapping::EventDataToValue(|event_data| from_bool(event_data == 1)), | ||
Variable::named("PARK_BRAKE_LEVER_POS"), | ||
|options| options.mask(), | ||
)?; | ||
|
||
// Controller inputs for the left and right brakes are captured and translated | ||
// to a variable so that it can be used by the simulation. | ||
// After running the simulation, the variable value is written back to the simulator | ||
// through the event. | ||
let axis_left_brake_set_event_id = builder.event_to_variable( | ||
"AXIS_LEFT_BRAKE_SET", | ||
EventToVariableMapping::EventData32kPosition, | ||
Variable::aspect("BRAKES_LEFT_EVENT"), | ||
|options| options.mask(), | ||
)?; | ||
builder.variable_to_event_id( | ||
Variable::aspect("BRAKE LEFT FORCE FACTOR"), | ||
VariableToEventMapping::EventData32kPosition, | ||
VariableToEventWriteOn::EveryTick, | ||
axis_left_brake_set_event_id, | ||
); | ||
let axis_right_brake_set_event_id = builder.event_to_variable( | ||
"AXIS_RIGHT_BRAKE_SET", | ||
EventToVariableMapping::EventData32kPosition, | ||
Variable::aspect("BRAKES_RIGHT_EVENT"), | ||
|options| options.mask(), | ||
)?; | ||
builder.variable_to_event_id( | ||
Variable::aspect("BRAKE RIGHT FORCE FACTOR"), | ||
VariableToEventMapping::EventData32kPosition, | ||
VariableToEventWriteOn::EveryTick, | ||
axis_right_brake_set_event_id, | ||
); | ||
|
||
// Inputs for both brakes, left brake, and right brake are captured and | ||
// translated via a smooth press function into a ratio which is written to variables. | ||
const KEYBOARD_PRESS_SPEED: f64 = 0.6; | ||
const KEYBOARD_RELEASE_SPEED: f64 = 0.3; | ||
builder.event_to_variable( | ||
"BRAKES", | ||
EventToVariableMapping::SmoothPress(KEYBOARD_PRESS_SPEED, KEYBOARD_RELEASE_SPEED), | ||
Variable::aspect("BRAKES"), | ||
|options| options.mask(), | ||
)?; | ||
builder.event_to_variable( | ||
"BRAKES_LEFT", | ||
EventToVariableMapping::SmoothPress(KEYBOARD_PRESS_SPEED, KEYBOARD_RELEASE_SPEED), | ||
Variable::aspect("BRAKES_LEFT"), | ||
|options| options.mask(), | ||
)?; | ||
builder.event_to_variable( | ||
"BRAKES_RIGHT", | ||
EventToVariableMapping::SmoothPress(KEYBOARD_PRESS_SPEED, KEYBOARD_RELEASE_SPEED), | ||
Variable::aspect("BRAKES_RIGHT"), | ||
|options| options.mask(), | ||
)?; | ||
|
||
// The maximum braking demand of all controller inputs | ||
// is calculated and made available as a percentage. | ||
builder.reduce( | ||
ExecuteOn::PreTick, | ||
vec![ | ||
Variable::aspect("BRAKES"), | ||
Variable::aspect("BRAKES_LEFT"), | ||
Variable::aspect("BRAKES_LEFT_EVENT"), | ||
], | ||
0., | ||
to_percent_max, | ||
Variable::named("LEFT_BRAKE_PEDAL_INPUT"), | ||
); | ||
builder.reduce( | ||
ExecuteOn::PreTick, | ||
vec![ | ||
Variable::aspect("BRAKES"), | ||
Variable::aspect("BRAKES_RIGHT"), | ||
Variable::aspect("BRAKES_RIGHT_EVENT"), | ||
], | ||
0., | ||
to_percent_max, | ||
Variable::named("RIGHT_BRAKE_PEDAL_INPUT"), | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn to_percent_max(accumulator: f64, item: f64) -> f64 { | ||
max(accumulator, item * 100.) | ||
} |
Oops, something went wrong.