Starter and Breaks Sevo Mapping in FlightGear/JSBSim

I am working to get the C172p JSBSim model working in Auto Flight mode. The problem I have is that when the C172p model is setup, its engine is not started. I would like to be able to use the servo-to-function mapping to tie a servo to the starter/ignition function as well as brakes release and possible flap control.

I have spent a good deal of time looking at the SIM_JSBSim.cpp./.h files and I can see where the servo data is sent from ArduPlane to the JSBSim in void JSBSim::send_servos(const struct sitl_input &input). But I don’t understand how this works… or how to map it to set fcs functions… or even if this is the right place to do it.

From what I understand, if in mavproxy I type rc 8 1900 I am guessing that this sets servo_8 to max PWM and this should eventually get sent to the send_servos method in the JSBSim interface files? Is this information then contained in the sitl_input struct? Or should I perhaps be using a relay rather than a servo?

Any help in posting me in the right direction would be most appreciated. Or… maybe this level of fidelity is not possible with JSBSim and FG?

Update on this… after spending a good deal of time with the code, I understand the servo mapping now. However, I can’t seem to access other servo data outside of the first 5 channels.

I have created a tuned ArduPlane parameter file that successfully flies the full-size C172P in JSBSim in auto mission mode with a modified electric motor. In the parameter file, I have mapped SERVO5_FUNCTION to the auto flaps function and SERVO6_FUNCTION to ground steering. I then added the following code to JSBSim::send_servos method:

    // NOTE channel mapping begins at 1
    char *buf = nullptr;
    float aileron  = filtered_servo_angle(input, 0); // SERVO1_FUNCTION (ch1)
    float elevator = filtered_servo_angle(input, 1); // SERVO2_FUNCTION (ch2)
    float throttle = filtered_servo_range(input, 2); // SERVO3_FUNCTION (ch3)
    float rudder   = filtered_servo_angle(input, 3); // SERVO4_FUNCTION (ch4)

    //printf("Input ail: %f elv %f thr %f rud %f\n", aileron, elevator, throttle, rudder);

    float auto_flaps = filtered_servo_range(input, 4); // SERVO5_FUNCTION (ch5)
    printf("Input flaps: %f \n", auto_flaps);

    float auto_steer = filtered_servo_angle(input, 5); // SERVO6_FUNCTION (ch6)
    printf("Input steer: %f \n", auto_steer);

The new extracted values are auto_flaps and auto_steer. The flaps servo is at offset 4 within the sitl_input struct and it appears to correctly output a flaps setting while flying based the LAND_FLAP_PERCNT, TKOFF_FLAP_PERCNT, FLAP_X_PERCNT, FLAP_X_SPEED ArduPlane parameter settings.

The problem I have is that the auto_steer call to filtered_servo_angle generates an error – PANIC: Attempt to filter invalid servo at offset 5. It appears that only the first five channels exist in the sitl_input struct and there is no channel 6 (offset 5). The JSBSim::send_servos method is called from JSBSim::update which takes the sitl_input struct from its caller. This struct looks like this:

struct sitl_input {
    uint16_t servos[32];
    struct {
        float speed;      // m/s
        float direction;  // degrees 0..360
        float turbulence;
        float dir_z;	  //degrees -90..90
    } wind;

This struct is supposed to contain 32 values in the servos array. So it would seem that floats should exist at offsets 4 (ch5) and 5 (ch6).

I am not sure who calls JSBSim::update outside of the SIM_JSBSim.cpp file or where the sitl_input is populated. I am also not sure why the error says the servo value is “invalid” as opposed to some kind of access violation. What am I missing? Any help would be appreciated.