Jump to content

[KSP 1.12.x] kOS v1.4.0.0: kOS Scriptable Autopilot System


Dunbaratu

Recommended Posts

On 5/21/2018 at 7:45 AM, Drew Kerman said:

does the code example for CHUTESAFE work with RealChute? I started doing some testing tonight but I couldn't tell if it was not meant to work or I was doing it wrong.

To be honest, I have no idea.

Looked up the source for RealChute, and it seems to be derived straight from PartModule with the deployment and safety states being defined anew. Then neither Chutes nor ChutesSafe in kOS would likely work with it, as these pseudo-actions are based on searching for stock ModuleParachute or anything derived from it and using the state values and deployment calls from there

(Is this legacy from the times when deriving from existing partModules refused to work whatsoever? Yes, when originally implemented, these modules were such a mess on the plugin making side...)

 

Anyway, the ChutesSafe action was created to account for the way stock parachutes behaved back then, basically, deploying even if it was unsafe. In newest versions of KSP stock chutes have additional setting and its default position is to wait for safe conditions, so you can just trigger all the chutes and they will gradually deploy same as with the code example provided in the documentation. Does this mod have such ability to put this kind of failsafe?

Link to comment
Share on other sites

18 minutes ago, Alchemist said:

Does this mod have such ability to put this kind of failsafe? 

it used to have a part module field that would say whether it was safe to deploy or not but recently it switched over to the stock way of changing the staging icon color, which is what I was hoping kOS was looking for when it was determining whether a chute was safe to open or not. Guess not.

Link to comment
Share on other sites

Hi I'm currently writing a script to make a Falcon 9 alike boostback burn to the launchpad, how can I set the KSC as my target and command the engine to cut off when the trajectory reaches the KSC? Thanks in advance.

Link to comment
Share on other sites

2 hours ago, Inspierio said:

Hi I'm currently writing a script to make a Falcon 9 alike boostback burn to the launchpad, how can I set the KSC as my target and command the engine to cut off when the trajectory reaches the KSC? Thanks in advance.

I think that best way to do it is by using Geographic Coordinates. It is just a metter to find out exact longitude and latitude of point where you want to land and that is easy enough with probes and stock map nav points. Geocoordinate structure provides enough data for autopilot to do landing on exact spot.

Creating such script for yourself is fun part, though, if you search with google, others are provided some examples how they have solved same or similar thing with kOS.

Link to comment
Share on other sites

What am I doing wrong here folks?  It's probably something stupid but I can't spot it!

I'm trying to do a braking burn for a Mun landing while keeping my vertical velocity constant, which is a fairly low descent rate as I've placed my Periapsis just after the target.

I have these lines in a  loop to work out how many degrees I need to point the nose up so that vertical component of thrust matches gravity, and then set the ship heading, which the steering is locked to.  VecBearing(-SteeringVec) returns the bearing I need to steer how I want.

set LocalGrav to ship:body:mu / (ship:altitude+ship:body:radius)^2.
set Noseup to arcsin(LocalGrav*ship:mass/Ship:maxthrust).	
set shipheading to heading(VecBearing(-SteeringVec),noseup).

However the burn starts with a vertical velocity of about -7 and ends up around +15, so I'm clearly to far nose up, despite the throttle not being set slightly below 1 so I should have less vertical thrust than the calculation assumes.

Edited by RizzoTheRat
Link to comment
Share on other sites

1 hour ago, RizzoTheRat said:

However the burn starts with a vertical velocity of about -7 and ends up around +15, so I'm clearly to far nose up, despite the throttle not being set slightly below 1 so I should have less vertical thrust than the calculation assumes. 

How fast are you going horizontally when this begins? At orbital velocity, the gravity you are trying to cancel out is effectively zero. By the time you are hovering, you do have the full force of gravity to counter.

I'll look up the calculation for 'effective' gravity...

Edit: okay, so your orbital velocity sideways can be used to calculate a centripetal acceleration. You then need to subtract that from local gravity when trying to determine how much you need to accelerate upwards:

LOCAL v_x2 IS VXCL(UP:VECTOR,VELOCITY:ORBIT):SQRMAGNITUDE.
LOCAL cent_acc IS v_x2 / (BODY:RADIUS + ALTITUDE).

Edited by ElWanderer
Link to comment
Share on other sites

8 hours ago, kcs123 said:

I think that best way to do it is by using Geographic Coordinates. It is just a metter to find out exact longitude and latitude of point where you want to land and that is easy enough with probes and stock map nav points. Geocoordinate structure provides enough data for autopilot to do landing on exact spot.

Creating such script for yourself is fun part, though, if you search with google, others are provided some examples how they have solved same or similar thing with kOS.

How would I be able to find the coordinates of specific locations? 

Link to comment
Share on other sites

On 5/24/2018 at 10:58 PM, ElWanderer said:

centripetal acceleration.

Well I was right about one thing, forgetting I'm still in orbit when I start the burn definitely counts as "something stupid" :D  Thanks.

 

On 5/24/2018 at 11:58 PM, Inspierio said:

How would I be able to find the coordinates of specific locations? 

If it's just the landing pad drive there in a rover with KER or KOS fitted and either read it off the KER display (note that KER gives a positive number of degrees East or West while KOS give -180 to +180 degrees East), or print it out from KOS

Print "Lat/Long : "+ Ship:Latitude + " / " + Ship:longitude.

For places you've not yet visited, my plan is to scan the body using the SCANSat mod which will give me a detailed map, and then either read lat/long coordinates of the display for spots that look flat enough, or export the data and process it in excel to find suitable landing points.

Edited by RizzoTheRat
Link to comment
Share on other sites

When I disable all the engines except the single core, the script still thinks it has all it's engines on. What's the problem here?

    if runmode = 27 { // Suicide burn
        lock STEERING to velocity:surface * -1.//Point retrograde
        set landingRadar to min(ALTITUDE, betterALTRADAR). 
		set GRAVITY to (constant():G * body:mass) / body:radius^2.
		lock TWR to MAX( 0.001, MAXTHRUST / (MASS*GRAVITY)).
        set TVAL to (1 / TWR) - (verticalspeed + max(5, min (250, landingRadar^1.08 / 8)) ) / 3 / TWR.
		// add realism by activating gear at slow speeds
		if ABS(VERTICALSPEED) < 20 {
			gear on.
			}
        if ABS(VERTICALSPEED) < 1 {
			brakes off.
			lights off.
			RCS off.
			SAS on.
            lock throttle to 0.
            lock steering to up.
            print "LANDED!".
            wait 2.
            set runmode to 0.
            }

        }

 

Link to comment
Share on other sites

34 minutes ago, Inspierio said:

When I disable all the engines except the single core, the script still thinks it has all it's engines on. What's the problem here?


    if runmode = 27 { // Suicide burn
        lock STEERING to velocity:surface * -1.//Point retrograde
        set landingRadar to min(ALTITUDE, betterALTRADAR). 
		set GRAVITY to (constant():G * body:mass) / body:radius^2.
		lock TWR to MAX( 0.001, MAXTHRUST / (MASS*GRAVITY)).
        set TVAL to (1 / TWR) - (verticalspeed + max(5, min (250, landingRadar^1.08 / 8)) ) / 3 / TWR.
		// add realism by activating gear at slow speeds
		if ABS(VERTICALSPEED) < 20 {
			gear on.
			}
        if ABS(VERTICALSPEED) < 1 {
			brakes off.
			lights off.
			RCS off.
			SAS on.
            lock throttle to 0.
            lock steering to up.
            print "LANDED!".
            wait 2.
            set runmode to 0.
            }

        }

 

How have you "disabled" them? If you have set their throttle limiters to 0, that would not affect the value of MAXTHRUST. SHIP:AVAILABLETHRUST is better in that situation as it takes limiters into account.

Link to comment
Share on other sites

1 hour ago, ElWanderer said:

How have you "disabled" them? If you have set their throttle limiters to 0, that would not affect the value of MAXTHRUST. SHIP:AVAILABLETHRUST is better in that situation as it takes limiters into account.

I'm using Tundra Exploration so there's an option to toggle between central engine and all engines

Link to comment
Share on other sites

14 minutes ago, Inspierio said:

I'm using Tundra Exploration so there's an option to toggle between central engine and all engines

I don't know what that is, but it sounds like the engines are a single part with mode switching (I think I've seen a SpaceY engine that did that). Sadly... I don't know how that would affect the values of MAXTHRUST and AVAILABLETHRUST. It shouldn't be too hard to test, though. If there is a single part involved, you could also get the current THRUST from it.

Link to comment
Share on other sites

1 minute ago, ElWanderer said:

I don't know what that is, but it sounds like the engines are a single part with mode switching (I think I've seen a SpaceY engine that did that). Sadly... I don't know how that would affect the values of MAXTHRUST and AVAILABLETHRUST. It shouldn't be too hard to test, though. If there is a single part involved, you could also get the current THRUST from it.

I've tried doing that but kOS replies with it being undefined

Link to comment
Share on other sites

Just now, Inspierio said:

I've tried doing that but kOS replies with it being undefined

What exactly have you tried?

MAXTHRUST and AVAILABLETHRUST are both vessel attributes, but from memory only MAXTHRUST has an alias that means you can leave off the vessel (defaults to SHIP) - hence you need to use SHIP:AVAILABLETHRUST. THRUST is a part/engine attribute, so you would need to have looked up the right part to use it.

Link to comment
Share on other sites

11 minutes ago, ElWanderer said:

What exactly have you tried?

MAXTHRUST and AVAILABLETHRUST are both vessel attributes, but from memory only MAXTHRUST has an alias that means you can leave off the vessel (defaults to SHIP) - hence you need to use SHIP:AVAILABLETHRUST. THRUST is a part/engine attribute, so you would need to have looked up the right part to use it.

I tried using SHIP:THRUST and this is what I got f808e9e20db3b7eda5f5a5af4204ccb0.png

Link to comment
Share on other sites

23 minutes ago, Inspierio said:

I tried using SHIP:THRUST

Yes, that won't work as it doesn't exist. Vessels don't have a THRUST suffix; only engine parts do.

Do you know how to get the list of engines and loop through them looking for those that are active? You can get the current thrust for each active engine and add them up.

Alternatively, you could tag the engine(s) in the VAB and look for just parts with that tag in your code.

Link to comment
Share on other sites

15 hours ago, Inspierio said:

How would I be able to find the coordinates of specific locations? 

In addition to already mentioned, you can launch probe and while on launchpad, open KerbNet Access on right click menu. There you can see geocoordinates and you can even set a custom waypoint. You can also use waypoint manager mod and for other locations than launchpad I recommend SCANSat mod too.

It is fun to use SCANSat in combo with all other stuff to get additonal sense to launch bunch of probes around Kerbin first for additional help in other kOS scripts and crafts.

Link to comment
Share on other sites

I'm getting strange twitching in pitch and yaw when using KOS, but it only happens when running a script from a file. If I type "set throt to 1." and "stage." in the KOS terminal in-game, the rocket flies just as expected, straight up with no control. However, if I launch the same rocket by calling a file (runpath("0:/launch.ks").) containing only "set throt to 1." and "stage.", the pitch and yaw of the rocket freak out and the gimbal of my engine and deflection of my control surfaces go all over the place, even though the rocket should be 100% uncontrolled. This effect is screwing up all of my other scripts as well, making them completely unusable. Does anyone know what the issue could be?

 

Edit: It seems to just have been a bug. I uninstalled and reinstalled KSP and KOS and the issue went away.

Edited by TheBeesSteeze
found a solution
Link to comment
Share on other sites

I'm having a major issue where my frames gradually drop from 100 fps to 5 fps in about 15 seconds. I'm running a simple as you can get script with no mods on the latest version of KOS and KSP. Any ideas? It was not happening a few days ago and I haven't changed anything. 

Link to comment
Share on other sites

2 hours ago, jbakes said:

I'm having a major issue where my frames gradually drop from 100 fps to 5 fps in about 15 seconds. I'm running a simple as you can get script with no mods on the latest version of KOS and KSP. Any ideas? It was not happening a few days ago and I haven't changed anything. 

Does this only happen while the script is running? What is your kOS "instructions per second" / CONFIG:IPU set to? Can you share the script?

Link to comment
Share on other sites

10 hours ago, ElWanderer said:

Does this only happen while the script is running? What is your kOS "instructions per second" / CONFIG:IPU set to? Can you share the script?

Okay so today I wrote some other scripts and it works fine. Yes the fps drop only happens when running a script, the IPS is set to default. This is the script that keeps lowering the fps. I'm guessing my problem lies in the pitch change script. Probably something to do with it continuously looping that's bogging down my computer.

 

Clearscreen.
wait 2.
Print "Ascent Script Loaded!".
wait 2.
Clearscreen.
Print "Launching!".
wait 1.5.
Clearscreen.
 
lock throttle to 1.
stage.
 
WHEN MAXTHRUST = 0 THEN {
PRINT "Staging".
WAIT 0.5.
STAGE.
WAIT 0.5.
PRESERVE. //Means to keep checking if thrust is = 0
}
 
until Apoapsis > 75000 {
 
lock targetPitch to 88.963-1.03287 * alt:radar^0.409511.
set targetDirection to 90.
lock steering to heading(targetDirection, targetPitch).
}
 
SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
SAS ON.
Edited by jbakes
Link to comment
Share on other sites

2 hours ago, jbakes said:
until Apoapsis > 75000 {

 

lock targetPitch to 88.963-1.03287 * alt:radar^0.409511.
set targetDirection to 90.
lock steering to heading(targetDirection, targetPitch).
}

You better not redeclare the same locks in a cycle - they are getting constantly reevaluated all the time anyway.

This would be enough:

lock targetPitch to 88.963-1.03287 * alt:radar^0.409511.
set targetDirection to 90.
lock steering to heading(targetDirection, targetPitch).

wait until Apoapsis > 75000.

 

Link to comment
Share on other sites

2 hours ago, jbakes said:

Okay so today I wrote some other scripts and it works fine. Yes the fps drop only happens when running a script. This is the script that keeps lowering the fps. I'm guessing my problem lies in the pitch change script. Probably something to do with it continuously looping that's bogging down my computer.

 

 
until Apoapsis > 75000 {
 
lock targetPitch to 88.963-1.03287 * alt:radar^0.409511.
set targetDirection to 90.
lock steering to heading(targetDirection, targetPitch).
}

This bit is quite expensive in terms of operations. You don't need to lock the steering continuously in a loop; just once. Take out the until apoapsis bit, and stick a wait until apoapsis > 75000 below the steering lock.

Haha - totally beaten to it.

Edited by ElWanderer
Link to comment
Share on other sites

11 hours ago, ElWanderer said:

This bit is quite expensive in terms of operations. You don't need to lock the steering continuously in a loop; just once. Take out the until apoapsis bit, and stick a wait until apoapsis > 75000 below the steering lock.

Haha - totally beaten to it.

Awesome, thank you!

I have another question. I'm trying to set an ascent profile based on time and pitch. Basically I want it to change the pitch by 0.2 degrees every 0.2 seconds. The script runs with no problems but the pitch is locked at 90 and never updates. Any ideas why?

Clearscreen.
wait 2.
Print "Ascent Script Loaded!".
wait 2.
Clearscreen.
Print "Launching!".
wait 1.5.
Clearscreen.
 
stage.
 
WHEN MAXTHRUST = 0 THEN {
PRINT "Staging".
WAIT 0.5.
STAGE.
WAIT 0.5.
PRESERVE
}
 
LOCK THROTTLE TO thrott.
LOCK STEERING TO HEADING(steeringDir,shipPitch).
 
SET steeringDir to 90.
SET shipPitch to 90.
SET thrott TO 1.
 
if shipPitch > 1 {
WAIT 0.2.
SET shipPitch to shipPitch-0.2.
}
 
WAIT UNTIL apoapsis > 85000.
Link to comment
Share on other sites

1 hour ago, jbakes said:
if shipPitch > 1 {
WAIT 0.2.
SET shipPitch to shipPitch-0.2.
}

 

WAIT UNTIL apoapsis > 85000.

This IF will be done once and then it waits for the apoapsis to reach the desired value

you need a proper cycle

until ((shipPitch <= 1)or(apoapsis > 85000)) {
WAIT 0.2.
SET shipPitch to shipPitch-0.2.
}


WAIT UNTIL apoapsis > 85000.

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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.

×
×
  • Create New...