gisikw / ksprogramming

Getting to space with kOS!
https://www.youtube.com/playlist?list=PLb6UbFXBdbCrvdXVgY_3jp5swtvW24fYv
MIT License
99 stars 17 forks source link

Episode 31 how to get it running #12

Closed Oghara closed 8 years ago

Oghara commented 8 years ago

Hey Kevin, I hope I'm not just too dense. Your advanced ascent profile of Episode 31 sounds really interesting. I understand the theory behind it but the coding is hard for me to understand since I have no programming background. I bing watched all your KSProgramming episodes and now got a little grasp.

However I can't get the Ascent AI to work. I load the boot.ks to my CPU, and I named the Vessel that I build myself "ascentnav" since no craftfile was in the episode folder. I also got the libs in the scriptfolder too.

Some help would be appreciated :)

gisikw commented 8 years ago

Heya!

So, that episode is a tricky one, and it will most likely take a pretty long time for it to converge on anything particulary useful (the data I got for that episode took about five days worth of constant playtime to collect). Using the original bootfile won't work, as it's designed to delete update scripts after reading them, which doesn't play nicely with all the reverting we're doing.

That said, here's how the scripts should work:

Setup

Running the Algorithm

Profiling a Result

If you wanna grab more detailed data for a particular example, you can copy ascentnav.update.3.ks to boot.ascent.ks, update the chromosome in that file, and let things run. It should log out its telemetry to ascent.js. If you then open up profile.html in a browser, with ascent.js in the same directory, you should be able to review the data in chart form.

Let me know if you're encountering any other specific errors. Definitely was a pretty code-heavy episode, so was difficult to try and catch everything in a reasonable time. Cheers!

Oghara commented 8 years ago

Hey, sadly I did not manage to get it to work yet. I get an error on line 126 "until 0 ga_next() ^" The genetics.ks is in the scripts folder, I checked since it should get build in there.

Here is what I did. Put float.ks, genetics.ks, ascentnav.update 1-3 into script folder renamed update.1.ks into boot.ascent.ks Made a 1 Stage craft. mounted the boot file launch. after initializing. deleted bootfile and renamed update.2.ks into bootfile name since nothing happend opened terminal, switch to 0 and ran bootfile manually

Here is my kOS and KSP version "VERSION": { "MAJOR": 0, "MINOR": 20, "PATCH": 0 }, "KSP_VERSION": { "MAJOR": 1, "MINOR": 1, "PATCH": 0 },

so to bother you, but the code is to complicated for me to understand. lastly I realize that it will take many iterations to get something good, that is how evolution works :)

Thanks for your help and the great KSP series! albeit to complicated for me for a few episodes now

gisikw commented 8 years ago

Hmm, well that certainly is odd. I can't update to the latest version of KSP just yet, so I can't provide direct support. If you could provide the error message you got though, it might provide some indication as to what the root cause is.

And yehp, this code is definitely more complex than most of what we've been going through. Was more intended as a proof-of-concept, so that we could pull out the ideal tuning values for future launches. This also came out just before function delegates, so combining that with the need for revert-to-launch put some pretty heavy limitations on how well-abstracted the code could get.

Oghara commented 8 years ago

It is literally the error i got.

http://abload.de/img/unbenannt-1orufu.png

Since I got quite an amount of other mods, the last thing that is left to do. Is a clean install and try it there, however it seems unlikely that that is the issue. I will do it though.

gisikw commented 8 years ago

Ah, so the error is being cut off because of the small screen size. If you were to comment out the lines that manipulate terminal size, you'll likely get a much more helpful error trace :) (that was there to try and keep the terminal small for the video)

Oghara commented 8 years ago

Yes that helped alot. Still looks like a wild goosechase :( http://abload.de/image.php?img=unbenannt-38if3e.png

gisikw commented 8 years ago

Aha, okay, that makes some sense! I'll bet that double quote characters aren't getting logged out to the ga_data file (this was written back when we had to do some hackiness to make that work).

If you update the genetics.ks file near the top to use set q to char(34) instead of the lexicon hack, then start over with the ascentnav.1 script, I'll bet the chromosome get correctly logged out as strings.

Cheers! That's a good catch :)

Oghara commented 8 years ago

Okay good that is makes sense to you! After replaceing the "dumb" with your version it started working.

It did return to launch, but didnt restart the update2 file which was set as a boot file. But after i changed the CRAFTname into the boot.CRAFT.ks all started to work like a charm! looking forward to get a good launchprofile for a far release :)

thanks a lot for your work and your lightning fast help! :100:

Oghara commented 8 years ago

Okay everything is working fine now, have been running it for the last 12 hours without ksp mucking around. The only issue I had was from tabbing out, somehow it changed the alogrithm and it aimed for 60.000.000.000 meters instead of 100.000 so i had to initialize again, but if i just let it run ksp seems stable as well.

one question though, i didnt understand how i am supposed to use the analyze tool, do I need to start that for every try or just after or before trys.

and how can i extract an ascent profile?

gisikw commented 8 years ago

Oh, that is very strange. I left the game running on a separate machine, so I didn't test any of the tabbing-out stuff.

As far as analysis goes, the ascentnav.update.3.ks file will write out an ascent.js file with the flight telemetry. You need to swap out the actual chromosome that you want in that file, and it'll go ahead and write out the info. In theory at least, opening the profile.html file, with ascent.js in the same directory, should provide the dashboard, though that could be a little bit iffy. But this does mean that you have to basically stop the algorithm, so you can test the one chromosome you want more info on.

As far as getting the data out, if you look at ga_log.txt, which the GA algorithm is writing out to, you should see entries like this:

  [19]= LIST of 2 items
    [ 0]= 00111111100100010001100001000101011000000011010001111111001111010011111000001010101100010100000011000010111001100111101010001100010000000001110001001000101001100100001010110001111011010110101001000111110100001011011110001010
    [ 1]= 13565.3763164921

The first item is the chromosome, and the second item is the score. In the third ascent script, the chromosome gets unpacked, e.g.

// Get values from chromosome
local t_mul is 1/max(to_float(chromosome:substring(0,32)),0.0001).
local t_exp is 1/max(to_float(chromosome:substring(32,32)),0.0001).
local t_off is 1/max(to_float(chromosome:substring(64,32)),0.0001).
local p_mul is to_float(chromosome:substring(96,32)).
local p_exp is 1/max(to_float(chromosome:substring(128,32)),0.0001).
local p_off is to_float(chromosome:substring(160,32)).
local cut   is to_float(chromosome:substring(192,32)).

Inside that file, you can see exactly how they're used (the throttle values actually tune the thrust-to-weight ratio, not the throttle itself, for example). But if you look at where it's setting the steering and throttle, you should be able to work out how it's grabbing those values from the long 101010101 sequence.

If it helps, I ended up extracting the values from a "good" chromosome to use in a later script, and you can see how that ended up being used to manage throttle and pitch in episode 37 here: https://github.com/gisikw/ksprogramming/blob/master/episodes/e037/herald_mission.ks#L31

I'm gonna go ahead and mark this issue as closed, since the problem you were encountering has been resolved. But definitely feel free to add further questions if stuff isn't working out! Cheers :)