• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Controlling rudder, flaps, etc on AI aircraft

Messages
26
Country
netherlands
Hi,
I'm progressing quite nicely on my project and can now create AI aircraft, give them a location, and (mostly) control the lights. Next bit are the control surfaces. Monitoring the user aircraft to get the data was not a big problem, although the "Position" type returned not a value from -16K to +16K as the SimConnect docs describe, but rather a FLOAT between -1.0 and 1.0.

Trying to set the "RUDDER POSITION" or "RUDDER PEDAL POSITION" and such got me a load of "Generic Data Error" exceptions. My Data Definition is:
Code:
        aircraftControlsData_.clear();
        aircraftControlsData_.add(DATAID_CONTROL_RUDDER, "RUDDER PEDAL POSITION", "Position", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_ELEVATOR, "ELEVATOR POSITION", "Position", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_AILERON, "AILERON POSITION", "Position", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_TRIM_RUDDER, "RUDDER TRIM PCT", "Percent over 100", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_TRIM_ELEVATOR, "ELEVATOR TRIM PCT", "Percent over 100", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_TRIM_AILERON, "AILERON TRIM PCT", "Percent over 100", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_SPOILERS, "SPOILERS HANDLE POSITION", "Position", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_FLAPS_HANDLE, "FLAPS HANDLE PERCENT", "Percent over 100", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_PARKING_BRAKE, "BRAKE PARKING POSITION", "Position", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_PRIMARY_DOOR, "EXIT OPEN:1", "Percent over 100", SIMCONNECT_DATATYPE_FLOAT64);
        aircraftControlsData_.add(DATAID_CONTROL_GEARS_HANDLE, "GEAR HANDLE POSITION", "Bool", SIMCONNECT_DATATYPE_INT32);
        mgr.defineData(aircraftControlsData_, [=](const void* data, const SimConnectData& dataDef) {
            switch (dataDef.id) {
            case DATAID_CONTROL_RUDDER: aircraftControls_.rudderPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_ELEVATOR: aircraftControls_.elevatorPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_AILERON: aircraftControls_.aileronPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_TRIM_RUDDER: aircraftControls_.rudderTrimPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_TRIM_ELEVATOR: aircraftControls_.elevatorTrimPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_TRIM_AILERON: aircraftControls_.aileronTrimPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_SPOILERS: aircraftControls_.spoilersPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_FLAPS_HANDLE: aircraftControls_.flapsPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_PARKING_BRAKE: aircraftControls_.parkingBrakePos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_PRIMARY_DOOR: aircraftControls_.doorPos = *static_cast<const double*>(data); break;
            case DATAID_CONTROL_GEARS_HANDLE: aircraftControls_.gearsDown = *static_cast<const int32_t*>(data); break;
            default: LOG4CPLUS_ERROR(log_, "[aircraftControlsDataItemCallback](): Unknown dataId " << dataDef.id); break;
            }
            return true;
        }, [=](int entryNr, int outOfNr, size_t size, const SimConnectDataDefinition* dataDef) {
            LOG4CPLUS_TRACE(log_, "[aircraftControlsDataCompleteCallback](): Data block complete.");
            api_.sendData(aircraftControls_);
            return true;
        });

When I tried to just set Flaps and Rudder with "FLAPS_SET" and "RUDDER_SET" events instead, I found out their parameters are DWORDS, so they can't take negative values.

Any hints?

Bert
 

ddawson

Resource contributor
Messages
862
Country
canada
Try using the events anyway. Just pass in the negative values when required.
The function prototype in gauges.h is
ERR (FSAPI *trigger_key_event) ( ID32 event_id, UINT32 value );
Theoretically the same issue would apply here, but the function will happily accept negative values.
 
Messages
26
Country
netherlands
Ok, that appears to do the trick. Value is indeed -16384..16383 for events which can take negative values, 0..16383 for FLAPS_SET and SPOILERS_SET, 0 or 1 for GEARS_SET.

The negative values will work if you make sure they're two's complement signed values, so 0x00003fff is 16383, 0xffffc000 is -16384. Simply passing them will work in both C and C++. The door appearently only has a toggle. (TOGGLE_AIRCRAFT_EXIT)

Thanks.

[EDIT was being paranoid about C++. negative values will be assigned without conversion and thus work]
 
Last edited:
Top