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(cond): randomized starting positions for air conditioning selector knobs #6922

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
1. [AP] Improved V/PATH law - lukecologne (luke)
1. [ADIRS] Improve ADR SSM behaviour, add missing data to the IR - @luke (lukecologne#1156)
1. [PFD] Improve SPD and MACH flag behaviour, add FPV flag - @luke (lukecologne#1156)
1. [COND] Randomize cabin air temperature knob starting position - @rare-potato(Rare Potato#9693)

## 0.7.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position=1
XMLVAR_SWITCH_OVHD_INTLT_EMEREXIT_Position=1
A32NX_OVHD_INTLT_ANN=1
XMLVAR_A320_WEATHERRADAR_MODE = 1
A32NX_OVHD_COND_CKPT_SELECTOR_KNOB=50
A32NX_OVHD_COND_FWD_SELECTOR_KNOB=50
A32NX_OVHD_COND_AFT_SELECTOR_KNOB=50
STROBE_1_Auto=1
A32NX_BARO_BRIGHTNESS=0.75
A32NX_SWITCH_RADAR_PWS_Position=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position=2
XMLVAR_SWITCH_OVHD_INTLT_EMEREXIT_Position=2
A32NX_OVHD_INTLT_ANN=1
XMLVAR_A320_WEATHERRADAR_MODE = 1
A32NX_OVHD_COND_CKPT_SELECTOR_KNOB=50
A32NX_OVHD_COND_FWD_SELECTOR_KNOB=50
A32NX_OVHD_COND_AFT_SELECTOR_KNOB=50
PUSH_OVHD_OXYGEN_CREW=1
STROBE_1_Auto=0
A32NX_BARO_BRIGHTNESS=0.15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position=1
XMLVAR_SWITCH_OVHD_INTLT_EMEREXIT_Position=1
A32NX_OVHD_INTLT_ANN=1
XMLVAR_A320_WEATHERRADAR_MODE = 1
A32NX_OVHD_COND_CKPT_SELECTOR_KNOB=50
A32NX_OVHD_COND_FWD_SELECTOR_KNOB=50
A32NX_OVHD_COND_AFT_SELECTOR_KNOB=50
STROBE_1_Auto=1
A32NX_BARO_BRIGHTNESS=0.75
A32NX_SWITCH_RADAR_PWS_Position=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position=1
XMLVAR_SWITCH_OVHD_INTLT_EMEREXIT_Position=1
A32NX_OVHD_INTLT_ANN=1
XMLVAR_A320_WEATHERRADAR_MODE = 1
A32NX_OVHD_COND_CKPT_SELECTOR_KNOB=50
A32NX_OVHD_COND_FWD_SELECTOR_KNOB=50
A32NX_OVHD_COND_AFT_SELECTOR_KNOB=50
STROBE_1_Auto=1
A32NX_BARO_BRIGHTNESS=0.75
A32NX_SWITCH_RADAR_PWS_Position=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position=2
XMLVAR_SWITCH_OVHD_INTLT_EMEREXIT_Position=2
A32NX_OVHD_INTLT_ANN=1
XMLVAR_A320_WEATHERRADAR_MODE = 1
A32NX_OVHD_COND_CKPT_SELECTOR_KNOB=50
A32NX_OVHD_COND_FWD_SELECTOR_KNOB=50
A32NX_OVHD_COND_AFT_SELECTOR_KNOB=50
PUSH_OVHD_OXYGEN_CREW=1
STROBE_1_Auto=0
A32NX_BARO_BRIGHTNESS=0.15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position=1
XMLVAR_SWITCH_OVHD_INTLT_EMEREXIT_Position=1
A32NX_OVHD_INTLT_ANN=1
XMLVAR_A320_WEATHERRADAR_MODE = 1
A32NX_OVHD_COND_CKPT_SELECTOR_KNOB=50
A32NX_OVHD_COND_FWD_SELECTOR_KNOB=50
A32NX_OVHD_COND_AFT_SELECTOR_KNOB=50
STROBE_1_Auto=1
A32NX_BARO_BRIGHTNESS=0.75
A32NX_SWITCH_RADAR_PWS_Position=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position=1
XMLVAR_SWITCH_OVHD_INTLT_EMEREXIT_Position=1
A32NX_OVHD_INTLT_ANN=1
XMLVAR_A320_WEATHERRADAR_MODE = 1
A32NX_OVHD_COND_CKPT_SELECTOR_KNOB=50
A32NX_OVHD_COND_FWD_SELECTOR_KNOB=50
A32NX_OVHD_COND_AFT_SELECTOR_KNOB=50
A32NX_AIRCOND_RAMAIR_TOGGLE=0
STROBE_1_Auto=1
A32NX_BARO_BRIGHTNESS=0.75
Expand Down
2 changes: 2 additions & 0 deletions src/fbw/src/FlyByWireInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ class FlyByWireInterface {

bool updateAltimeterSetting(double sampleTime);

bool setAirConditionSetting(double sampleTime);

double getTcasModeAvailable();

double getTcasAdvisoryState();
Expand Down
3 changes: 2 additions & 1 deletion src/systems/systems/src/air_conditioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use uom::si::{

pub mod acs_controller;
pub mod cabin_air;
pub mod selector_position;

pub trait DuctTemperature {
fn duct_demand_temperature(&self) -> Vec<ThermodynamicTemperature>;
Expand Down Expand Up @@ -71,7 +72,7 @@ pub struct AirConditioningSystem<const ZONES: usize> {
impl<const ZONES: usize> AirConditioningSystem<ZONES> {
pub fn new(context: &mut InitContext, cabin_zones: [ZoneType; ZONES]) -> Self {
Self {
acs_overhead: AirConditioningSystemOverhead::new(context, &cabin_zones),
acs_overhead: AirConditioningSystemOverhead::new(context, &cabin_zones), //NOTE
acsc: AirConditioningSystemController::new(context, &cabin_zones),
pack_flow_valves: [
PackFlowValve::new(context, 1),
Expand Down
94 changes: 94 additions & 0 deletions src/systems/systems/src/air_conditioning/selector_position.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use crate::simulation::{InitContext, VariableIdentifier, SimulatorWriter, Writer};
use rand::distributions::{Distribution, WeightedIndex};
use rand::prelude::{thread_rng, ThreadRng};
use crate::air_conditioning::ZoneType;

#[derive(Debug)]
pub struct AirConditioningSelector;

impl AirConditioningSelector {
pub fn new<U>(context: &mut InitContext, writer: &mut SimulatorWriter,
) where U: FnOnce(&mut InitContext) -> U {
// Set the position of the A/C knobs on aircraft load

let ckpt_start_position: f64 = random_start_position();
let cabin_start_position: f64 = random_start_position();

let knob_start_positions: [f64; 3] = [
ckpt_start_position,
cabin_start_position,
cabin_start_position
];

let mut knob_ids: Vec<VariableIdentifier> = Vec::new();

let cabin_zones: [ZoneType; 3] =
[ZoneType::Cockpit, ZoneType::Cabin(1), ZoneType::Cabin(2)];

for zone in cabin_zones {
knob_ids.push(
context.get_identifier(
format!("OVHD_COND_{}_SELECTOR_KNOB", zone)
)
);
}

for (i, knob_id) in knob_ids.iter().enumerate() {
write(
writer,
&knob_id,
knob_start_positions[i]
);
}
}
}

fn write(
writer: &mut SimulatorWriter,
knob_id: &VariableIdentifier,
knob_start_position: f64,
) {
writer.write_f64(knob_id, knob_start_position);
}

fn random_start_position() -> f64 {
// Sum of all occurrences is currently 1000 so the probability of a value to be chosen can be
// calculated by taking the weight and dividing it by 1000
const POSITION_OCCURRENCES: [i32; 13] = [10, 1, 2, 30, 93, 139, 614, 104, 2, 1, 1, 1, 1];
// Accounts for the 0 position
const POSITION_COUNT: usize = (POSITION_OCCURRENCES.len() - 1) as usize;
const SELECTOR_KNOB_MAX: usize = 300;
// Randomly selects one of the 13 possible starting positions based on predefined weights
//
// The 13 possible starting positions are the knob values for
// the whole number temperatures between 18C and 30C inclusive
// starting at 0 and ending at 300
//
// TODO: Increase possible starting positions

let mut knob_start_positions: Vec<(usize, i32)> = Vec::new();
let knob_position_multiplier: usize = SELECTOR_KNOB_MAX / POSITION_COUNT;
let mut rng: ThreadRng = thread_rng();

for (_0, _1) in POSITION_OCCURRENCES.iter().enumerate() {
knob_start_positions.push(((_0 * knob_position_multiplier) as usize, *_1));
}

let weighted_knob_start_positions: WeightedIndex<i32> = WeightedIndex::new(
knob_start_positions.iter().map(|pos| pos.1)
).unwrap();

knob_start_positions[weighted_knob_start_positions.sample(&mut rng)].0 as f64
}


#[cfg(test)]
mod selector_position_tests {
use super::*;
use crate::{
simulation::{
test::{ReadByName, SimulationTestBed, TestBed, WriteByName},
Aircraft, SimulationElement, SimulationElementVisitor, UpdateContext,
},
};
}