flybywiresim / aircraft

The A32NX & A380X Project are community driven open source projects to create free Airbus aircraft in Microsoft Flight Simulator that are as close to reality as possible.
https://flybywiresim.com
GNU General Public License v3.0
5.14k stars 1.12k forks source link

Mach var restricted by airspeed var #8294

Closed rthom91 closed 2 days ago

rthom91 commented 1 year ago

Aircraft Version

Stable

Build info

{
    "built": "2023-11-03T17:47:36+00:00",
    "ref": "refs/tags/v0.11.1",
    "sha": "f055eb02dc0af32441f8b2873f58e8316d7ca638",
    "actor": "Saschl",
    "event_name": "manual",
    "pretty_release_name": "stable/v0.11.1",
    "version": "v0.11.1-rel.f055eb0"
}

Describe the bug

AUTOPILOT MACH HOLD VAR is being held back by AUTOPILOT AIRSPEED HOLD VAR. MACH does not drop below 0.15 (100 knots) or higher than 0.61 (399 knots).

Expected behavior

MACH simvar should go to 0.10 min and 0.99 max.

Steps to reproduce

https://www.youtube.com/watch?v=SxHnrRToAeA

References (optional)

No response

Additional info (optional)

No response

Discord Username (optional)

No response

ArtemisPlayer commented 11 months ago

It looks like the issue has already been solved in the dev version. Microsoft Flight Simulator Screenshot 2023 12 07 - 15 55 44 85

Maximilian-Reuter commented 11 months ago

It looks like the issue has already been solved in the dev version. Microsoft Flight Simulator Screenshot 2023 12 07 - 15 55 44 85

Did you check the Simvars in question ? seeing as the issue wasnt what the FCU shows but what is written to the Simvar which can be seen in the tooltips

ArtemisPlayer commented 11 months ago

Mea culpa, it looks like the mach value is converted to speed before being given to the AP. Edit: I am working on it

ArtemisPlayer commented 11 months ago

Hey ! I am trying to solve the issue, at first it looks simple: I can change this part of the code (fbw-a32nx\src\base\flybywire-aircraft-a320-neo\html_ui\Pages\VCockpit\Instruments\Airliners\FlyByWire_A320_Neo\FCU\A320_Neo_FCU.js):

            // get current target speed
            let targetSpeed = (isMachActive || this.selectedValue < 1)
                ? SimVar.GetGameVarValue("FROM MACH TO KIAS", "number", this.selectedValue)
                : this.selectedValue;
            // clamp speed into valid range
            targetSpeed = this.clampSpeed(targetSpeed);
            // set target speed
            if (targetSpeed !== this.targetSpeed) {
                Coherent.call("AP_SPD_VAR_SET", 0, targetSpeed).catch(console.error);
                this.targetSpeed = targetSpeed;
            }
            // detect mismatch
            if (Simplane.getAutoPilotAirspeedHoldValue() !== this.targetSpeed) {
                Coherent.call("AP_SPD_VAR_SET", 0, targetSpeed).catch(console.error);
            }

into

            if (isMachActive || this.selectedValue < 1){
                targetMach = this.clampMach(this.selectedValue); // clamp into valid range
                if (targetMach !== this.targetMach) {
                    // set target mach
                    Coherent.call("AP_MACH_VAR_SET", 0, Math.round(targetMach * 100).catch(console.error));
                    this.targetMach = targetMach;
                }
                if (Simplane.getAutoPilotMachHoldValue() !== this.targetMach) {
                    Coherent.call("AP_MACH_VAR_SET", 0, Math.round(targetMach * 100).catch(console.error));
                }
            } else {
                targetSpeed = this.clampSpeed(this.selectedValue); // clamp into valid range
                if (targetSpeed !== this.targetSpeed) {
                    // set target speed
                    Coherent.call("AP_SPD_VAR_SET", 0, targetSpeed).catch(console.error);
                    this.targetSpeed = targetSpeed;
                }
                // detect mismatch
                if (Simplane.getAutoPilotAirspeedHoldValue() !== this.targetSpeed) {
                    Coherent.call("AP_SPD_VAR_SET", 0, targetSpeed).catch(console.error);
                }
            }

(the mach is multiplied by 100 as indicated here : https://docs.flightsimulator.com/html/Programming_Tools/Event_IDs/Aircraft_Autopilot_Flight_Assist_Events.htm)

But that makes the module crash (only dashed lines). I have some beginner's questions:

Thanks for any help !

EDIT: the idea is to not convert mach into speed before sending it to the autopilot, so it does clamp the value to knots limits.

lukecologne commented 11 months ago

Mea culpa, it looks like the mach value is converted to speed before being given to the AP. Edit: I am working on it

Correct, the AP currently only uses AUTOPILOT AIRSPEED HOLD VAR, which is set by the FCU converted from the selected mach. Anyways, the current legacy FCU is planned to be replaced by a totally new implementation with #7587, which will then also no longer use the sim's default AP variables.

EDIT: the idea is to not convert mach into speed before sending it to the autopilot, so it does clamp the value to knots limits.

This will not work, we use our own AP which, as I said, currently just reads the sim's default variables. It expects to receive the speed target in CAS. (Note, this is not correct IRL, where the FCU will send selected mach and CAS seperately as A429 words, but that is not currently implemented, and will be corrected in #7587.)

Maximilian-Reuter commented 11 months ago

Mea culpa, it looks like the mach value is converted to speed before being given to the AP. Edit: I am working on it

Correct, the AP currently only uses AUTOPILOT AIRSPEED HOLD VAR, which is set by the FCU converted from the selected mach. Anyways, the current legacy FCU is planned to be replaced by a totally new implementation with #7587, which will then also no longer use the sim's default AP variables.

EDIT: the idea is to not convert mach into speed before sending it to the autopilot, so it does clamp the value to knots limits.

This will not work, we use our own AP which, as I said, currently just reads the sim's default variables. It expects to receive the speed target in CAS. (Note, this is not correct IRL, where the FCU will send selected mach and CAS seperately as A429 words, but that is not currently implemented, and will be corrected in #7587.)

So that effectively means, that these simvars will be useless once that implementation comes into effect ? If so then this is a "Not planned" then right ?

lukecologne commented 11 months ago

So that effectively means, that these simvars will be useless once that implementation comes into effect ?

Yep, they won't be used anymore and possible not even exist (since I might completely disable the sim AP in the configs, which might result in these not being defined by the sim anymore).

If so then this is a "Not planned" then right ?

The PR is still some time away. Should this be needed for some reason, then I don't see why this couldn't get a fix if it's not too big.

tracernz commented 11 months ago

Yep, they won't be used anymore and possible not even exist (since I might completely disable the sim AP in the configs, which might result in these not being defined by the sim anymore).

We should look into using the managed mode so we can override the vars, for the benefit of third party tools.