Kamik423

2mF - KOS autopiloted return to launch site development project

Recommended Posts

The goal of this series/project is to develop a KOS script that can fly a falcon heavy like rocket or a single booster rocket and return all boosters and the first stage to the KSC autonomously. Progress will be posted over time. I will post single 'flights' on YouTube and in responses to this post. Each 'flight' will include an iteration on the source code adding or improving a single feature. The source code is available on Github.

There now is a followup project: 

 

Questions/comments/improvements are greatly appreciated.

Mission Log:

 

 

Github source code

Kamik423

Edited by Kamik423
extended explanation

Share this post


Link to post
Share on other sites

Flight #1:

Vertical boost for 10 seconds and subsequent touchdown using vector addition for directional steering.

 

PARAMETER landingpad.
PARAMETER throttleMultiplier.

IF NOT BRAKES { TOGGLE BRAKES. } //Turn Brakes on
LOCK vTarget_vertical TO (SHIP:ALTITUDE - landingpad:TERRAINHEIGHT) / 5 - 1.
LOCK vTarget_horizontal TO landingpad:ALTITUDEPOSITION(SHIP:ALTITUDE):MAG / 8.
LOCK steeringVector TO landingpad:ALTITUDEPOSITION(SHIP:ALTITUDE):NORMALIZED * vTarget_horizontal - VECTOREXCLUDE(SHIP:UP:FOREVECTOR, SHIP:VELOCITY:SURFACE).
LOCK STEERING TO LOOKDIRUP( steeringVector + SHIP:UP:FOREVECTOR:NORMALIZED * 20, HEADING(90,0):FOREVECTOR).
LOCK THROTTLE TO - throttleMultiplier * SHIP:VERTICALSPEED / vTarget_vertical.
WAIT UNTIL ALT:RADAR < 35.
IF NOT GEAR { TOGGLE GEAR.}
WAIT UNTIL SHIP:VERTICALSPEED > -0.1.
TOGGLE BRAKES.

 

 

Edited by Kamik423

Share this post


Link to post
Share on other sites

Flight #2:

 

Boost until Apoapsis > 20km, 2º off of the UP vector, then uses liftingbody forces to adjust glideslope to aim at launchsite, without ever performing a boostback or course correction. Those will be added later.

It aims at the the calculated impact point (via 1s - interval Euler integration) mirrored at the launchsite.

The touchdown script was adjusted to perform a suicide burn, wich however is still off. If anybody knows the cause, please tell me!!!

LOCK STEERING TO - ( landingpad:POSITION * 2 - impactPoint(6)). 

FUNCTION impactPoint {
    DECLARE PARAMETER k.
    DECLARE PARAMETER dv IS V(0,0,0).

    SET ps TO V(0,0,0).
    SET vs TO SHIP:VELOCITY:SURFACE + dV.
    SET as TO V(0,0,0).
    SET t TO 0.
    UNTIL ps:Z < -ALT:RADAR {
        SET t TO t + 1.
        SET as TO (- as:NORMALIZED * (as:MAG ^ 2 * k * (0.99997 ^ ALT:RADAR)) / (SHIP:MASS * 1000)) - SHIP:UP:FOREVECTOR:NORMALIZED * 9.81.
        SET vs TO VS + as.
        SET ps TO ps + vs.
    }
    RETURN ps.
}

 

 

Share this post


Link to post
Share on other sites
On 11/15/2016 at 7:05 AM, Kamik423 said:

The touchdown script was adjusted to perform a suicide burn, wich however is still off. If anybody knows the cause, please tell me!!!

Very impressive, sir!  kOS is a very powerful tool and fun to tinker with, but I've never attempted anything so ambitious.

I don't quite understand what you mean about the suicide burn being "off".  Looks like it worked perfectly to me.  However, several people have done Blue Origins-style missions with kOS, including one who got the booster back on the pad and the capsule on the island runway.  Those folks could probably help you.

Share this post


Link to post
Share on other sites
1 hour ago, Geschosskopf said:

I don't quite understand what you mean about the suicide burn being "off".  Looks like it worked perfectly to me.

It starts burning too early, as you see in the video and then descents with lower throttle, which is quite inefficient. The current equation is `h_suicide = 0.5*v^2/(F_max / m - 9.81)`

where F_max is the max thrust of the rocket and h_suicide the suicide burn height.

This equations results from `v^2 - v_0^2 = 2*a*x`.

 My guess is that is due to the variable mass of the system, but I am not quite sure what the right equation is...

(I hope the equations will be formatted)

 

EDIT:

they didn't.

And: I found this document which can be reduced to the same equation...

EDIT: mechjeb source code also uses basically the same equation

 

kamik423

Edited by Kamik423

Share this post


Link to post
Share on other sites
1 hour ago, Kamik423 said:

It starts burning too early, as you see in the video and then descents with lower throttle, which is quite inefficient.

......

EDIT: mechjeb source code also uses basically the same equation

So there you have it.  You're doing it right :).  Slowly hovering down the last dozen meters or so isn't inefficient enough to worry about because it only lasts a few seconds.  More importantly, it gives you a useful margin of error.  There's a bit of latency in the system, plus inherent inaccuracies in the measurements and math.  These combine to make it really suicidal to attempt to have max thrust stop you just as you touch the ground.  It's a lot safer to stop a few meters up and then slowly lower yourself the last little bit.

Share this post


Link to post
Share on other sites

Flight #3 - This took a while to get right, especially since I want the script to be as universal as possible

 

Boost until AP>20k. Then perform a boostback at AP.

Boostback waits until distance to impact point is greater than the distance to the launchpad AND until the angle between the impact-vector and the launchpad-vector (projected on a surfaceparallel plane) is less than 45º, so it doesn't continue flying in the wrong direction.

All scripts have been adjusted, especially the glidetowards. It is now steering relative to the velocity vector and not relative to the launchpad vector, because it has been aiming too low all the time.

Full source code as always on GitHub.

PARAMETER landingpad.
PARAMETER overshoot.

LOCK impact TO -landingpad:POSITION.

SET k TO 9.

UNTIL (VANG(VXCL(SHIP:UP:FOREVECTOR, landingpad:POSITION), VXCL(SHIP:UP:FOREVECTOR, impact)) < 45) AND (VXCL(SHIP:UP:FOREVECTOR, impact):MAG - overshoot > VXCL(SHIP:UP:FOREVECTOR, landingpad:POSITION):MAG){ //Less than 45º off of the launchpad to ensure right direction, and distance to impact > distance to launchpad
    LOCK STEERING TO VXCL(SHIP:UP:FOREVECTOR, landingpad:POSITION):NORMALIZED * 2 - SHIP:VELOCITY:SURFACE:NORMALIZED.
    LOCK THROTTLE TO 1.
    SET ps TO V(0,0,0).
    SET vs TO SHIP:VELOCITY:SURFACE.
    SET as TO V(0,0,0).
    SET t TO 0.
    UNTIL ps:Z < -ALT:RADAR {
        SET t TO t + 1.
        SET as TO (- as:NORMALIZED * (as:MAG ^ 2 * k * (0.99997 ^ ALT:RADAR)) / (SHIP:MASS * 1000)) - SHIP:UP:FOREVECTOR:NORMALIZED * 9.81.
        SET vs TO VS + as.
        SET ps TO ps + vs.
    }
    SET impact TO ps.
}
LOCK THROTTLE TO 0.
LOCK STEERING TO RETROGRADE.

 

Edited by Kamik423

Share this post


Link to post
Share on other sites

Flight #4

 

Heavy Demonstrator!

This happened soon! It still is an ugly rocket. I will probably improve that in the next flight.

The side boosters have individual scripts, that stay dormant until action group 5 is triggered by the main core. This ensures that there is no conflict between the different cores. They basically execute the same script as in the last flight, but the boosters have hard coded touchdown coordinates.

It still is on a "dumb" trajectory, 75º, wich is just meant as a feasibility demonstrator, not an actual orbital boost. The second stage is just a simulator, there are filled ore tanks inside the fairing to simulate a payload.

The boosters don't try to avoid each other after separation, the just operate independently and hope... sometimes one (the southern one) loses a nosecone seconds after separation, or the bump into one another if they don't quite hit the landingpad.

At launch the first stage engines are throttled down to 50%, to enable the first stage to burn for a longer period of time that the boosters. Full power is restored after booster separation.

The other scripts have been tweaked a little to prevent over-steering and oscillating.

For some reason all parts of the rocket impact hundreds of meters short of the designated landing areas for the first few flights after starting KSP. After about 5 crashes it suddenly starts working and I have no idea why.

Hey, this doubles the number of successful landings you have seen from me so far!!!

 

 

Edited by Kamik423

Share this post


Link to post
Share on other sites
8 hours ago, Kamik423 said:

Heavy Demonstrator!

Bravo!  Simultaneous landings side-by-side on the VAB roof for extra style points, too :D  Very impressive.

How big of an impediment is it to have to worry about the distance between the boosters and the rest of the rocket?  Do the boosters have to get down safely before the rest of the rocket gets so far downrange that the game unloads the boosters?

Share this post


Link to post
Share on other sites

Ok, I'm impressed. Have some rep-likes.

Your boosters sure freak out a bit immediately after sep. (More the radials and the core booster in the older videos.) I'm guessing that's due to aerodynamic forces and not some strange kOS script artifact? More than likely that motion exceeds the lateral structural limits on the booster, but that's one of the joys of playing kerbal - we can safely ignore such things. :wink: 

8 hours ago, Kamik423 said:

The other scripts have been tweaked a little to prevent over-steering and oscillating.

I hear ya there. I've spent entirely too many hour playing with different algorithms for my RSS/RO launch scripts to keep the oversteer in check, and I still haven't found anything perfect.... just close enough.

Edited by Cydonian Monk

Share this post


Link to post
Share on other sites
6 hours ago, Geschosskopf said:

How big of an impediment is it to have to worry about the distance between the boosters and the rest of the rocket?

I am not having any issues with the rest of the rocket, however after separating the boosters swing quite dramatically and about one third of all times the nosecone of the southern booster collided into an engine of the northern booster, that is fixed now.

7 hours ago, Geschosskopf said:

Do the boosters have to get down safely before the rest of the rocket gets so far downrange that the game unloads the boosters?

I actually haven't had any problems with that, the furthest distance I have seen is 50 km, and that is the payload/second stage section plummeting to their death when following the boosters (S2 cannot stage if it is not the active vessel). Vessels do not seem to unload during flight, however one the touch down they immediately do

6 hours ago, Cydonian Monk said:

Your boosters sure freak out a bit immediately after sep. (More the radials and the core booster in the older videos.) I'm guessing that's due to aerodynamic forces and not some strange kOS script artifact? More than likely that motion exceeds the lateral structural limits on the booster, but that's one of the joys of playing kerbal - we can safely ignore such things.

You are right with that, I traced the issue back to the angle of attack during separation: the rocket aims at a constant 75°, which is about 10° off prograde during separation, which causes massive shear forces on the mostly empty boosters. When pitching the rocket down to prograde shortly before separation it tends to be much more stable. Also when the boosters are activated through AG5 during staging they cannot immediately take control, because KOS crashes when receiving throttle / steering calls from multiple cores. So I built in a one second wait, wich I have now replaced with a 0.01 second wait until they can take over control. This causes them to stay prograde during and after separation.

 

thanks for your input!

Share this post


Link to post
Share on other sites
6 hours ago, Kamik423 said:

I am not having any issues with the rest of the rocket, however after separating the boosters swing quite dramatically and about one third of all times the nosecone of the southern booster collided into an engine of the northern booster, that is fixed now.

Add a few Sepratrons to kick the boosters further apart.  Sepratrons are my favorite part in the whole game.  Besides being useful for their intended purpose, they have countless amusing and entertaining uses :)

 

6 hours ago, Kamik423 said:

I actually haven't had any problems with that, the furthest distance I have seen is 50 km, and that is the payload/second stage section plummeting to their death when following the boosters (S2 cannot stage if it is not the active vessel). Vessels do not seem to unload during flight, however one the touch down they immediately do

That's good to know.  Thanks.  I'd always assumed that you had to design the whole rocket so that the initial boosters could be safely down before the rest of it got too far away, with obvious limits on overall efficiency.

Share this post


Link to post
Share on other sites
14 hours ago, Geschosskopf said:

Add a few Sepratrons to kick the boosters further apart.  Sepratrons are my favorite part in the whole game.  Besides being useful for their intended purpose, they have countless amusing and entertaining uses :)

But those would not be reusable, would they? I want to basically refuel the parts and just launch them again. If proximity becomes a problem I want write something using RCS or boost them apart a little.

Share this post


Link to post
Share on other sites
10 hours ago, Kamik423 said:

But those would not be reusable, would they? I want to basically refuel the parts and just launch them again. If proximity becomes a problem I want write something using RCS or boost them apart a little.

Well, decouplers aren't reusable, either, so you can't reassemble the boosters back into a rocket whether you use Sepratrons or not.  Especially if you park the boosters on the VAB roof :wink:

That said, though, while no SRBs (including Sepratrons) are refuelable in stock, it's easy enough to change that with ModuleManager.  You just have to patch the resources file so you can pump SolidFuel, then you can use large RSBs on refueling rovers the same as you use large LFO tanks.

Share this post


Link to post
Share on other sites
35 minutes ago, Geschosskopf said:

Well, decouplers aren't reusable, either, so you can't reassemble the boosters back into a rocket whether you use Sepratrons or not.  Especially if you park the boosters on the VAB roof :wink:

That said, though, while no SRBs (including Sepratrons) are refuelable in stock, it's easy enough to change that with ModuleManager.  You just have to patch the resources file so you can pump SolidFuel, then you can use large RSBs on refueling rovers the same as you use large LFO tanks.

I have thought about that, but it just seems un-SpaceX-y. I have considered liquide sepratron (those little orange ones) firing for a second or so, but I think I will be able to safely fly the boosters apart in different ways, without adding more engines. This I will however only add if necessary. Just stay tuned :wink: 

Share this post


Link to post
Share on other sites
44 minutes ago, Kamik423 said:

I have thought about that, but it just seems un-SpaceX-y. I have considered liquide sepratron (those little orange ones) firing for a second or so, but I think I will be able to safely fly the boosters apart in different ways, without adding more engines. This I will however only add if necessary. Just stay tuned :wink: 

Surely SpaceX uses explosive bolts?  I really don't know what they use to keep their boosters from hitting the core, but I'm sure it's some simple, light system that probably needs to be replaced after 1 use.

Share this post


Link to post
Share on other sites

I AM A MORON

I was so proud of my iterative numerical trajectory integration, but it was just not working out. I found the mistake:

    SET ps TO V(0,0,0).
    SET vs TO SHIP:VELOCITY:SURFACE.
    SET as TO V(0,0,0).
    SET t TO 0.
    UNTIL ps:Z < -SHIP:ALTITUDE {
        SET t TO t + 1.
        SET as TO (- as:NORMALIZED * (as:MAG ^ 2 * k * (0.99997 ^ ALT:RADAR)) / (SHIP:MASS * 1000)) - SHIP:UP:FOREVECTOR:NORMALIZED * 9.81.
        SET vs TO vs + as.
        SET ps TO ps + vs.
    }

can you spot it?

I am using a newtonian drag approximation (I think KSP is using this one too).

The equation for this is F = 0.5 * v^2 * k * p

can you spot it now?

the acceleration is proportional to v^2 not a^2. that explains so much.

Everything is working so well now!!!!

    SET ps TO V(0,0,0).
    SET vs TO SHIP:VELOCITY:SURFACE.
    SET as TO V(0,0,0).
    SET t TO 0.
    UNTIL ps:Z < -SHIP:ALTITUDE {
        SET t TO t + 1.
        SET as TO (- vs:NORMALIZED * (vs:MAG ^ 2 * k * (0.99997 ^ ALT:RADAR)) / (SHIP:MASS * 1000)) - SHIP:UP:FOREVECTOR:NORMALIZED * 9.81.
        SET vs TO vs + as.
        SET ps TO ps + vs.
    }

EDIT: Is there a petition I can sign to get KOS syntax highlighting on the forum?

Edited by Kamik423

Share this post


Link to post
Share on other sites

Finally, I finished it! Here is a complete mission completely autonomously controlled and 90 percent reusable! Thanks for sticking with me for this long!

 

Share this post


Link to post
Share on other sites

How adaptable is this script? I'd like to use one of my launch systems thats basically Falcon 9, however my boosters are about twice the size of yours. What would be the parts of code I change for mission specifics. Great videos, looking forward to the Athena stuff as well! 

Share this post


Link to post
Share on other sites

Thanks, glad you like it

Well, you could theoretically adapt it to do most of that.

Select the 2mF-c/b1/b2/s2 as the scripts for the core, booster 1, 2 and the second stage respectiveley. You would have to change the values plugged into the returnTo function, the fist one is the landingpad, the second one the 'coefficient of friction' (not really, but kinda) if it falls to short adjust it up, and the other way around, and the second one is the height offset. If it touches down too hard adjust that up as well (and the other way around). Also in the core script adjust the two fuelcutoff points. It stages once the fuel in the respective parts falls under this limit. (B=booster, C=core).

Part naming scheme (name those parts, otherwise the script will not work as intended):

CSE: core stage engine

RTB: reserve tank booster (reserve tank of the booster, can partially be emptied. This is the one checked for the remaining fuel. Can only be one tank per booster)

RTC: reserve tank core

BE: booster engine (radial boosters, not core)

CSE: core stage engine

also put nothing on actiongroup 5 and 6 (they get called to signal activation to the other scripts, not sage the parts. 5: booster separation, 6: second stage separation)

action group one is called after fairing deploy, two for satellite deploy.

also you might need some RCS

 

I intend for project Athena to handle more of this by itself.

Share this post


Link to post
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.