From b5e881fb4e0e47ef88e90254f652e280246b9380 Mon Sep 17 00:00:00 2001 From: Rare Potato Date: Tue, 15 Mar 2022 02:59:24 -0500 Subject: [PATCH 1/4] refactor: remove static ac knob start positions remove the static starting positions for the cabin air conditioning selector knobs --- .../SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT | 3 --- .../SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT | 3 --- .../SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT | 3 --- .../SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT | 3 --- .../SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt | 3 --- .../SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT | 3 --- .../SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt | 3 --- 7 files changed, 21 deletions(-) diff --git a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT index e97941fe0e8..f8873e6fc51 100644 --- a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT +++ b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT @@ -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 diff --git a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT index 75522622b3d..2cefaeabc3a 100644 --- a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT +++ b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT @@ -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 diff --git a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT index 503698ff3c9..d579e4b4cdd 100644 --- a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT +++ b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT @@ -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 diff --git a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT index aa519f3e148..58854533052 100644 --- a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT +++ b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT @@ -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 diff --git a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt index 4f7f250cc8f..24cc38d1497 100644 --- a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt +++ b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt @@ -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 diff --git a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT index 46dd12731ae..0ba33cc6a41 100644 --- a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT +++ b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT @@ -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 diff --git a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt index d29100163d1..ce6c50d2ece 100644 --- a/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt +++ b/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt @@ -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 From 697fcf1446d99dd1d571dc9fd6cc2839ebd9d0ff Mon Sep 17 00:00:00 2001 From: Rare Potato Date: Tue, 15 Mar 2022 04:22:55 -0500 Subject: [PATCH 2/4] feat(cond): initial randomize aircond knob starting positions (initial implementation) on plane load randomize air conditioner knob starting positions based on a normal distribution --- .github/CHANGELOG.md | 1 + src/fbw/src/FlyByWireInterface.cpp | 91 ++++++++++++++++++++++++++++++ src/fbw/src/FlyByWireInterface.h | 6 ++ 3 files changed, 98 insertions(+) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index d2298055ef8..d921ad2ef29 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -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 diff --git a/src/fbw/src/FlyByWireInterface.cpp b/src/fbw/src/FlyByWireInterface.cpp index 85f7d5578f7..cc8b1a12dd9 100644 --- a/src/fbw/src/FlyByWireInterface.cpp +++ b/src/fbw/src/FlyByWireInterface.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "FlyByWireInterface.h" #include "SimConnectData.h" @@ -215,6 +217,9 @@ void FlyByWireInterface::loadConfiguration() { mappingTable3d.emplace_back(35.0, 75.0); mappingTable3d.emplace_back(45.0, 100.0); idThrottlePositionLookupTable3d.initialize(mappingTable3d, 0, 100); + + // set air condition knob setting + setAirConditionSetting(calculatedSampleTime); } void FlyByWireInterface::setupLocalVariables() { @@ -439,6 +444,10 @@ void FlyByWireInterface::setupLocalVariables() { idRadioReceiverLocalizerDistance = make_unique("A32NX_RADIO_RECEIVER_LOC_DISTANCE"); idRadioReceiverGlideSlopeValid = make_unique("A32NX_RADIO_RECEIVER_GS_IS_VALID"); idRadioReceiverGlideSlopeDeviation = make_unique("A32NX_RADIO_RECEIVER_GS_DEVIATION"); + + idAirConditionSettingCkpt = make_unique("A32NX_OVHD_COND_CKPT_SELECTOR_KNOB"); + idAirConditionSettingFwd = make_unique("A32NX_OVHD_COND_FWD_SELECTOR_KNOB"); + idAirConditionSettingAft = make_unique("A32NX_OVHD_COND_AFT_SELECTOR_KNOB"); } bool FlyByWireInterface::readDataAndLocalVariables(double sampleTime) { @@ -1754,3 +1763,85 @@ double FlyByWireInterface::getTcasAdvisoryState() { return state; } + +bool FlyByWireInterface::setAirConditionSetting(double sampleTime) { + //MIN = 18.00C/64.400F 0 + //9 O'CLOCK = 19.92C/67.856F 16 + //REALISTIC MIN = 21.12C/70.016F 26 + //10 O' CLOCK = 22.08C/71.744F 34 + //AVERAGE = 24.00C/75.000F 50 + //2 O' CLOCK = 25.92C/78.656F 66 + //REALISTIC MAX = 26.88C/80.384F 74 + //3 O' CLOCK = 28.08C/82.544F 84 + //MAX = 30.00C/86.000F 100 + + //auto simData = simConnectInterface.getSimData(); + //ambientTemperature = simData.ambient_temperature_celsius; + //cout << "DEBUG: Current ambient temperature " << ambientTemperature << endl; + + unsigned seed = chrono::system_clock::now().time_since_epoch().count(); + default_random_engine generator(seed); + normal_distribution distribution(0.5, 0.09727); + double random_number = distribution(generator); + int rounded_number = 2 * round((random_number * 100) / 2); + + if (rounded_number <= 2) { + //~%0.15 chance (1/667) the knobs will be set between 10 o'clock and the lowest setting + int temp = rand()%(34 - 2) + 2; + int rounded_temp = 2 * round((temp * 100) / 2 ); + idAirConditionSettingCkpt->set(rounded_temp); + idAirConditionSettingFwd->set(rounded_temp); + idAirConditionSettingAft->set(rounded_temp); + } + else if (rounded_number >= 98) { + //~%0.15 chance (1/667) the knobs will be set between 2 o'clock and the highest setting + int temp = rand()%(98 - 66) + 66; + int rounded_temp = 2 * round((temp * 100) / 2 ); + idAirConditionSettingCkpt->set(rounded_temp); + idAirConditionSettingFwd->set(rounded_temp); + idAirConditionSettingAft->set(rounded_temp); + } + else if (42 < rounded_number && rounded_number < 58) { + //~68% chance (1/3) that the knobs will be at 12 o'clock + idAirConditionSettingCkpt->set(50); + idAirConditionSettingFwd->set(50); + idAirConditionSettingAft->set(50); + } + else if (34 <= rounded_number && rounded_number <= 42) { + //~11% chance (1/10) the knobs will be on the 10 o'clock setting + idAirConditionSettingCkpt->set(34); + idAirConditionSettingFwd->set(34); + idAirConditionSettingAft->set(34); + } + else if (58 <= rounded_number && rounded_number <= 66) { + //~11% chance (1/10) the knobs will be on the 2 o'clock setting + idAirConditionSettingCkpt->set(66); + idAirConditionSettingFwd->set(66); + idAirConditionSettingAft->set(66); + } + else if (2 < rounded_number && rounded_number < 34) { + //~5% chance (1/20) the knobs will be set between the 10 o'clock and 12 o'clock setting + int cold = 50 + rounded_number - 34; //THIS NEEDS TO BE CHANGED + idAirConditionSettingCkpt->set(cold); + idAirConditionSettingFwd->set(cold); + idAirConditionSettingAft->set(cold); + } + else if (66 < rounded_number && rounded_number < 98) { + //~5% chance (1/20) the knobs will be set between the 12 o'clock and 2 o'clock setting + int hot = 50 + rounded_number - 66; //THIS NEEDS TO BE CHANGED + idAirConditionSettingCkpt->set(hot); + idAirConditionSettingFwd->set(hot); + idAirConditionSettingAft->set(hot); + } + else { + cout << "WASM: Unkown Error setting Air Conditioning Knob" << endl; + return true; + } + + cout << "WASM: Setting Cockpit A/C Knob " << idAirConditionSettingCkpt->get() << endl; + cout << "WASM: Setting Forward A/C Knob " << idAirConditionSettingFwd->get() << endl; + cout << "WASM: Setting Aft A/C Knob " << idAirConditionSettingAft->get() << endl; + cout << "WASM: A/C Knob Rounded Variable " << rounded_number << endl; + + return true; +} diff --git a/src/fbw/src/FlyByWireInterface.h b/src/fbw/src/FlyByWireInterface.h index e38b049cd96..bacf25349b0 100644 --- a/src/fbw/src/FlyByWireInterface.h +++ b/src/fbw/src/FlyByWireInterface.h @@ -320,6 +320,10 @@ class FlyByWireInterface { std::unique_ptr idRadioReceiverGlideSlopeValid; std::unique_ptr idRadioReceiverGlideSlopeDeviation; + std::unique_ptr idAirConditionSettingCkpt; + std::unique_ptr idAirConditionSettingFwd; + std::unique_ptr idAirConditionSettingAft; + void loadConfiguration(); void setupLocalVariables(); @@ -342,6 +346,8 @@ class FlyByWireInterface { bool updateAltimeterSetting(double sampleTime); + bool setAirConditionSetting(double sampleTime); + double getTcasModeAvailable(); double getTcasAdvisoryState(); From 748755ce4a152b38026d5440715f4774b2c9047a Mon Sep 17 00:00:00 2001 From: Rare Potato Date: Thu, 17 Mar 2022 18:34:30 -0500 Subject: [PATCH 3/4] revert: feat(cond): initial randomize aircond knob starting positions This partially reverts commit 697fcf1446d99dd1d571dc9fd6cc2839ebd9d0ff inappropriate location for logic --- src/fbw/src/FlyByWireInterface.cpp | 91 ------------------------------ src/fbw/src/FlyByWireInterface.h | 4 -- 2 files changed, 95 deletions(-) diff --git a/src/fbw/src/FlyByWireInterface.cpp b/src/fbw/src/FlyByWireInterface.cpp index cc8b1a12dd9..85f7d5578f7 100644 --- a/src/fbw/src/FlyByWireInterface.cpp +++ b/src/fbw/src/FlyByWireInterface.cpp @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include "FlyByWireInterface.h" #include "SimConnectData.h" @@ -217,9 +215,6 @@ void FlyByWireInterface::loadConfiguration() { mappingTable3d.emplace_back(35.0, 75.0); mappingTable3d.emplace_back(45.0, 100.0); idThrottlePositionLookupTable3d.initialize(mappingTable3d, 0, 100); - - // set air condition knob setting - setAirConditionSetting(calculatedSampleTime); } void FlyByWireInterface::setupLocalVariables() { @@ -444,10 +439,6 @@ void FlyByWireInterface::setupLocalVariables() { idRadioReceiverLocalizerDistance = make_unique("A32NX_RADIO_RECEIVER_LOC_DISTANCE"); idRadioReceiverGlideSlopeValid = make_unique("A32NX_RADIO_RECEIVER_GS_IS_VALID"); idRadioReceiverGlideSlopeDeviation = make_unique("A32NX_RADIO_RECEIVER_GS_DEVIATION"); - - idAirConditionSettingCkpt = make_unique("A32NX_OVHD_COND_CKPT_SELECTOR_KNOB"); - idAirConditionSettingFwd = make_unique("A32NX_OVHD_COND_FWD_SELECTOR_KNOB"); - idAirConditionSettingAft = make_unique("A32NX_OVHD_COND_AFT_SELECTOR_KNOB"); } bool FlyByWireInterface::readDataAndLocalVariables(double sampleTime) { @@ -1763,85 +1754,3 @@ double FlyByWireInterface::getTcasAdvisoryState() { return state; } - -bool FlyByWireInterface::setAirConditionSetting(double sampleTime) { - //MIN = 18.00C/64.400F 0 - //9 O'CLOCK = 19.92C/67.856F 16 - //REALISTIC MIN = 21.12C/70.016F 26 - //10 O' CLOCK = 22.08C/71.744F 34 - //AVERAGE = 24.00C/75.000F 50 - //2 O' CLOCK = 25.92C/78.656F 66 - //REALISTIC MAX = 26.88C/80.384F 74 - //3 O' CLOCK = 28.08C/82.544F 84 - //MAX = 30.00C/86.000F 100 - - //auto simData = simConnectInterface.getSimData(); - //ambientTemperature = simData.ambient_temperature_celsius; - //cout << "DEBUG: Current ambient temperature " << ambientTemperature << endl; - - unsigned seed = chrono::system_clock::now().time_since_epoch().count(); - default_random_engine generator(seed); - normal_distribution distribution(0.5, 0.09727); - double random_number = distribution(generator); - int rounded_number = 2 * round((random_number * 100) / 2); - - if (rounded_number <= 2) { - //~%0.15 chance (1/667) the knobs will be set between 10 o'clock and the lowest setting - int temp = rand()%(34 - 2) + 2; - int rounded_temp = 2 * round((temp * 100) / 2 ); - idAirConditionSettingCkpt->set(rounded_temp); - idAirConditionSettingFwd->set(rounded_temp); - idAirConditionSettingAft->set(rounded_temp); - } - else if (rounded_number >= 98) { - //~%0.15 chance (1/667) the knobs will be set between 2 o'clock and the highest setting - int temp = rand()%(98 - 66) + 66; - int rounded_temp = 2 * round((temp * 100) / 2 ); - idAirConditionSettingCkpt->set(rounded_temp); - idAirConditionSettingFwd->set(rounded_temp); - idAirConditionSettingAft->set(rounded_temp); - } - else if (42 < rounded_number && rounded_number < 58) { - //~68% chance (1/3) that the knobs will be at 12 o'clock - idAirConditionSettingCkpt->set(50); - idAirConditionSettingFwd->set(50); - idAirConditionSettingAft->set(50); - } - else if (34 <= rounded_number && rounded_number <= 42) { - //~11% chance (1/10) the knobs will be on the 10 o'clock setting - idAirConditionSettingCkpt->set(34); - idAirConditionSettingFwd->set(34); - idAirConditionSettingAft->set(34); - } - else if (58 <= rounded_number && rounded_number <= 66) { - //~11% chance (1/10) the knobs will be on the 2 o'clock setting - idAirConditionSettingCkpt->set(66); - idAirConditionSettingFwd->set(66); - idAirConditionSettingAft->set(66); - } - else if (2 < rounded_number && rounded_number < 34) { - //~5% chance (1/20) the knobs will be set between the 10 o'clock and 12 o'clock setting - int cold = 50 + rounded_number - 34; //THIS NEEDS TO BE CHANGED - idAirConditionSettingCkpt->set(cold); - idAirConditionSettingFwd->set(cold); - idAirConditionSettingAft->set(cold); - } - else if (66 < rounded_number && rounded_number < 98) { - //~5% chance (1/20) the knobs will be set between the 12 o'clock and 2 o'clock setting - int hot = 50 + rounded_number - 66; //THIS NEEDS TO BE CHANGED - idAirConditionSettingCkpt->set(hot); - idAirConditionSettingFwd->set(hot); - idAirConditionSettingAft->set(hot); - } - else { - cout << "WASM: Unkown Error setting Air Conditioning Knob" << endl; - return true; - } - - cout << "WASM: Setting Cockpit A/C Knob " << idAirConditionSettingCkpt->get() << endl; - cout << "WASM: Setting Forward A/C Knob " << idAirConditionSettingFwd->get() << endl; - cout << "WASM: Setting Aft A/C Knob " << idAirConditionSettingAft->get() << endl; - cout << "WASM: A/C Knob Rounded Variable " << rounded_number << endl; - - return true; -} diff --git a/src/fbw/src/FlyByWireInterface.h b/src/fbw/src/FlyByWireInterface.h index bacf25349b0..0cfab99d6ca 100644 --- a/src/fbw/src/FlyByWireInterface.h +++ b/src/fbw/src/FlyByWireInterface.h @@ -320,10 +320,6 @@ class FlyByWireInterface { std::unique_ptr idRadioReceiverGlideSlopeValid; std::unique_ptr idRadioReceiverGlideSlopeDeviation; - std::unique_ptr idAirConditionSettingCkpt; - std::unique_ptr idAirConditionSettingFwd; - std::unique_ptr idAirConditionSettingAft; - void loadConfiguration(); void setupLocalVariables(); From 71ec1caf16000db061a8a669823c168761b0b2d3 Mon Sep 17 00:00:00 2001 From: Rare Potato Date: Thu, 17 Mar 2022 18:35:48 -0500 Subject: [PATCH 4/4] wip(cond): initial rust randomize aircond knob starting positions start of logic to randomized air conditioning knobs on aircraft load --- .../systems/src/air_conditioning/mod.rs | 3 +- .../src/air_conditioning/selector_position.rs | 94 +++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/systems/systems/src/air_conditioning/selector_position.rs diff --git a/src/systems/systems/src/air_conditioning/mod.rs b/src/systems/systems/src/air_conditioning/mod.rs index 95e3918d24f..27558bac9d2 100644 --- a/src/systems/systems/src/air_conditioning/mod.rs +++ b/src/systems/systems/src/air_conditioning/mod.rs @@ -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; @@ -71,7 +72,7 @@ pub struct AirConditioningSystem { impl AirConditioningSystem { 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), diff --git a/src/systems/systems/src/air_conditioning/selector_position.rs b/src/systems/systems/src/air_conditioning/selector_position.rs new file mode 100644 index 00000000000..f8f6eafffea --- /dev/null +++ b/src/systems/systems/src/air_conditioning/selector_position.rs @@ -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(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 = 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 = 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, + }, + }; +}