Board index FlightGear Development Nasal

CitationX autopilot go to next waypoint

Nasal is the scripting language of FlightGear.

CitationX autopilot go to next waypoint

Postby SurferTim » Wed Dec 19, 2018 4:33 pm

I'm trying to remove a glitch from the CitationX autopilot. I hope this is the correct topic for this. I can use the menu "Autopilot -> Next Waypoint" to avoid the glitch, but would like the autopilot to do it automatically.

I want to detect when the aircraft is within a mile of the fix, and change to the next waypoint. I tried this but it doesn't work.
Code: Select all
    }elsif(NAVSRC == "FMS"){
        setprop("autopilot/internal/nav-type","FMS1");
        setprop("autopilot/internal/in-range",1);
        setprop("autopilot/internal/gs-in-range",0);
        setprop("autopilot/internal/nav-distance",getprop("instrumentation/gps/wp/wp[1]/distance-nm"));
        setprop("autopilot/internal/nav-id",getprop("instrumentation/gps/wp/wp[1]/ID"));
        course_offset("instrumentation/gps/wp/wp[1]/bearing-mag-deg");
        setprop("autopilot/internal/to-flag",getprop("instrumentation/gps/wp/wp[1]/to-flag"));
        setprop("autopilot/internal/from-flag",getprop("instrumentation/gps/wp/wp[1]/from-flag"));

#this is what I added
   var mydist=getprop("instrumentation/gps/wp/wp[1]/distance-nm");
   if(mydist < 1.0){
      var myfp=flightplan();
      myfp.nextWP();
   }
    }


Edit: Here is the wiki page I am using:
http://wiki.flightgear.org/Nasal_Flightplan
Fly low, fly slow, land on a dime. Twin Otter.
SurferTim
 
Posts: 88
Joined: Sun Dec 09, 2018 5:49 pm
Location: Miramar Beach, FL
Callsign: N2ST/Pirate
Version: 2018-3-1
OS: Ubuntu 18.04

Re: CitationX autopilot go to next waypoint

Postby legoboyvdlp » Wed Dec 19, 2018 5:39 pm

Could you be more specific as to what doesn't work? Is there an error reported?
User avatar
legoboyvdlp
 
Posts: 6652
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: CitationX autopilot go to next waypoint

Postby SurferTim » Wed Dec 19, 2018 6:19 pm

I've been playing with it a while. It won't go to the next waypoint at 0.9 miles or less. It goes completely to the waypoint.

Here is what I am using in flightdirector.nas to troubleshoot it.
As a global variable, I added this to keep the current waypoint
Code: Select all
var thiswp="";

In function update_nav
Code: Select all
    }elsif(NAVSRC == "FMS"){
        setprop("autopilot/internal/nav-type","FMS1");
        setprop("autopilot/internal/in-range",1);
        setprop("autopilot/internal/gs-in-range",0);
        setprop("autopilot/internal/nav-distance",getprop("instrumentation/gps/wp/wp[1]/distance-nm"));
        setprop("autopilot/internal/nav-id",getprop("instrumentation/gps/wp/wp[1]/ID"));
        course_offset("instrumentation/gps/wp/wp[1]/bearing-mag-deg");
        setprop("autopilot/internal/to-flag",getprop("instrumentation/gps/wp/wp[1]/to-flag"));
        setprop("autopilot/internal/from-flag",getprop("instrumentation/gps/wp/wp[1]/from-flag"));
# added this
   var mydist=getprop("instrumentation/gps/wp/wp[1]/distance-nm");
   if(mydist < 1.0){
      var myfp=flightplan();
      if(thiswp != myfp.nextWP().id){
         print("Here");
         print(myfp.getWP(myfp.current).id);
         print(myfp.nextWP().id);
         thiswp = myfp.nextWP().id;
         setprop("autopilot/internal/nav-id","myfp.nextWP().id");
      }
   }
    }

I get the correct responses, but it won't go to the next waypoint.
Fly low, fly slow, land on a dime. Twin Otter.
SurferTim
 
Posts: 88
Joined: Sun Dec 09, 2018 5:49 pm
Location: Miramar Beach, FL
Callsign: N2ST/Pirate
Version: 2018-3-1
OS: Ubuntu 18.04

Re: CitationX autopilot go to next waypoint

Postby SurferTim » Thu Dec 20, 2018 12:13 am

I found the solution. It is for a 727, but works splendid for the Citation-X.
Copy this code into a file named WaypointSmoothing.nas
https://github.com/FGMEMBERS/727-230/bl ... othing.nas
Copy that file into your Aircraft/CitationX/Nasal directory
Open the /Aircraft/CitationX/CitationX-set.xml and add this line
Code: Select all
<nasal>
        <citation>
            <file>Aircraft/CitationX/Nasal/CitationX.nas</file>
            <file>Aircraft/CitationX/Nasal/Electrical.nas</file>
            <file>Aircraft/CitationX/Nasal/flightdirector.nas</file>
#add the next line
            <file>Aircraft/CitationX/Nasal/WaypointSmoothing.nas</file>
            <file>Aircraft/Generic/limits.nas</file>
        </citation>
        <dialogs>
            <file>Aircraft/CitationX/Nasal/dialogs.nas</file>
        </dialogs>
    </nasal>

Done! No more glitches and smooth turns at waypoints just like the 777. Now for the vertical speed/altitude challenge.
Fly low, fly slow, land on a dime. Twin Otter.
SurferTim
 
Posts: 88
Joined: Sun Dec 09, 2018 5:49 pm
Location: Miramar Beach, FL
Callsign: N2ST/Pirate
Version: 2018-3-1
OS: Ubuntu 18.04


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest