Skip to content

Commit

Permalink
feat(efcs): add precontrol to roll angle controller (flybywiresim#8272)
Browse files Browse the repository at this point in the history
* feat(efcs): add precontrol to roll rate controller

* feat(fbw): increase default max simrate to 8, decrease min FPS to 5

* chore: add changelog

* docs: also change max sim rate in provided example ini files
  • Loading branch information
lukecologne authored Nov 12, 2023
1 parent 9de8d52 commit 4b10ad4
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 191 deletions.
2 changes: 2 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
1. [MCDU] Dash alternate time predictions if alternate fuel is manually inserted @BravoMike99 (bruno_pt99)
1. [BLEED] Add Air starter unit to enable ground starts - @Maximilian-Reuter (\_Chaoz_)
1. [MCDU] FUEL PRED layout improvemnts @BravoMike99 (bruno_pt99)
1. [EFCS] Add precontrol to roll angle controller to improve dynamic response - @lukecologne (luke)
1. [EFCS] Increase maximum sim rate limit to 8 due to improvements in roll law stability - @lukecologne (luke)

## 0.11.0

Expand Down
2 changes: 1 addition & 1 deletion fbw-a32nx/docs/Configuration/ModelConfiguration.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

; !! WARNING CHANGE AT YOUR OWN RISK !!
; maximum allowed simulation rate
;maximum_simulation_rate = 4
;maximum_simulation_rate = 8

; !! WARNING CHANGE AT YOUR OWN RISK !!
; if enabled, limit simulation rate by performance
Expand Down
22 changes: 10 additions & 12 deletions fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ bool FlyByWireInterface::connect() {
// initialize flight data recorder
flightDataRecorder.initialize();



// connect to sim connect
bool success = simConnectInterface.connect(clientDataEnabled, autopilotStateMachineEnabled, autopilotLawsEnabled, flyByWireEnabled, elacDisabled,
secDisabled, facDisabled, throttleAxis, spoilersHandler, flightControlsKeyChangeAileron,
flightControlsKeyChangeElevator, flightControlsKeyChangeRudder,
disableXboxCompatibilityRudderAxisPlusMinus, enableRudder2AxisMode, idMinimumSimulationRate->get(),
idMaximumSimulationRate->get(), limitSimulationRateByPerformance);
bool success = simConnectInterface.connect(
clientDataEnabled, autopilotStateMachineEnabled, autopilotLawsEnabled, flyByWireEnabled, elacDisabled, secDisabled, facDisabled,
throttleAxis, spoilersHandler, flightControlsKeyChangeAileron, flightControlsKeyChangeElevator, flightControlsKeyChangeRudder,
disableXboxCompatibilityRudderAxisPlusMinus, enableRudder2AxisMode, idMinimumSimulationRate->get(), idMaximumSimulationRate->get(),
limitSimulationRateByPerformance);

// request data
if (!simConnectInterface.requestData()) {
Expand Down Expand Up @@ -207,7 +205,7 @@ void FlyByWireInterface::loadConfiguration() {
// --------------------------------------------------------------------------
// load values - autopilot
idMinimumSimulationRate->set(INITypeConversion::getDouble(iniStructure, "AUTOPILOT", "MINIMUM_SIMULATION_RATE", 1));
idMaximumSimulationRate->set(INITypeConversion::getDouble(iniStructure, "AUTOPILOT", "MAXIMUM_SIMULATION_RATE", 4));
idMaximumSimulationRate->set(INITypeConversion::getDouble(iniStructure, "AUTOPILOT", "MAXIMUM_SIMULATION_RATE", 8));
limitSimulationRateByPerformance = INITypeConversion::getBoolean(iniStructure, "AUTOPILOT", "LIMIT_SIMULATION_RATE_BY_PERFORMANCE", true);
simulationRateReductionEnabled = INITypeConversion::getBoolean(iniStructure, "AUTOPILOT", "SIMULATION_RATE_REDUCTION_ENABLED", true);

Expand Down Expand Up @@ -807,8 +805,6 @@ bool FlyByWireInterface::readDataAndLocalVariables(double sampleTime) {
simConnectInterface.setLoggingFlightControlsEnabled(idLoggingFlightControlsEnabled->get() == 1);
simConnectInterface.setLoggingThrottlesEnabled(idLoggingThrottlesEnabled->get() == 1);



// read data
if (!simConnectInterface.readData()) {
std::cout << "WASM: Read data failed!" << std::endl;
Expand Down Expand Up @@ -1332,7 +1328,8 @@ bool FlyByWireInterface::updateElac(double sampleTime, int elacIndex) {
if (elacIndex == 0) {
powerSupplyAvailable =
idElecDcEssBusPowered->get() ||
((elacsDiscreteOutputs[0].batt_power_supply || secsDiscreteOutputs[0].batt_power_supply) ? idElecBat1HotBusPowered->get() : false);
((elacsDiscreteOutputs[0].batt_power_supply || secsDiscreteOutputs[0].batt_power_supply) ? idElecBat1HotBusPowered->get()
: false);
} else {
bool elac1OrSec1PowersupplySwitched = elacsDiscreteOutputs[0].batt_power_supply || secsDiscreteOutputs[0].batt_power_supply;
bool elac2NormalSupplyAvail = idElecDcBus2Powered->get();
Expand Down Expand Up @@ -1504,7 +1501,8 @@ bool FlyByWireInterface::updateSec(double sampleTime, int secIndex) {
if (secIndex == 0) {
powerSupplyAvailable =
idElecDcEssBusPowered->get() ||
((secsDiscreteOutputs[0].batt_power_supply || elacsDiscreteOutputs[0].batt_power_supply) ? idElecBat1HotBusPowered->get() : false);
((secsDiscreteOutputs[0].batt_power_supply || elacsDiscreteOutputs[0].batt_power_supply) ? idElecBat1HotBusPowered->get()
: false);
} else {
powerSupplyAvailable = idElecDcBus2Powered->get();
}
Expand Down
2 changes: 1 addition & 1 deletion fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FlyByWireInterface {
private:
const std::string CONFIGURATION_FILEPATH = "\\work\\ModelConfiguration.ini";

static constexpr double MAX_ACCEPTABLE_SAMPLE_TIME = 0.11;
static constexpr double MAX_ACCEPTABLE_SAMPLE_TIME = 0.22;
static constexpr uint32_t LOW_PERFORMANCE_TIMER_THRESHOLD = 10;
uint32_t lowPerformanceTimer = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2699,7 +2699,7 @@ void SimConnectInterface::simConnectProcessEvent(const SIMCONNECT_RECV_EVENT* ev
// calculate frame rate that will be seen by FBW / AP
double theoreticalFrameRate = (1 / sampleTime) / (simData.simulation_rate * 2);
// determine if an increase of simulation rate can be allowed
if ((simData.simulation_rate < maxSimulationRate && theoreticalFrameRate >= 8) || simData.simulation_rate < 1 ||
if ((simData.simulation_rate < maxSimulationRate && theoreticalFrameRate >= 5) || simData.simulation_rate < 1 ||
!limitSimulationRateByPerformance) {
sendEvent(Events::SIM_RATE_INCR, 0, SIMCONNECT_GROUP_PRIORITY_DEFAULT);
std::cout << "WASM: Simulation rate " << simData.simulation_rate;
Expand Down
Loading

0 comments on commit 4b10ad4

Please sign in to comment.