Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


Recommended Posts

7 minutes ago, -ctn- said:

Nice! How do you get kOS to calculate the gravity of the body? I tried looking but could not find a way for it to find that out - it was up to me to "hard code" that in. 

set g to body:mu / body:radius^2.

And if you need the g at the altitude of your ship, just do this:

set g to body:mu / (body:radius+altitude)^2.

:)

Link to post
Share on other sites

Nice! That's a fair bit more reliable than my version. As I said, all it does is loop between throttle at 0.5 if vertical speed is greater than or equal to 2m/s and throttle at 0 if vertical speed is less than 2m/s. 

When it works, I get a nice slow touchdown from 40 meters altitude, but if the parachute doesn't slow my speed enough, the engines won't kick on and I crash. 

Link to post
Share on other sites

I could use some help please :/

Expet for the regulation of thrust near the AP I'm quite happy with the script I put together.

I have no real experience in coding.

The problem: My engine refuses to shutdown when the script ends and I really can't figure out why!

It's been bothering me the whole evening. It truly fullfills the definition of insanity right now ...

here is my script, please help:

Spoiler

 

//launch.ks

//prepare vessel:
sas off.
rcs off.
lights off.
set throttle to 0.
gear off.
clearscreen.

//define orbit:
set targetapoapsis to 75000.
set targetperiapsis to 75000.

//initial logo:
print "(c)maculator" at (35,35).

//make sure, script only activates on launchpad:
set task to 02.		
if alt:radar < 50 {
	set task to 01.
}
	
until task = 12 {	

//Liftoff:		
	if task = 01 {			
		lock steering to up.	
		lock throttle to 1.
		stage.
		set task to 02.		
	}
	
//gain altitude:
	else if task = 02 {
		lock steering to heading (90,90).
		lock throttle to 1.
		if ship:altitude > 200 {
			set task to 03.				
		}
	}
	
//turn 5 degrees east:
	else if task = 03 {
		lock steering to heading (90,85).
		lock throttle to 1.
		if ship:altitude > 8000 {
			set task to 04.				
		}
	}	
	
//gravity turn:
	else if task = 04 {
		set targetpitch to max (3,90*(1-alt:radar/35000)).
		lock steering to heading (90,targetpitch).
		lock throttle to 1.
		if ship:apoapsis > targetapoapsis {
			lock throttle to 0.
			set task to 05.
		}
	}
	
//cost to the edge of atmosphere:
	else if task = 05 {
		lock steering to heading (90,0).
	if altitude > 70000 {
			set task to 06.
		}
	}
//cost to circulationburn:	
	else if task = 06 {
		if eta:apoapsis < 55 {
			set task to 07.
		}
	}

//start circulationburn:	
	else if task = 07 {
		if eta:apoapsis < 50 {
			lock throttle to 1.
			set task to 08.
		}
	}
	
//check if burn is complete or needs tweaking:
	else if task = 08 {
		if (ship:periapsis > targetperiapsis) or (ship:periapsis > targetapoapsis * 0.96) {
			lock throttle to 0.
			set task to 12.
		}
		else if (ship:apoapsis > targetapoapsis){
			lock throttle to 0.
			set task to 09.
		}
	}
	
//tweak circulationburn:	
	else if task = 09 {
		if eta:apoapsis < 25 {
			lock throttle to max (1,(ship:apoapsis - ship:altitude)/1000).
			set task to 10.
		}
	}
	
//check again:
	else if task = 10 {
		if (ship:periapsis > targetperiapsis) or (ship:periapsis > targetapoapsis * 0.96) {
			lock throttle to 0.
			set task to 12.
		}
		else if eta:apoapsis > 35 {
			lock throttle to 0.
			set task to 11.
		}
	}
	
//tweak again:
	else if task = 11 {
		if eta:apoapsis < 25 {
			lock throttle to max (1,(ship:apoapsis - ship:altitude)/1000).
			set task to 10.
		}
	}
	
//finalisation:
	else if task = 12 {
		set throttle to 0.
		panels on.
		lights on.
		unlock steering.
		print "finished".
	}
	
//stageing
	if stage:liquidfuel < 1 {
		stage.
	}

	print "current mode:" 	+ task 						+ "/12" at (10,10).
	print "altitude:" 		+ round (ship:altitude)		+ "          " at (10,12).
	print "apoapsis:" 		+ round (ship:apoapsis)		+ "          " at (10,13).
	print "periapsis:" 		+ round (ship:periapsis)	+ "          " at (10,14).
	print "eta to ap:" 		+ round (eta:apoapsis)		+ "          " at (10,15).
	print "(c)maculator" at (35,35).
}

I just saw I missused the max-function .... but that wont fix my problem, it just underlines how smart Iam.

Also the 2. "tweaking" is pointless.

Edited by maculator
I'm not a smart man
Link to post
Share on other sites
8 minutes ago, Alchemist said:

this does nothing:

set throttle to 0.

use this instead:

SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.

it will put the throttle input to 0.

Right. The reason why "set throttle" doesn't work is because it only sets the throttle to that value while the code is running. Once the code program ends, the throttle position is set by default to whatever you had it set to before you ran the code. So if you had your throttle up full-blast and then ran the code, when the code is completed, it will set your throttle back to full blast. 

 

The line of code Alchemist recommended will tell the code that you are setting a new "default" value for the throttle, so when the code program ends, it will return the throttle to this value  

 

Link to post
Share on other sites

in the end, if the script ends on standby mode not just finishes, you need to

UNLOCK THROTTLE.

Alternatively, you can

LOCK THROTTLE TO 0.

at that point, but you still need to ensure the throttle input is set to 0 before the script finishes, because it will be unlocked

Link to post
Share on other sites

I thought it might have a problem since its running in an "else if" with 2 "ifs" executed parralel. So I moved it to the verry end of the script and it worked.

Wow KOS definitly has a interresting learning curve. The basic script was done in a few minutes with the help of a tutorial then a bit tweaking for 90 minutes and then 3 houres of pure frustration. Thank god its finished!

 

So now I only need to learn how to replace my 100% throttle setting with a variable and tweak the final steps to make it possible to bring vessels with realy low TWR into orbit.

Edited by maculator
Link to post
Share on other sites

Well, it is a coding language. That's how it usually goes - the bulk of the program is done fairly quickly, and then dozens of hours are spent tweaking it or streamlining it. 

Link to post
Share on other sites

I have one last question: Is there some sort of up to date libary of scripts? I've been looking on the KOS homepage and the tutorials really helped me but I did'nt find a libary with easy exampels for the variouse things it can do. Like hover, land, parachutes etc. I'm fairly new to this stuff and need some simple things I can see in action and lern from. Would be nice if someone could point me in the right direction, thanks.

Link to post
Share on other sites

As far as I know, there is no up-to-date example library. You can glean some information from outdated scripts, but the real meat and potatoes comes from the kOS documentation github. It has everything you need, just remember that coding is a specific and fussy business. Most of my time when writing a script is spent on that documentation site and testing. 

Link to post
Share on other sites
3 hours ago, Kartoffelkuchen said:

I've now highly improved my code, and it is really much better:

 

:)

Can your script target certain vessels (such as the LZ1 and the drone barge) as well? 

Link to post
Share on other sites
2 hours ago, maculator said:

I have one last question: Is there some sort of up to date libary of scripts?

There are a couple of really great resources linked right from the manual:

http://ksp-kos.github.io/KOS_DOC/tutorials/quickstart.html
 

and in the user manual index there is the community library which has a lot of the more complex routines.
Each section of the manual has solid examples, like the PID section etc.
Have a look through it, you will be surprised at the amount of cut-and-paste solutions you can find to help you get familiar.
And the developers are regularly checking in on the forum to answer any questions and help you develop your code.

Just ask!

PGodd

Link to post
Share on other sites

New Release

Github : Download

Spacedock : Download

 

BREAKING CHANGES

  • As usual, you must recompile any KSM files when using the new version.
  • Vecdraw :SCALE no longer applied to :START. Only applied to :VEC.
  • Varying power consumption might make it so if you have high IPU settings some designs might run out of power when they didn't before. (in most cases it should draw less power for most people).
  • !!!! Default extension of ".ks" is no longer applied to all new filenames created. But it still will be looked for when reading existing files if you leave the extension off !!!!
  • FileInfo information now moved to Volume (http://ksp-kos.github.io/KOS_DOC/structures/volumes_and_files/volume.html).
  • VOLUME:FILES was returning a LIST(), now it returns a LEXICON who's keys are the filename.
  • String sort-order comparisons with "<" and ">" operators were implemented wrongly and just compared lengths. Now they do a character-by-character comparison (case-insensitively). On the off chance that anyone was actually trying to use the previous weird length-comparison behavior, that would break.

NEW FEATURES

BUG FIXES

  • Numerous additional checks to prevent control of other vessels the kOS CPU isn't attached to.
  • The error beep and keyboard click sounds now obey game's UI volume settings. (#1287)
  • Fixed two bugs with obtaining waypoints by name. (#1313) (#1319)
  • Removed unnecessary rounding of THRUSTLIMIT to nearest 0.5%, now it can be more precise. (#1329)
  • Removed the ability to activate both modes on multi-mode engine simultaneously.
  • LIST ENGINES now lists all engines and displays part names instead of module names. (https://github.com/KSP-KOS/issues/1251)
  • Fixed bug that caused hitting ESC to crash the telnet server. (#1328)
  • Some exceptions didn't cause beep, now they all do. (#1317)
  • Vecdraw :SCALE no longer applied to :START. Only applied to :VEC. (#1200)
  • Fixed bug that made up-arrow work incorrectly when the cursor is at the bottom of the terminal window. (#1289)
  • A multitude of small documentation fixes (#1341)
  • Fixed a bug when performing an undock (#1321)
  • IR:AVAILABLE was reporting incorrectly ()
  • Boot files now wait until the ship is fully unpacked and ready (#1280)
  • The Vessel :HASBODY (aliases :HASOBT and :HASORBIT) suffix was in the documentation, but had been lost in a refactor last year. It is put back now.
  • String sort-order comparisons with "<" and ">" operators were implemented wrongly and just compared lengths. Now they do a character-by-character comparison (case-insensitively)
  • Small documentation edits and clarifications all over the place.

KNOWN issues

  • Using lock variables in compiled scripts with a duplicate identifier (like "throttle") throws an error (#1347 and #1253).
  • Occasionally staging with a probe core or root part in the ejected stage will break cooked steering (#1492).
  • The limitations of RemoteTech integration can be bypassed by storing a volume in a variable before the ship looses a connection to the KSC (#1464).

CONTRIBUTORS THIS RELEASE

(These are generated from records on Github of anyone who's Pull Requests are part of this release.)
(Names are simply listed here alphabetically, not by code contribution size. Anyone who even had so much as one line of change is mentioned.)

Stephan Andreev (ZiwKerman) https://github.com/ZiwKerman
Bert Cotton (BertCotton) https://github.com/BertCotton
Kevin Gisi (gisikw) https://github.com/gisikw
Peter Goddard (pgodd) https://github.com/pgodd
Steven Mading (Dunbaratu) https://github.com/Dunbaratu
Eric A. Meyer (meyerweb) https://github.com/meyerweb
Tomek Piotrowski (tomekpiotrowski) https://github.com/tomekpiotrowski
Brad White (hvacengi) https://github.com/hvacengi
Chris Woerz (erendrake) https://github.com/erendrake (repository owner)
(name not public in github profile) (alchemist_ch) https://github.com/AlchemistCH
(name not public in github profile) (tdw89) https://github.com/TDW89

Edited by erendrake
Link to post
Share on other sites

@erendrake Oh lol I had just downloaded the one before this update around 2 minutes before this got updated. Anyways thank you for updating this mod it really is awesome! Just wondering is it possible to define our own commands? I am just wondering this because I would love to make a command that finds Delta V and stuff via referencing a script and executing it like a command.

Edited by Riderfighter
Link to post
Share on other sites

Also quick question is there a way to see how much power you have and switch off power consuming parts and then extend solars when at a certain amount? (Via scripts of course if it wasn't clear)

Edited by Riderfighter
Link to post
Share on other sites
6 hours ago, Riderfighter said:

Just wondering is it possible to define our own commands?

Yes absolutely! 
You can create a user function

function function_name {parameter parameter_if_desired code}
call it anywhere in the program : function_name(optional parameters)

kOS manual function page: http://ksp-kos.github.io/KOS_DOC/language/user_functions.html?highlight=function#declare-function

Since last night there is also delegates:

 

Link to post
Share on other sites

 

7 hours ago, Riderfighter said:

Also quick question is there a way to see how much power you have and switch off power consuming parts and then extend solars when at a certain amount? (Via scripts of course if it wasn't clear)

You can obtain the aggregate charge for your ship this way:
print ship:electriccharge.
So to activate the panels before you run out of power:
when ship:electriccharge < x then panels on.

Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...