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...

Комментарии • 26

  • @xTwisteDx
    @xTwisteDx 5 лет назад +2

    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.

  • @NicholasJJackson
    @NicholasJJackson 6 лет назад +1

    Nice! I keep tinkering and playing with this one. So much fun! Thank you! I am learning alot :)

  • @n111254789
    @n111254789 6 лет назад +1

    Loving the series cannot wait for the next video!!!

  • @matthewp4046
    @matthewp4046 2 года назад

    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

  • @redline6802
    @redline6802 6 лет назад +7

    You should double step size if it improves and halve it if it doesn't, should make it quite a bit quicker.

    • @CheersKevin
      @CheersKevin  6 лет назад +5

      Yehp! You can actually extend this idea out even further by moving in proportion to the improvement - a technique known as gradient descent :)

    • @redline6802
      @redline6802 6 лет назад +1

      I know, but what I mentioned would just be something that would be very easy to implement.
      (edit) and very easy to understand.

    • @offtheball87
      @offtheball87 6 лет назад +1

      Hill climbing with gradient descent. I get why people find this topic confusing sometimes.

  • @MaximLaeveren
    @MaximLaeveren 6 лет назад

    Really liking this series!

    • @CheersKevin
      @CheersKevin  6 лет назад

      Thanks! Really glad you're enjoying it :)

  • @flwi
    @flwi 6 лет назад

    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.

    • @CheersKevin
      @CheersKevin  6 лет назад

      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 :)

    • @flwi
      @flwi 6 лет назад

      CheersKevin cool, looking forward to the next video to see what you‘re up to!

  • @nghicks42
    @nghicks42 6 лет назад +1

    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?

    • @CheersKevin
      @CheersKevin  6 лет назад +1

      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 :)

    • @nghicks42
      @nghicks42 5 лет назад

      @@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!

  • @Oscar1618033
    @Oscar1618033 5 лет назад

    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

    • @chrisloach9658
      @chrisloach9658 4 года назад

      Cool. Although aren't the "speed at Ap of the circular orbit" and "speed at Ap of the current orbit" the same thing?

  • @amelia_Hope
    @amelia_Hope 4 года назад

    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.

  • @FutureAIDev2015
    @FutureAIDev2015 4 года назад

    How do you find a maneuver that transfers between planets?

  • @RuohongZhao
    @RuohongZhao 4 года назад +1

    Is this scoring system machine learning?

    • @fangslash
      @fangslash 3 года назад

      @Notative No it actually is. Very crude, but it is how genetic algorithm works.

  • @evrolicious
    @evrolicious 3 года назад

    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?

    • @Bendigo1
      @Bendigo1 3 года назад

      Stop doing it wrong. :)

  • @melone3631
    @melone3631 Год назад

    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.

  • @JoMiMi_h
    @JoMiMi_h 4 года назад

    18:48 for later