Board index FlightGear Development Aircraft Autopilot and route manager

kap140 setlistener

Designing a stable autopilot is one of the hardest things. Need help?

kap140 setlistener

Postby gkick » Thu Mar 30, 2017 7:26 pm

Hi all,
What would the nasal code look like for activating the hold alt property once the preset altitude has been reached ?
Thanks for your thoughts
gk
gkick
 
Posts: 106
Joined: Sun Jan 01, 2017 11:04 pm

Re: kap140 setlistener

Postby Octal450 » Fri Mar 31, 2017 3:28 am

Hi
I've achieved this in my IT-AUTOFLIGHT system by listening for altitude whenever the aircraft is in a V/S, FLCH, or similar modes

It has different capture times for higher VS speeds, and lower, but you could remove that and use fixed numbers.

To make it start checking, execute altcaptt.start();
You should run a altcaptt.stop(); when capturing happens, as you can see below.
NOTE: I don't put it there in ITAF, because other code stops it for me.

Code: Select all
var altcapt = func {
   var vsnow = getprop("/it-autoflight/internal/vert-speed-fpm"); # this stuff is for capturing earlier at higher VS's.
   if ((vsnow >= 0 and vsnow < 500) or (vsnow < 0 and vsnow > -500)) {
      setprop("/it-autoflight/internal/captvs", 100);
      setprop("/it-autoflight/internal/captvsneg", -100);
   } else  if ((vsnow >= 500 and vsnow < 1000) or (vsnow < -500 and vsnow > -1000)) {
      setprop("/it-autoflight/internal/captvs", 150);
      setprop("/it-autoflight/internal/captvsneg", -150);
   } else  if ((vsnow >= 1000 and vsnow < 1500) or (vsnow < -1000 and vsnow > -1500)) {
      setprop("/it-autoflight/internal/captvs", 200);
      setprop("/it-autoflight/internal/captvsneg", -200);
   } else  if ((vsnow >= 1500 and vsnow < 2000) or (vsnow < -1500 and vsnow > -2000)) {
      setprop("/it-autoflight/internal/captvs", 300);
      setprop("/it-autoflight/internal/captvsneg", -300);
   } else  if ((vsnow >= 2000 and vsnow < 3000) or (vsnow < -2000 and vsnow > -3000)) {
      setprop("/it-autoflight/internal/captvs", 450);
      setprop("/it-autoflight/internal/captvsneg", -450);
   } else  if ((vsnow >= 3000 and vsnow < 4000) or (vsnow < -3000 and vsnow > -4000)) {
      setprop("/it-autoflight/internal/captvs", 650);
      setprop("/it-autoflight/internal/captvsneg", -650);
   } else  if ((vsnow >= 4000 and vsnow < 5000) or (vsnow < -4000 and vsnow > -5000)) {
      setprop("/it-autoflight/internal/captvs", 1000);
      setprop("/it-autoflight/internal/captvsneg", -1000);
   } else  if ((vsnow >= 5000) or (vsnow < -5000)) {
      setprop("/it-autoflight/internal/captvs", 1250);
      setprop("/it-autoflight/internal/captvsneg", -1250);
   }
   var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
   var alt = getprop("/it-autoflight/internal/alt");
   var dif = calt - alt; # Finds the different between current and target altitude
   if (dif < getprop("/it-autoflight/internal/captvs") and dif > getprop("/it-autoflight/internal/captvsneg")) { # If the conditions are met, capture altitude
      # Put in these brackets the functions which switch to ALT HLD
      altcaptt.stop(); # Stop checking altitude capture
   }
}

var altcaptt = maketimer(0.5, altcapt);


Here is a simple version with fixed altitude difference numbers for capturing:

Code: Select all
var altcapt = func {
   var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
   var alt = getprop("/it-autoflight/internal/alt");
   var dif = calt - alt; # Finds the different between current and target altitude
   if (dif < 500 and dif > -500) { # If the conditions are met, capture altitude
      # Put in these brackets the functions which switch to ALT HLD
      altcaptt.stop(); # Stop checking altitude capture
   }
}

var altcaptt = maketimer(0.5, altcapt);


EDIT: replace /it-autoflight/internal/alt with your AP altitude property

Hope that helps!

Kind Regards,
Josh
Waste of time. Goodbye forever.
Octal450
 
Posts: 4398
Joined: Tue Oct 06, 2015 12:51 pm

Re: other set listener

Postby gkick » Sat Apr 01, 2017 8:19 pm

Hi Josh,

I am curently remodeling the Cherokee cockpit for my desire to learn about navigation. Almost complete with instruments from all over the place, however going in circles with the last one, ok second last one.

I hope you do not mind me asking for your advise .

I am using the ki227-228 RMI, have implemented a switch to show or hide the vor needle, that part works fine.

I also have another switch which is designed to switch between nav1 and nav0 for the DME and the RMI. The DME part works, but I am stuck with some code I do not understand, end up with nasal parse errors or nothing happens.

There are three parts supposed to make this happen.

First there is the switch toggling vor-bearing-source value 0 or 1, that works fine.
Second there is a listener code for the pa28-161.set like

setlistener( "/instrumentation/ki227/vor-bearing-source", func(node) {
var num = node.getValue();
props.globals.getNode("/instrumentation/ki227/vor-bearing-deg").alias("/instrumentation/nav["~ num ~"]/vor-bearing-source"]/radials/reciprocal-radial-deg");
});

and lastly in the ki227-228.xml the parameter line

<vor-bearing-deg>instrumentation/nav[0]/radials/reciprocal-radial-deg</vor-bearing-deg>

needs to be changed to use the value of the listener, something like this -

<!-- <vor-bearing-deg>/instrumentation/ki227/nav[vor-bearing-source]/radials/reciprocal-radial-deg</vor-bearing-deg> -->

Would you by any chance be able to have a look at this if I send you the aircraft?

Thanks a lot

Gerhard
gkick
 
Posts: 106
Joined: Sun Jan 01, 2017 11:04 pm

Re: kap140 setlistener

Postby Octal450 » Sun Apr 02, 2017 2:56 am

No problem!
That's what we are here for.

I'd be happy to take a look at it and see if I can find the problem.

Josh
Waste of time. Goodbye forever.
Octal450
 
Posts: 4398
Joined: Tue Oct 06, 2015 12:51 pm

Re: kap140 setlistener

Postby gkick » Sun Apr 02, 2017 11:25 am

Thank you Josh, much appreciated.
Here she is https://www.dropbox.com/s/1kqanmbaqdwpm ... 1.rar?dl=0
She is a bit of a mess and needs to be cleaned up, cases in particular.
cheers
Gerhard
gkick
 
Posts: 106
Joined: Sun Jan 01, 2017 11:04 pm

Re: kap140 setlistener

Postby Octal450 » Sun Apr 02, 2017 2:34 pm

OK I'll take a look.
I'll let you know what fixes it!

Josh
Waste of time. Goodbye forever.
Octal450
 
Posts: 4398
Joined: Tue Oct 06, 2015 12:51 pm

Re: kap140 setlistener

Postby Octal450 » Mon Apr 03, 2017 8:57 pm

OK, I finally found some time test. First issue: http://prntscr.com/es2qn3

I don't have that aircraft. Can you send the dme instrument?
Waste of time. Goodbye forever.
Octal450
 
Posts: 4398
Joined: Tue Oct 06, 2015 12:51 pm

Re: kap140 setlistener

Postby gkick » Mon Apr 03, 2017 11:22 pm

Thanks Josh, here are the files

https://www.dropbox.com/s/ykh64gohlyjna ... a.rar?dl=0

cheers
G
gkick
 
Posts: 106
Joined: Sun Jan 01, 2017 11:04 pm

Re: kap140 setlistener

Postby Octal450 » Tue Apr 04, 2017 1:12 am

Thanks

BTW, the altitude capturing works fine on the AP, but it doesn't fly so nicely. I'm going to tune the AP slightly if you don't mind.

I found the instrument, and ported it into the pa28 plane, so it should be fine.
Waste of time. Goodbye forever.
Octal450
 
Posts: 4398
Joined: Tue Oct 06, 2015 12:51 pm

Re: kap140 setlistener

Postby gkick » Tue Apr 04, 2017 8:48 am

yep, the AP is weird, on takeoff can climb up to 2000fpm or more and stall, if you cruise and turn it off the plane goes up like a rocket yet I like the plane because it has lots of room on the panel for big size instruments, so you need not zoom in and out constantly and when turning the panel does not jump about the screen like other small crafts.

Just want to adapt her into a pure Navigator with tutorials because I found most of the small crafts have insufficient and many non working instruments.
For example so far I have not found a working version of the kcs55 HSI other then in the Seneca which has a beautiful cockpit. By the way I could not figure out how to make the glideslope work on the kcs, something to do with the properties of the ki525a, but can do without as the vor is on the left side..
Also scouring for some sort of dome light with a dimmer since she is a bit dark at night.

You might want to take her for a ride from Memmingen (EDJA) to Innsbruck (LOWI) via NDB RTT and NDB Absams. Have taken the 777 there once, brought her down in one piece but not on the runway.
Anyway thanks again for your help

G
gkick
 
Posts: 106
Joined: Sun Jan 01, 2017 11:04 pm


Return to Autopilot and route manager

Who is online

Users browsing this forum: No registered users and 1 guest

cron