Finding Maneuvers with Magic - Hill Climbing in kOS
HTML-код
- Опубликовано: 27 ноя 2024
- Now that we're able to execute maneuvers accurately, we need to find which maneuvers we need. This time, rather than diving into the math and physics, we'll use two simple functions. One will give us a score for a maneuver, and the other will make tiny naïve improvements. This pair allows us to hone in on a perfect circularization burn using a strategy known as hill climbing!
This tutorial is running on KSP version 1.4.1, and kOS version 1.1.5.2.
READ THE FRIENDLY MANUAL
ksp-kos.github...
GRAB THE CURRENT SCRIPT
gist.github.co...
SUPPORT THIS SERIES
/ cheerskevin
GET THE KOS MOD
ksp-kos.github...
DOWNLOAD KERBAL SPACE PROGRAM
kerbalspacepro...
WOOOT! I did the thing. I'm def going to refactor that hill climb though. It works for the purposes given, but I want to give it the ability to perfectly circularize within 100m.
Nice! I keep tinkering and playing with this one. So much fun! Thank you! I am learning alot :)
Loving the series cannot wait for the next video!!!
Great video! I’ve been binge watching all of your kOS videos. I would love if you started a new kOS series, but I guess you must be pretty busy with your day job now
You should double step size if it improves and halve it if it doesn't, should make it quite a bit quicker.
Yehp! You can actually extend this idea out even further by moving in proportion to the improvement - a technique known as gradient descent :)
I know, but what I mentioned would just be something that would be very easy to implement.
(edit) and very easy to understand.
Hill climbing with gradient descent. I get why people find this topic confusing sometimes.
Really liking this series!
Thanks! Really glad you're enjoying it :)
I really like your series! Thanks for your effort!
I have a little refactoring suggestion: what do you think about using a node-object instead of a list as the method parameter and return value? Using this you have named parameters for accessing the individual components of the vector. Should make the code a bit clearer than a list where you have to remember the correct indices of the values.
Absolutely right about it being cleaner - however, there are cases where we want to be able to optimize only a subset of the maneuver values. The reason for using something generic like a list, is that we can pack and unpack data of any format - and we'll make use of that in the next video :)
CheersKevin cool, looking forward to the next video to see what you‘re up to!
Love this series, and your Kerbal Space Programming series! I actually like following these series with a more current kOS mod than what you had when recording--I have to dig into the updated mod and find the way to make it operate as you intended in your code. Frustrating, but more rewarding. In the hill climbing algorithm, is there something that would prevent the code from walking the planned maneuver earlier than present time? If you executed this code when your craft had just passed the apoapsis, the logic should prefer a burn time earlier rather than later. The code would walk backwards second-by-second, until it reached the apoapsis you had just passed (unless something inherent to kOS prevents this), correct?
Thanks for the kind words - to your question, there's nothing inherent in the hill-climbing algorithm that prevents it from looking at burn times in the past. In a later episode, we add a little wrapper function to guard against this :)
@@CheersKevin I've been mostly absent from kOS programming for well over a year. Just this week, I had a problem at work that I couldn't solve by putting into a spreadsheet, but I knew had a mathematical solution. I remembered your example of solving this problem using the hill-climbing algorithm. With a lot of googling, I was able to write some VBA code to implement a similar algorithm (finding the Equal Time Point between divert airports for long-range flight). Thanks!
I use a different approach to circularize:
(From now on, consider Ap and r the distance from the center of the planet respectively of the apoapsis and the ship, let also phi be the true anomaly of the orbit)
I found that if you pitch at
arctg(-cotg(phi/2)*(1+r/Ap))
In the direction of the orbit, your apoapsis does not change whichever is your thrust;
then wait for the right moment and lock the throttle to
requiredAcc/maxAcc
where requiredAcc is
[(speed at Ap of the circular orbit) - (speed at Ap of the current orbit)]/eta::apoapsis
and stop right when you reach apoapsis
Cool. Although aren't the "speed at Ap of the circular orbit" and "speed at Ap of the current orbit" the same thing?
you could have create a maneuver mnv instead of the list and add it from the beginning of the function to keep your function simplier, and pass the maneuver around. and would also had help your cpu usage a lot.
How do you find a maneuver that transfers between planets?
Is this scoring system machine learning?
@Notative No it actually is. Very crude, but it is how genetic algorithm works.
i realize this is an old video, but maybe someone can help me out. i've gotten as far as getting the script to start calculating maneuvers, however when it's done calculating the best maneuver it removes the final iteration. i'm doing something wrong, obviously. any ideas?
Stop doing it wrong. :)
I am a beginner in kOS and I started today. I do have limited knowledge in programming and my approach to it was just brute forcing. It's not perfect, but since the apoapsis is already the target orbital height, meaning we should put the maneuver there, all that we need to do is prograde. So I set up a little script that constantly made and removed maneuvers with increasing prograde value until the maneuvers periapsis went into a certain error interval of apoapsis.
18:48 for later