Jump to content

KK's Airplane Autopilot V2


Kartoffelkuchen
 Share

Recommended Posts

4uQ0Ngo.png

Features

  • Speed control
  • Maintain altitude
  • Maintain heading
  • Maintain climbrate
  • Autonomous takeoff
  • Autonomous landing
  • Fly a pre-programmed route
  • Fly to a pre-programmed waypoint
  • Also works in FAR

What it is

This is a project I've been working on forever. Programming an atmospheric autopilot can be very, very hard, but I've came up with an acceptable result, at least in my eyes, and wanted to let you guys be able to check it out! There is much to be optimized which I will do in the future as well as add new features, but for now, the results were quite good in my opinion, which is why I'm releasing it now.

Installation

  1. Install kOS https://github.com/KSP-KOS/KOS/releases
  2. Download the script https://spacedock.info/mod/2346/KK's Airplane Autopilot
  3. Put all the files inside your KSP Main/Ships/Script folder

How to use

  1. Attach a kOS unit to your aircraft
  2. If your craft has thrust reversers, put them on action group 4
  3. Launch the craft
  4. Open the kOS terminal
  5. Enter the following: switch to 0. run auto307.
  6. Once the gui is built, you can hop into the settings menu and adjust all your parameters there. For some more detailed information, you can also hop into the script, I've added some comments there explaining the different variables, but it should be pretty much self-explanatory. You can also choose to add a new "airplane" to the database, simply copy an existing one (do not copy the last aircraft, copy one of the first) and adjust the parameters.
  7. Enjoy!

To create new waypoints, simply copy an existing one (best if you copy the first one), give it a new name and enter it's latlng position. You can do this two ways: log the current geoposition of your craft to a file and then copy the logged coordinates into the waypoint OR enter the coordinates from the cheat menu "Set position".

The same procedure for navigation / flyroute mode. Copy an existing one, add the waypoints and end with a runway.

 

This script could be extremely handy for career mode where you have to fly to certain waypoints, gather some data etc. Now you can just enter the heading you need to fly to, select the speed and altitude and lean back!

 

Bus / Known issues:

  • You might see some severe wobble / oscillation of the craft shortly after you activate a mode for the first time. The script will automatically try to reduce the oscillation but this might take a few seconds. If the oscillation is really bad, try to reduce control authority on the rudders in the beginning and steadily increase it.

 

Some more action:

 

@Mods, I hope this is considered to be an Addon and thus is in the right subforum!

   

 

 

Edited by Kartoffelkuchen
Link to comment
Share on other sites

Wow... this looks kewl... A nice way for peeps to dip a toe into kOS, without having to use the kOS terminal and scripting for *everything*? vOv

Hmmm... I imagine this could be adapted easily for use with ground vehicles/rovers, as well as naval craft?

Could this also be easily adapted for use with waypoint addons? ie Waypoint Manager, NavUtilities, etc...??

@Kartoffelkuchen

Edited by Stone Blue
Link to comment
Share on other sites

@Cataclism Wow that review from @Kottabos is awesome, never expected that! :O

@Stone Blue It's fairly easy, just open your standard editor and start coding away. Language isn't too hard since it's based on english.

Yes, this can be easily adapted for ground use. I actually have already made a ground based mode for taxiing and stuff, I'll include that later. As far as integration with other mods is concerned, I think this would actually need to be a real plugin, but I have no experiences with such so far.

@shdwlrd What do you mean with PA? :)

Link to comment
Share on other sites

This is great, got me to actually use kOS since it first came out.   Could you explain a few of the settings?     

Height?  

for thr rev. I assume 1 means true and 0 for false  (ie  On and Off)       Most are self explanatory but I'm probably over-thinking the rest of them.

 

Link to comment
Share on other sites

On 2/28/2020 at 9:02 PM, shdwlrd said:

One way to get me to actually use K-os. Real cool work, may I suggest looking at PA to see how the PIDs were implemented. 

Sure I can have a look at it, though I think my PIDs are well tuned now. And as far as I understand PA also has trouble with over- and undercorrecting due to control authority on the aircraft. :)

@Noir Thank You so much, I love to hear that!

@rottielover Height means the altitude above ground the kOs unit is reading in the takeoff / landing configuration (so with gear extended, it's the altitude from the command module). You can get a good value by typing "print alt:radar." in the console and just add 0.5-3m to that numer, depending on your aircrafts size. Just keep in mind, too high value means that the plane will come in higher than it should (because the ap thinks it's lower than it actually is) while too low means that if you have a certain pitch angle at landing you might actually crash into the ground because the cockpit is higher up than the landinh gear.

Yes, for thr reverse and landingabort, this is correct. Should probably make them switch-like.

I will write up a more in depth-guide on how to use and how it works but that will take some time.


I'm looking forward to further feedback!

Link to comment
Share on other sites

3 hours ago, Kartoffelkuchen said:

And as far as I understand PA also has trouble with over- and undercorrecting due to control authority on the aircraft.

Nah, I use it all the time. The only times I've seen it flake out is when your plane is stalling and can't recover. (Which at that point, you shouldn't be using an auto-pilot anyways.) I do admit you do have to do some tuning for various conditions and craft though.

BTW, can you tune the script to various different crafts? 

Link to comment
Share on other sites

  • 2 weeks later...
13 hours ago, aisored224 said:

Yes, and that appears to work. Or, at least, it doesn't give me an error message.

Is the file located inside your "KSP Main/Ships/Script" folder?

You could also try to delete kOS and the script folder, reinstall kOS, fire up KSP once and then copy auto260.ks into the Script folder.

Edited by Kartoffelkuchen
Link to comment
Share on other sites

@shdwlrd The main difference between Pilot Assistant and this is that I made a kOS script, not an external plugin. This means that the script, due to kOS limitations, will run at a significantly lower rate than PA would do, due to kOS limited "processor speed". It can o be increased, but I didn't want to make that step for now.

This runtime difference means that it is much harder for the script to compensate, from the time it sees that the aircraft is exceeding it's target pitch rate (for example) until it does something to correct for it, up to 0.2seconds pass by. That makes it quite complicated to properly tune a PID, since a LOT can happen between each "run" in .2s, especially with very sensitive aircrafts.

I think I've done a fairly good job at implementing this for now, there's much to be streamlined and optimized, but I think results are good enough. 

For a real step-up, I will have to look at properly implementing this as a plugin though and my experiences with coding a  plugin are marginal for now, so that will take some time.

Link to comment
Share on other sites

47 minutes ago, Kartoffelkuchen said:

@shdwlrd The main difference between Pilot Assistant and this is that I made a kOS script, not an external plugin. This means that the script, due to kOS limitations, will run at a significantly lower rate than PA would do, due to kOS limited "processor speed". It can o be increased, but I didn't want to make that step for now.

This runtime difference means that it is much harder for the script to compensate, from the time it sees that the aircraft is exceeding it's target pitch rate (for example) until it does something to correct for it, up to 0.2seconds pass by. That makes it quite complicated to properly tune a PID, since a LOT can happen between each "run" in .2s, especially with very sensitive aircrafts.

I think I've done a fairly good job at implementing this for now, there's much to be streamlined and optimized, but I think results are good enough. 

For a real step-up, I will have to look at properly implementing this as a plugin though and my experiences with coding a  plugin are marginal for now, so that will take some time.

I wasn't trying to compare a Kos script to a .DLL plugin. I was just curious if the could tune the PID's and max limits to different crafts. The planes I make are stable, but some are underpowered. They can't do high amounts of positive pitch for very long before stalling. I was planning to using it to send planes to a set of coordinates and have it land near by.

That is kind of moot at the moment, I'm getting errors left and right with Kos. I haven't had time to scour the Kos threads for the wiki to see if it's a bad install or just user error. 

Link to comment
Share on other sites

8 hours ago, shdwlrd said:

I wasn't trying to compare a Kos script to a .DLL plugin. I was just curious if the could tune the PID's and max limits to different crafts. The planes I make are stable, but some are underpowered. They can't do high amounts of positive pitch for very long before stalling. I was planning to using it to send planes to a set of coordinates and have it land near by.

That is kind of moot at the moment, I'm getting errors left and right with Kos. I haven't had time to scour the Kos threads for the wiki to see if it's a bad install or just user error. 

Yeah sure if you open the "Settings" Tab of the gui, you can adjust things like "max pitch, roll angle, min speed, max speed" there when in flight OR you can create a profile for your own plane in the database.ks script so you don't have to adjust things every time (see step 6 of how to use).

Edited by Kartoffelkuchen
Link to comment
Share on other sites

After reviewing how to use Kos, I actually got to test it. It works pretty good, but there are some oddities. I'll need to run the scenarios over again to see if it will preform the same.

But I do have a couple suggestions. 

Add in holding patterns near the KSC and desert runway. That way you can guide planes into the pattern from anywhere and then do the landing approaches from there. Also, if there is missed landing, the ap can directly fly you back to the pattern to try again.

Add a check see if the SAS is on and turn it off. If the SAS is on, the ap won't take control of the plane.

Edited by shdwlrd
adding info
Link to comment
Share on other sites

  • 4 weeks later...

Hey! I've been testing this 'mod' with FAR for a while now, and while it works for the basic features (I'm damm impressed by that, even havign a custom UI with kOS is crazy!) it does have a few problems:

- While the oszilation dampening for the pitch control works I'm experienceing low frequency oszilations when using the autoland function. These oszialtions are so bad that the plane slams into the ocean or the landing lights before even reaching the runway. This seems to happen with planes of any size. 

- Landing speeds aren't customizable leading to stalls on most planes since FAR requires higher speeds. 

- the custom UI stays visible when switching to another vessel which leads to screen clutter when using multiple vessels.

- Waypoint mode leads to my plane just diving into the ground

-  This is a kOS problem, the pilot doesn't work with SAS enabled, so it would be useful if SAS was automatically disabled when the pilot is on

- This is just a suggestion but maybe add a boot scrip that can be selected in the hangar so the autopilot is ready to go when the vessel loads

-Another suggestion, add a bank angle mode. I frequently need a plane to just fly in large circles and this would be really helpful

Keep up the great work!
-HB

 

Edit: It would also be really cool to have a feature where the plane is placed at the intended touch-down spot with the right heading and then this info can be put into the autopilot to generate an approach path that can be later used to automatically land at this destination.

 

Edit 2: I'm also facing a problem where the autopilot aborts every landing attempt at Island 09

 

Edit 3: It would be really nice if we could save plane profiles from in game.

Edited by HB Stratos
Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...