This is a masterclass in bridging the gap between orbital mechanics and control theory through elegant automation. It elevates Kerbal Space Program from a mere game to a sophisticated sandbox for genuine aerospace engineering.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Using KOS to Code a Super Smooth GRAVITY TURN | Kerbal Space ProgramAdded:
How's it going, ladies and gentlemen?
I'm working on my second prototype of a self-landing rocket. Trying to do what Elon Musk did with the Falcon 9 in my own way. So, it's quite a bit different than the last rocket I had. The last rocket I had had one engine and was very tiny. I have four huge fuel tanks now, nine engines. I had to put some stabilizers on the bottom of this one on some decouplers because it won't fly up straight. I'm going to have to figure that out later on, but let me go ahead and show you what we got. We're adding a huge feature today. First, I'm going to do what we did in the last video and just test out to make sure that the very simple suicide burn I have works. I also need to pay attention to how high we get and how fast we're going at certain points.
Let's go ahead and run that code.
Just see what the rocket does.
I already adjusted its height that it starts the burn at, so it's not the exact same code as my last video.
Just cuz this is a heavier rocket.
But, this is my first run, so I really don't know what's going to happen here.
We could still smash into the ground. I added about 50 ft. Oh, I got to stage the stage the stupid fins or this thing's going to hit the ground.
Oh, I might have screwed it. I might have screwed it by not staging fast enough.
Come on, baby. I believe in you.
All right, does it have it?
Oh, yeah.
It has it.
Actually, it doesn't have it.
Oh, no.
Catastrophic.
Hm.
Hm. Well, back to the drawing board on that one, huh? Right now, we're starting at 775, so that's way too high.
So, I'm going to go 760.
760 might be perfect. I also realized I don't have any landing gear. I'm kind of hoping this is just going to work without it. Fat chance, but we got to find out. All right, I want to see something impressive here, rocket.
It's going to smack into the ground.
Oh.
Yeah, that's just not going to do it, is it?
So, I think the problem I'm encountering right now is I need to have landing gear for it to count as landed.
I think landing on the engines is just bugging it out. What's the best landing gear I have though? I only have micro struts still, and these engines are far too big for a micro strut. Now, we're in business, baby. This whole thing going to land on those little itty-bitty legs.
Now, the rocket's all tilted over and leaning weird. I need to start using those stupid things that hold rockets. I do have high hopes for this one, honestly.
60 ft, a little bit more weight.
Come on.
All right.
All right, I think we're good. I think we're good.
I just got to make some changes to the code. The landing gear was too slow to pop out, and I think it needs like 5 more ft before it starts the burn.
Very good.
That's what I'm talking about, baby.
What just blew up though?
Oh, the landing gear. We just landed on the metal girders on the bottom. What the heck? So, those those landing gear must be too too fragile to survive.
Interesting. All right, well, we got the code figured out and the height for the landing gear.
Time to show you the gravity turn. Then if we can combine the gravity turn and the self-landing part that's tweaked slightly, cuz I'll need a slow down burn in the atmosphere. If we can do the whole thing, we can end the video and make way for prototype number three, which is going to be the most intense prototype yet. I just want to say this while I'm in the middle of the video and most of the people are still listening.
Prototype three, I'm going to have to use something called state machines or I think it's just called a state machine.
How do I explain? I'm so bad at explaining code. I've used them before when I was making trying to make video games, but a state machine is like a bunch of different states something can be in. And then you put code inside those states. So like one state could be taking off, the next state could be gravity turn, and then one another state could be back to base burn. It's super complex. I'll show you when I get there.
Issue is it's probably going to take me a couple of weeks to figure that out.
So don't expect another one of these videos for a second. So this is the code I have for the gravity turn. I'm using variables in this one and the variable is just something you use to store data under some words.
Changeable data. It's like memory kind of.
So I have set turn start altitude ALT to 1,000.
I have set turn end altitude to 45,000 and final pitch to 10. And then this code just stages, locks the throttle, points the rocket straight up, and then it goes into a loop.
And what a loop is is a chunk of code that just runs continuously over and over again until a condition is met. So until ship apoapsis is greater than 80,000 this chunk of code is going to run over and over and over again. And this chunk of code takes our altitude variables that we set turns them into a fraction and then uses that fraction to slowly turn the rocket over. We're going to start a gravity turn at 1,000 m and at 45,000 m and this code is going to get us up to an apopsis of 80,000. And 80,000 ft is where our second stage is going to go off in orbit and our launching stage is going to turn back around, burn back to where it launched from and land next to it, hopefully.
All right, let's run this and see how this goes.
It is honestly so satisfying having the rockets fly themselves, though.
It really goes to show just how much error a human can bring into a situation. I'm terrible at flying these rockets.
Just having code do it for you really gives you that understanding of why they let robots fly things in real life.
Cuz if it was up to the actual pilots, they would be they'd be killing themselves left and right 100%.
As you can see, we started the gravity turn, though, and it's slowly pitching over. There's no like jarring pitches.
It's using that fraction to very nicely find its next angle.
Boom, there it goes, our stabilizers.
Now we're just out here tilting, brother.
Tilting. Okay, so let me click on the terminal. Come on.
I got it.
I'm going to run the code to land. Now, this code is not going to work because we're coming in from a way higher altitude. Everything we worked out in the beginning of this video was for an altitude of 2,000 falling down. So, we're going to pick up so much more speed. My bet is we're going to just dunk directly into the ocean and not see much engine happening, but I'm curious.
I'm curious to see what happens. We kind of need to see what happens here to be able to incorporate both the scripts together. Oh, shoot. Here it goes nothing.
Oh, yeah. Straight into the water.
Okay, this is new.
We just flew into that water at like 960 m/s and didn't blow up.
Now, the rocket's going absolutely bonkers.
You know what?
I say we count it. That's a pretty reusable rocket to me. I mean, we can send a ship out here and pick this thing up. Still have our three girders here laying in the water, too. The only thing we lost is all of our engines. Still good to save money on the tanks, though, and all the all the computer parts up front. I combined the gravity turn code up front and I put our landing code at the bottom, and then I also tried to make a slow down burn right here. I don't know if this is going to work because I wrote this all by myself and I didn't put it into Perplexity to check it if it was going to work or not. I'm kind of just going to see if it works myself to see if I'm understanding how this thing goes. So, I have wait until altitude radar less than 10,000, then print start or print slowing down, lock throttle to one, then if ship velocity surface mag is less than zero, lock throttle to zero. Well, I actually don't think that's going to work now that I'm looking at it. If the ship velocity to the surface is less than zero, I don't think it ever goes into a negative number. I'm not even going to mess around with not throwing this into Perplexity. I am going to just do it real quick. Show you guys how to do that to work through some of the problems you may encounter in your code. Okay, so I just told it I just need this chunk to act as a slow down before the other loop runs. Then I paste in the code and let it think. I know people hate using AI or I shouldn't even say the word AI. I might freaking really screw my comment section up, but we'll just say a large language model.
People don't like them, but you got to kind of use them when you're coding sometimes. Fix logic, use something like this. Print slowing down lock throttle to one until ship velocity surface mag is less than zero, wait one, lock throttle to zero. And then this version down here fixes it for the altitude problem. So then we can set the altitude, figure out which altitude to slow it down at and then we can adjust the actual landing part as well to a new height.
And we technically don't want it to slow down all the way at 10,000 m, even though that's what the code is going to do right now. We can adjust that.
To slow it down just to a specific point.
All right, it's picking up speed.
Quite a bit of speed.
Maybe we should be doing a slow down right around here.
Was it like 19,000 ft?
Cuz it slow it burns to slow it down to cool it down. The Falcon 9 does. Oh, there goes that burn.
Yes, it's bleeding speed pretty slowly.
I'm not going to lie.
Oh, we're still going to smack into the water.
No shot.
Wait a second.
All right, now the rocket's going to freak out.
It doesn't like uh it doesn't like when it's not able to land.
So every time it's retrying, it's firing for way too long.
It should be locking the throttle to zero, though.
If it gets above 5 m/s, it should be doing that thing where it fires on and off and slows us down.
And now you're out of fuel, idiot.
Time to suffer the consequences. See if it blows up from this height.
Way more damage. That thing disintegrated way more than when it went in at 900 m/s. The game must have been bugging bugging. Kind of already getting excited for version three of this rocket, but I need to fix this version for this video. All right, so I'm at a point where I've almost been at this for another whole hour trying to get these settings correct. I'm going to run the edited version of the code one more time and what we get is what we get.
Fortunately, I can't stay here forever trying it. I'm just noticing the more and more I go on, the more and more I need improved code already. I'm working with some simple stuff that got me here, but it's not going to get me further than I need to go. So, one of the things is I'm like getting pretty close to the ground and I'm just pulsing too much, so I think I'm going to drop this by hopefully like 5 ft. What I was at 285, we're going to do 80.
2580. And I hope that gets me to where I need to be. I also added four RCS RCS tanks at the top and four RCS thrusters around the top of the rocket.
Cuz what was happening is I was getting close to the water and then it was just pulsing too much and it was the pulse was too powerful to keep it stable. The reaction wheel couldn't do it alone, so I'm hoping this addition plus the change in altitude is going to going to get us there. But like I said, whatever I get, I'm taking.
If it's a failure, it's a failure. Not everything is going to be a [clears throat] success on this channel, especially prototypes.
My game is running like garbage, too, cuz I've been at it for so long.
It's time warping now.
Okay, here we go.
Comes the slow down.
Please, rocket, just do something cool.
I need this.
RCS is on.
Slow down burn completed.
Hopefully that 5 ft I took off isn't going to sit us into the water. All right.
Hopefully the RCS thrusters keep us steady if we need them.
You know what?
I'm honestly not mad at that. For how long I've been at it, the rocket is still put together in one piece.
That's all you can really ask for. So, right now, if I wanted to, I could add some more code to this, put a second stage on top, and use this type of rocket to reliably launch stuff up in orbit, have it land in the water, and recover the vessel. Now, that would defeat the purpose of trying to make it like a Falcon 9 rocket, because obviously there would be a way easier way to do this without mods, without anything. You would just attach parachutes, and a bunch of them to the side of your rocket, and you could recover your boosting stage out in the ocean. So, I need to advance the code, and get it so we have everything. We have the state machine, we have another new feature, the burn back to the space station. We need to land somewhere around here. I'm going to have to figure out how to target somewhere around here, maybe by driving a vehicle out and targeting the vehicle. Either ways, I want the rockets landing around the launch pad. And it's going to take me a while, guys. So, if you're enjoying these prototype videos, I'm sorry, but the next one is going to take me weeks if not a month or two. I'm a grown man that works a full-time job and has a girlfriend on the outside. It's very hard to find time to do stuff, especially nerdy stuff like this. But in the meantime, I hope you enjoy all the other KSP content I'm putting out. I will release a video with a full I think prototype three. I think we might go prototype three with the full system working.
And then I might go and try to actually recreate one to one what Elon Musk is working with, the Falcon 9. And then if we want to get crazy, maybe we go on in the future create a Starship. I'm also thinking I want to build a space shuttle replica and fly it off of the KOS system at some point. These are huge ideas that might never show up. Definitely going to take me a huge amount of time, but there's a good chance you might see them in the future. If you enjoyed watching up till this point, hit me with one of those. I love those so much. Thanks to all the nice people who have been subbing and commenting recently, and I hope you enjoy the rest of your day.
Deuces.
Related Videos
Beyond Robotics | European Rover Challenge 2026
beyondrobotics
189 views•2026-06-01
Beatbot Sora70: JetPulse Technology and AI obstacle avoidance and navigation!
DroidModderX
26K views•2026-06-02
Tesla FSD 14.3.3 Hits Phoenix Streets - FIRST LOOK
anthonystesla
114 views•2026-05-29
Elon Musk Just Revealed Fremont Line for Optimus Gen 3 Mass Production
TheAINexusOfficial
180 views•2026-05-30
人機一体「零式人機 ver.2」 子ども企画【おもしろ発見!モビリティー】 #乗り物 #automobile #robot #shorts
KyodoNews
1K views•2026-05-28
China’s New Luna AI Robot Looks Shockingly Human...
NextGenHumanoids
850 views•2026-05-28
Reachy Mini: the $300 open source robot you can actually hack — Andres Marafioti, Hugging Face
aiDotEngineer
662 views•2026-05-29
柔軟指×AI画像処理食品の仕分け作業システム!#柔軟指 #ロボット #自動化 #製造業をもっと盛り上げたい
KiQ_Robotics_Corp.
113 views•2026-05-28











