Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

25 minutes ago, Riderfighter said:

So I was making my script open solars when at a certain level of power but I wanted to know if there is a way to detect if light is facing your way.

ship:sensors:light gives you a scalar (between 0-1, 1 being 100%) of the amount of sunlight falling on your panels.

You could also get a list of panels and query each one for the light falling on a certain panel.
To be realistic, the way the ship detects light is through the light "sensor"(solar panel) which happens to act as a good battery charger as well.
Some solar panels automatically track the sun, but they do have to be deployed to do this.
 

Link to comment
Share on other sites

49 minutes ago, Riderfighter said:

So I was making my script open solars when at a certain level of power but I wanted to know if there is a way to detect if light is facing your way.

I'm a noob, so my solution would look like this:

put a single smal panel somwhere on the rocket and check if it produces power.

 

But now the reason I came here:

I completed my simple orbit script. With a "normal and simple" built rocket it can achieve the target orbit within a aceptable margin.

And since I'm really proud I thought I share it here in case someone wants to have a look at it and suggest improvements or siply wants to use parts of it. (prepare for some spelling misstakes befor looking at it, I'm german. also opening it in a decent editor makes the layout "a bit" better readable)

Spoiler

//launch.ks by maculator.
//my first functioning script that does more then just say hello.
//launches a rocket to 100km orbit, can't handle boosters or aspargus.

//setting up the panel:
clearscreen.
set terminal:width to 21.
set terminal:height to 21.
print "---------------------".
print "---simple launcher---".
print "-no boosters/aspargus".
print "---------------------".
print "---------by maculator".
print "---------------------".
print "---------------------" at (0,9).
print "---------------------" at (0,11).
print "---------------------" at (0,13).
print "---------------------" at (0,16).
print "---------------------" at (0,18).

//prepare vessel:
set ship:control:pilotmainthrottle to 0.

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

//check if ship is on launchpad	
set task to 02.		
if alt:radar < 50 	{	set task to 01.
					}
//starting the until-loop wich contains all the tasks:	
until task = 11 {	

//Liftoff:		

	if task = 01 		{	lock steering to up + r(0,0,180). lock customthrottle to 1. stage. set task to 02.
						}
	
//gain altitude:
	else if task = 02 	{	lock steering to heading (90,90). lock customthrottle 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 customthrottle 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/40000)). lock steering to heading (90,targetpitch). lock customthrottle to 1. 
							if ship:apoapsis > targetapoapsis {lock customthrottle to 0.set task to 05.}
						}
	
//cost to the edge of atmosphere:
	else if task = 05 	{	lock steering to heading (90,0). set warpmode to "physics". wait 1. set warp to 1.
							if altitude > 70000 {set warp to 0. wait 1. set task to 06.}
						}
						
//cost to circulationburn:	
	else if task = 06 	{	if eta:apoapsis > 100 {set warpmode to "rails". wait 1. set warp to 1. wait 1. set task to 07.}
							else if eta:apoapsis < 100 {set warpmode to "physics". wait 1. set warp to 1. wait 1. set task to 07.}
						}

//start circulationburn:	
	else if task = 07 	{	if eta:apoapsis < 50 {set warp to 0. lock customthrottle 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.97) {lock customthrottle to 0. set task to 11.}
							else if (ship:apoapsis > targetapoapsis){lock customthrottle to 0. set task to 09.}
						}
	
//tweak circulationburn:	
	else if task = 09 	{	if ship:periapsis < 0 {if eta:apoapsis < 25 {lock customthrottle to min (1,(ship:apoapsis - ship:altitude)/800). set task to 10.}}
							else if ship:periapsis > 0 	{	if ship:periapsis < (targetperiapsis / 2)		{if eta:apoapsis < 20 {lock customthrottle to min (1,max (0.1,(ship:apoapsis - ship:altitude)/800)). set task to 10.}}
															else if ship:periapsis > (targetperiapsis / 2) 	{if eta:apoapsis < 10 {lock customthrottle to min (1,max (0.1,(ship:apoapsis - ship:altitude)/800)). set task to 10.}}
														}	
						}
	
//check again:
	else if task = 10 	{	if (ship:periapsis > targetperiapsis) or (ship:periapsis > targetapoapsis * 0.96) {lock customthrottle to 0. set task to 11.}
							else if eta:apoapsis > 35 {lock customthrottle to 0. set task to 09.}
						}
		
//finalisation:
	else if task = 11 	{	panels on. lights on.
						}
	
//staging:
	if stage:liquidfuel < 1 {lock throttle to 0. wait 0.2. stage. wait 0.5. lock throttle to customthrottle.}

//Saving throttle state (important for staging!):	
	set throttlegarage to customthrottle.
	lock throttle to throttlegarage.
	
//print data on screen:	
	print "current mode:" 	+ task	+ "  " at (0,10).
	print "alt: " + round(ship:altitude) + "      " at (0,12).
	print "ap : " + round(ship:apoapsis) + "      " at (0,14).
	print "pe : " + round(ship:periapsis) + "      " at (0,15).
	print "eta to ap : " + round(eta:apoapsis) + "      " at (0,17).	

				}
				
//end program:
set ship:control:pilotmainthrottle to 0.
unlock steering.
print "i hope we did it".
wait 3.

 

 

Edited by maculator
found some misspelled words, again.
Link to comment
Share on other sites

It's a fine script for sure.
There are about a hundred different ways to do everything.
After the devs have had a rest from working all day and night for a week to get the release out, they will be happy to offer some improvements.
^_^
In the mean-time just think about how your script is working and how you'd like to improve it.
here's a link to some really great tutorials on youtube:


 

Link to comment
Share on other sites

^ this. This is the tutorial my script is based on :)

I took it as a "base" and then tweeked/expanded it to my liking.

For now I'll give kos a little break and enjoy launching tourists to orbit with my script. Much more rewarding then using mechjeb.

My next goal is a script wich lands my capsule with chutes (I dont care where I just want to start the program in orbit and when I'm back the capsul should be on solid gorund or water).

Link to comment
Share on other sites

If you set your chutes to action groups, the script for a deorbit/ chute landing is quite simple.

if you're looking for a powered landing, that's a bit more work. I have a script I'm working on that throttles the engines for a soft landing, but they "sputter," unlike Kartoffelkuchen's script, which is quite nice and uses a single burn. I'm not sure how he did that yet, but I'm assuming it has something to do with throttling the engines to a certain TWR during the descent. 

Link to comment
Share on other sites

9 hours ago, Dr_Goddard said:

ship:sensors:light gives you a scalar (between 0-1, 1 being 100%) of the amount of sunlight falling on your panels.

This maybe stupid but since I'm not that sure can it be a decimal for the scalar? and if so would 0.1 be the right when sunlight peaks onto the ship?

Link to comment
Share on other sites

Not sure if I'm just doing something horribly wrong or the newest update broke "RENAME".

Reproduce:

copy anyfile from 0.
rename file anyfile to othername.

Error is: File does not exist: othername________________________________

The result is that anyfile gets deleted.

Link to comment
Share on other sites

5 hours ago, leviathan01 said:

how would I find the location/time tell of the ascending node between my orbit and the orbit of my target (ship or moon)?

That value is not directly exposed by kOS.  You can solve for it using orbital parameters though.  Here is a good link to the math involved.  Remember to pay attention to radians/degrees and that the LAN is in universal longitude, which is based on the solar prime vector.

2 hours ago, Riderfighter said:

This maybe stupid but since I'm not that sure can it be a decimal for the scalar? and if so would 0.1 be the right when sunlight peaks onto the ship?

Yes, it can be any decimal value between 0 and 1, including 0.1.  You'll have to experiment to see what values correspond to what you're looking for.

56 minutes ago, troyfawkes said:

Not sure if I'm just doing something horribly wrong or the newest update broke "RENAME".

Reproduce:


copy anyfile from 0.
rename file anyfile to othername.

Error is: File does not exist: othername________________________________

The result is that anyfile gets deleted.

Could you please swing over to github and create an issue for this?  I know we already have an issue submitted with issues for different case of letters in file names, and this should get fixed too.  Did you test it using string literals as well ("anyfile" and "othername")?

Link to comment
Share on other sites

Okay I have a question about "until loops":

This is how the loop in my orbit script works right now:

Spoiler

 


...
set VARIABLE to 1
if vessel on launchpad {set VARIABLE to 2}
until VARIABLE = X 	{
					if {getting off the pad then set VARIABLE to 3 }
					else if {gravity turn then set VARIABLE to 4}
					else if {...  set VARIABLE X+n}
					else if {orbit achieved sets VARIABLE to X}
					else if {when VARIABLE = X give back control etc.}
					if {stage}
					if {print infos /print action}
					}

 

What I dont like is, that it runs over everything again and again. It seems unefficient to me.

So what I was thinking could a script like that also work like this:

Spoiler

...
set VARIABLE to 1
if vessel on launchpad {set VARIABLE to 2}

else if {getting off the pad then set VARIABLE to 3 /print action }
else if {gravity turn then set VARIABLE to 4 /print action }
else if {... set VARIABLE to x+n /print action }
else if {orbit achieved sets VARIABLE to X /print action }
else if {when VARIABLE = X give back control etc. /print action }
until VARIABLE = x 	{
					if {stage}
					if {print infos}
					}

 

 

Edited by maculator
Link to comment
Share on other sites

9 hours ago, hvacengi said:

Could you please swing over to github and create an issue for this?  I know we already have an issue submitted with issues for different case of letters in file names, and this should get fixed too.  Did you test it using string literals as well ("anyfile" and "othername")?

https://github.com/KSP-KOS/KOS/issues/1498

I did, yeah. I tested it in a bunch of other scenarios as well. I actually can't get rename to work under any circumstance, which is frustrating because I use it extensively in my boot file.

Link to comment
Share on other sites

I'm not sure if this question has been asked before or not, but is there any documentation for kOS in a downloadable or printable format? The user guide on Github is impressive and great for refrence when I'm online, but it'd be nice to be able to look at the documentation without being connected to the internet.

Link to comment
Share on other sites

1 hour ago, ILikeIke said:

I'm not sure if this question has been asked before or not, but is there any documentation for kOS in a downloadable or printable format? The user guide on Github is impressive and great for refrence when I'm online, but it'd be nice to be able to look at the documentation without being connected to the internet.

It occurs to me that we *could* include the html tree of directories in the ZIP file in future releases.  All the URLs are relative and do work in a `file:///` context.

In the meantime you can clone the github repository and then on your local copy do `git checkout gh-pages` to see the html docs.

A while back someone was working on a LaTEX output for our docs but I don't know if that ever got done.

Link to comment
Share on other sites

is it possible to make a script to run science experiments? I would love this so that when I launch my probe to the mun it will automatically run the experiments when in high/low mun orbit.

@ILikeIkeI can convert the github page to a pdf if that will help you anyway?

Edited by Riderfighter
Link to comment
Share on other sites

@Riderfighter thanks for the offer! I don't know the first thing about github so I'm going to try to do it myself as an introduction to it, but if I have any questions, I know where to go for help. If I'm able to from my device (I'm not on a computer), I'll post whatever my finished product is in this thread.

Link to comment
Share on other sites

3 hours ago, Riderfighter said:

is it possible to make a script to run science experiments? I would love this so that when I launch my probe to the mun it will automatically run the experiments when in high/low mun orbit.

@ILikeIkeI can convert the github page to a pdf if that will help you anyway?

5 hours ago, ILikeIke said:

I'm not sure if this question has been asked before or not, but is there any documentation for kOS in a downloadable or printable format? The user guide on Github is impressive and great for refrence when I'm online, but it'd be nice to be able to look at the documentation without being connected to the internet.

4 hours ago, Steven Mading said:

It occurs to me that we *could* include the html tree of directories in the ZIP file in future releases.  All the URLs are relative and do work in a `file:///` context.

In the meantime you can clone the github repository and then on your local copy do `git checkout gh-pages` to see the html docs.

A while back someone was working on a LaTEX output for our docs but I don't know if that ever got done.

You can actually already download a zip file of the html files directly from our KOS_DOC repository: https://github.com/KSP-KOS/KOS_DOC/archive/gh-pages.zip

The sphinx software that we use to generate the documents has some kind of a pdf output option, as well as a variety of other formats (like Windows help files).  I don't think the pdf generation worked when I tested it last on my windows machine, but I don't mind trying it again to see if we can provide a downloadable pdf.

Link to comment
Share on other sites

So I may or may not of locked myself out of my house and well for two hours in the cold and it made me wonder can you script something to make lights come on based on the temperature of the environment? This would be awesome!

Edited by Riderfighter
Link to comment
Share on other sites

41 minutes ago, Riderfighter said:

Also if that is possible would a script like, When ship:sensors:temp >= 0.1  { lights on. } , this work?

Looks about right

 

Lights and landing gear sometimes exhibit a bit of a glitch in my experience with a very slow computer. Sometimes they have to be activated twice to come on the first time.

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...