Board index FlightGear Support Interfacing

Pressing a key (start) through network for some seconds

Connecting two computers, using generic protocol, connecting with Matlab?

Pressing a key (start) through network for some seconds

Postby vanosten » Sun Mar 17, 2019 8:07 am

Hi

I try to control a plane through Telnet/httpd. A lot of propeller planes require pressing 's' for a few seconds to start the motor. Is there a trick to press the key through properties or Nasal for a amount of time?

I can do
Code: Select all
props.runBinding(props.getNode(sprintf("/input/keyboard/key[%i]/binding", keyValue)));
, but that does not press they key long enough.
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 416
Joined: Sat Sep 25, 2010 5:38 pm
Location: Denmark - but I am Swiss
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Pressing a key (start) through network for some seconds

Postby wkitty42 » Sun Mar 17, 2019 1:26 pm

can you wrap that in a timer so it is pressed for long enough and then released when the engine starts? i think engine running indication is another property? probably depends on the craft, though...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5700
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Pressing a key (start) through network for some seconds

Postby vanosten » Sat Mar 23, 2019 7:35 am

I would be glad for some example code. As far as I understand maketimer() in Nasal just repeatedly calls a method at intervalls - or should I just call this for let's say 100 times with a 0.1 interval?
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 416
Joined: Sat Sep 25, 2010 5:38 pm
Location: Denmark - but I am Swiss
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Pressing a key (start) through network for some seconds

Postby Parnikkapore » Sat Mar 23, 2019 10:57 am

You'd call the script to set the property to 0 in say 3 secs (interval of 3s) then shut it off immediately in the same function.
There are free alternatives to every program you encounter. You just have to find them.
Parnikkapore
 
Posts: 818
Joined: Thu Oct 29, 2015 10:16 am
Callsign: HS-FGS
Version: next [PPA]
OS: Mint 18

Re: Pressing a key (start) through network for some seconds

Postby vanosten » Mon Mar 25, 2019 7:29 pm

I still do not get it. maketimer will just call the method every x interval - it will not magically execute the method content in three seconds. So somehow the key binding must be able to simulate key up and key down - but how?
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 416
Joined: Sat Sep 25, 2010 5:38 pm
Location: Denmark - but I am Swiss
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Pressing a key (start) through network for some seconds

Postby wlbragg » Mon Mar 25, 2019 10:00 pm

What about executing an autostart aircraft side? Or are you adamant about transferring a command that is setting the s-key down?

This is the starter code in the c172p
Code: Select all
# key 's' calls to this function when it is pressed DOWN even if I overwrite the binding in the -set.xml file!
# fun fact: the key UP event can be overwriten!
controls.startEngine = func(v = 1) {
    # Only operate in non-walker mode ('s' is also bound to walk-backward)
    var view_name = getprop("/sim/current-view/name");
    if (view_name == getprop("/sim/view[110]/name") or view_name == getprop("/sim/view[111]/name")) {
        return;
    }
    if (getprop("/engines/active-engine/running"))
    {
        setprop("/controls/switches/starter", 0);
        return;
    }
    else {
        setprop("/controls/switches/magnetos", 3);
        setprop("/controls/switches/starter", v);
    }
};


This is the pertinent autostart code
Code: Select all
var autostart = func (msg=1) {
    if (getprop("/engines/active-engine/running")) {
        if (msg)
            gui.popupTip("Engine already running", 5);
        return;
    }

    # Reset battery charge and circuit breakers
    electrical.reset_battery_and_circuit_breakers();

    # Filling fuel tanks
    setprop("/consumables/fuel/tank[0]/selected", 1);
    setprop("/consumables/fuel/tank[1]/selected", 1);

    # Setting levers and switches for startup
    setprop("/controls/switches/magnetos", 3);
    setprop("/controls/engines/current-engine/throttle", 0.2);

    var auto_mixture = getprop("/fdm/jsbsim/engine/auto-mixture");
    setprop("/controls/engines/current-engine/mixture", auto_mixture);

    setprop("/controls/flight/elevator-trim", 0.0);
    setprop("/controls/switches/master-bat", 1);
    setprop("/controls/switches/master-alt", 1);
    setprop("/controls/switches/master-avionics", 1);

    # Checking for minimal fuel level
    var fuel_level_left  = getprop("/consumables/fuel/tank[0]/level-norm");
    var fuel_level_right = getprop("/consumables/fuel/tank[1]/level-norm");

    if (fuel_level_left < 0.25)
        setprop("/consumables/fuel/tank[0]/level-norm", 0.25);
    if (fuel_level_right < 0.25)
        setprop("/consumables/fuel/tank[1]/level-norm", 0.25);

    setprop("/controls/engines/engine[0]/primer-lever", 0);
    setprop("/controls/engines/engine/primer", 3);

    # All set, starting engine
    setprop("/controls/switches/starter", 1);
    setprop("/engines/active-engine/auto-start", 1);

    var engine_running_check_delay = 5.0;
    settimer(func {
        if (!getprop("/engines/active-engine/running")) {
            gui.popupTip("The autostart failed to start the engine. You must lean the mixture and start the engine manually.", 5);
        }
        setprop("/controls/switches/starter", 0);
        setprop("/engines/active-engine/auto-start", 0);
    }, engine_running_check_delay);

};


Maybe some of this can help.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4915
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest