-ctn- Posted February 28, 2016 Share Posted February 28, 2016 Nice! How do you get kOS to calculate the gravity of the body? I tried looking but could not find a way for it to find that out - it was up to me to "hard code" that in. Link to comment Share on other sites More sharing options...
Kartoffelkuchen Posted February 28, 2016 Share Posted February 28, 2016 7 minutes ago, -ctn- said: Nice! How do you get kOS to calculate the gravity of the body? I tried looking but could not find a way for it to find that out - it was up to me to "hard code" that in. set g to body:mu / body:radius^2. And if you need the g at the altitude of your ship, just do this: set g to body:mu / (body:radius+altitude)^2. Link to comment Share on other sites More sharing options...
-ctn- Posted February 28, 2016 Share Posted February 28, 2016 Nice! That's a fair bit more reliable than my version. As I said, all it does is loop between throttle at 0.5 if vertical speed is greater than or equal to 2m/s and throttle at 0 if vertical speed is less than 2m/s. When it works, I get a nice slow touchdown from 40 meters altitude, but if the parachute doesn't slow my speed enough, the engines won't kick on and I crash. Link to comment Share on other sites More sharing options...
Kartoffelkuchen Posted March 1, 2016 Share Posted March 1, 2016 I've now highly improved my code, and it is really much better: Link to comment Share on other sites More sharing options...
maculator Posted March 1, 2016 Share Posted March 1, 2016 (edited) I could use some help please :/ Expet for the regulation of thrust near the AP I'm quite happy with the script I put together. I have no real experience in coding. The problem: My engine refuses to shutdown when the script ends and I really can't figure out why! It's been bothering me the whole evening. It truly fullfills the definition of insanity right now ... here is my script, please help: Spoiler //launch.ks //prepare vessel: sas off. rcs off. lights off. set throttle to 0. gear off. clearscreen. //define orbit: set targetapoapsis to 75000. set targetperiapsis to 75000. //initial logo: print "(c)maculator" at (35,35). //make sure, script only activates on launchpad: set task to 02. if alt:radar < 50 { set task to 01. } until task = 12 { //Liftoff: if task = 01 { lock steering to up. lock throttle to 1. stage. set task to 02. } //gain altitude: else if task = 02 { lock steering to heading (90,90). lock throttle to 1. if ship:altitude > 200 { set task to 03. } } //turn 5 degrees east: else if task = 03 { lock steering to heading (90,85). lock throttle to 1. if ship:altitude > 8000 { set task to 04. } } //gravity turn: else if task = 04 { set targetpitch to max (3,90*(1-alt:radar/35000)). lock steering to heading (90,targetpitch). lock throttle to 1. if ship:apoapsis > targetapoapsis { lock throttle to 0. set task to 05. } } //cost to the edge of atmosphere: else if task = 05 { lock steering to heading (90,0). if altitude > 70000 { set task to 06. } } //cost to circulationburn: else if task = 06 { if eta:apoapsis < 55 { set task to 07. } } //start circulationburn: else if task = 07 { if eta:apoapsis < 50 { lock throttle to 1. set task to 08. } } //check if burn is complete or needs tweaking: else if task = 08 { if (ship:periapsis > targetperiapsis) or (ship:periapsis > targetapoapsis * 0.96) { lock throttle to 0. set task to 12. } else if (ship:apoapsis > targetapoapsis){ lock throttle to 0. set task to 09. } } //tweak circulationburn: else if task = 09 { if eta:apoapsis < 25 { lock throttle to max (1,(ship:apoapsis - ship:altitude)/1000). set task to 10. } } //check again: else if task = 10 { if (ship:periapsis > targetperiapsis) or (ship:periapsis > targetapoapsis * 0.96) { lock throttle to 0. set task to 12. } else if eta:apoapsis > 35 { lock throttle to 0. set task to 11. } } //tweak again: else if task = 11 { if eta:apoapsis < 25 { lock throttle to max (1,(ship:apoapsis - ship:altitude)/1000). set task to 10. } } //finalisation: else if task = 12 { set throttle to 0. panels on. lights on. unlock steering. print "finished". } //stageing if stage:liquidfuel < 1 { stage. } print "current mode:" + task + "/12" at (10,10). print "altitude:" + round (ship:altitude) + " " at (10,12). print "apoapsis:" + round (ship:apoapsis) + " " at (10,13). print "periapsis:" + round (ship:periapsis) + " " at (10,14). print "eta to ap:" + round (eta:apoapsis) + " " at (10,15). print "(c)maculator" at (35,35). } I just saw I missused the max-function .... but that wont fix my problem, it just underlines how smart Iam. Also the 2. "tweaking" is pointless. Edited March 1, 2016 by maculator I'm not a smart man Link to comment Share on other sites More sharing options...
Alchemist Posted March 1, 2016 Share Posted March 1, 2016 this does nothing: set throttle to 0. use this instead: SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0. it will put the throttle input to 0. Link to comment Share on other sites More sharing options...
-ctn- Posted March 1, 2016 Share Posted March 1, 2016 8 minutes ago, Alchemist said: this does nothing: set throttle to 0. use this instead: SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0. it will put the throttle input to 0. Right. The reason why "set throttle" doesn't work is because it only sets the throttle to that value while the code is running. Once the code program ends, the throttle position is set by default to whatever you had it set to before you ran the code. So if you had your throttle up full-blast and then ran the code, when the code is completed, it will set your throttle back to full blast. The line of code Alchemist recommended will tell the code that you are setting a new "default" value for the throttle, so when the code program ends, it will return the throttle to this value Link to comment Share on other sites More sharing options...
maculator Posted March 1, 2016 Share Posted March 1, 2016 I changed the code it tells me at the end, that its at step 12/12, wich is the step where I set the throttel to 0 with the patch you guys suggested, but it stil doesn't work. Link to comment Share on other sites More sharing options...
Alchemist Posted March 1, 2016 Share Posted March 1, 2016 in the end, if the script ends on standby mode not just finishes, you need to UNLOCK THROTTLE. Alternatively, you can LOCK THROTTLE TO 0. at that point, but you still need to ensure the throttle input is set to 0 before the script finishes, because it will be unlocked Link to comment Share on other sites More sharing options...
maculator Posted March 1, 2016 Share Posted March 1, 2016 (edited) I thought it might have a problem since its running in an "else if" with 2 "ifs" executed parralel. So I moved it to the verry end of the script and it worked. Wow KOS definitly has a interresting learning curve. The basic script was done in a few minutes with the help of a tutorial then a bit tweaking for 90 minutes and then 3 houres of pure frustration. Thank god its finished! So now I only need to learn how to replace my 100% throttle setting with a variable and tweak the final steps to make it possible to bring vessels with realy low TWR into orbit. Edited March 1, 2016 by maculator Link to comment Share on other sites More sharing options...
-ctn- Posted March 1, 2016 Share Posted March 1, 2016 Well, it is a coding language. That's how it usually goes - the bulk of the program is done fairly quickly, and then dozens of hours are spent tweaking it or streamlining it. Link to comment Share on other sites More sharing options...
maculator Posted March 1, 2016 Share Posted March 1, 2016 I have one last question: Is there some sort of up to date libary of scripts? I've been looking on the KOS homepage and the tutorials really helped me but I did'nt find a libary with easy exampels for the variouse things it can do. Like hover, land, parachutes etc. I'm fairly new to this stuff and need some simple things I can see in action and lern from. Would be nice if someone could point me in the right direction, thanks. Link to comment Share on other sites More sharing options...
-ctn- Posted March 1, 2016 Share Posted March 1, 2016 As far as I know, there is no up-to-date example library. You can glean some information from outdated scripts, but the real meat and potatoes comes from the kOS documentation github. It has everything you need, just remember that coding is a specific and fussy business. Most of my time when writing a script is spent on that documentation site and testing. Link to comment Share on other sites More sharing options...
maculator Posted March 2, 2016 Share Posted March 2, 2016 Thats what I was afraid I would hear. Learning things is so much easier when you can play arround with a working version of a thing close to that one you want to do. Link to comment Share on other sites More sharing options...
-ctn- Posted March 2, 2016 Share Posted March 2, 2016 Yes, I agree. But sometimes figuring it all out on your own is rewarding too! Link to comment Share on other sites More sharing options...
Delta_8930 Posted March 2, 2016 Share Posted March 2, 2016 3 hours ago, Kartoffelkuchen said: I've now highly improved my code, and it is really much better: Can your script target certain vessels (such as the LZ1 and the drone barge) as well? Link to comment Share on other sites More sharing options...
Dr_Goddard Posted March 2, 2016 Share Posted March 2, 2016 2 hours ago, maculator said: I have one last question: Is there some sort of up to date libary of scripts? There are a couple of really great resources linked right from the manual: http://ksp-kos.github.io/KOS_DOC/tutorials/quickstart.html and in the user manual index there is the community library which has a lot of the more complex routines. Each section of the manual has solid examples, like the PID section etc. Have a look through it, you will be surprised at the amount of cut-and-paste solutions you can find to help you get familiar. And the developers are regularly checking in on the forum to answer any questions and help you develop your code. Just ask! PGodd Link to comment Share on other sites More sharing options...
erendrake Posted March 2, 2016 Author Share Posted March 2, 2016 (edited) New Release Github : Download Spacedock : Download BREAKING CHANGES As usual, you must recompile any KSM files when using the new version. Vecdraw :SCALE no longer applied to :START. Only applied to :VEC. Varying power consumption might make it so if you have high IPU settings some designs might run out of power when they didn't before. (in most cases it should draw less power for most people). !!!! Default extension of ".ks" is no longer applied to all new filenames created. But it still will be looked for when reading existing files if you leave the extension off !!!! FileInfo information now moved to Volume (http://ksp-kos.github.io/KOS_DOC/structures/volumes_and_files/volume.html). VOLUME:FILES was returning a LIST(), now it returns a LEXICON who's keys are the filename. String sort-order comparisons with "<" and ">" operators were implemented wrongly and just compared lengths. Now they do a character-by-character comparison (case-insensitively). On the off chance that anyone was actually trying to use the previous weird length-comparison behavior, that would break. NEW FEATURES Art asset rework. The meshes and textures of the kOS CPU parts have recieved an update, and a new KAL9000 high-end computer part was included. Varying power consumption. Units of electric charge used now varies depending on CPU speed and how much the CPU is being actually used. If your IPU setting is low, or if your program isn't doing very much and is just stuck on a wait statement, it won't use as much power. (http://ksp-kos.github.io/KOS_DOC/general/cpu_hardware#electricdrain) Ability to read and write whole files at a time as one big string. (http://ksp-kos.github.io/KOS_DOC/structures/volumes_and_files/volumefile.html) User Functions can now be referred to with function pointers, or "delegates". (http://ksp-kos.github.io/KOS_DOC/language/delegates.html) Automatic serialization system to save/load some kinds of data values to JSON-format files (http://ksp-kos.github.io/KOS_DOC/commands/files.html#writejson-object-filename) User Programs and Functions now allow trailing optional parameters with defaulted values. (http://ksp-kos.github.io/KOS_DOC/language/user_functions.html#optional-parameters-parameter-defaults). There are now some suffixes that work on all value types, even primitive scalars. To accomplish this, a new "encapsulation" system has wrapped all kOS structures and primitive types inside a generic base type. (http://ksp-kos.github.io/KOS_DOC/structures/reflection.html) ENGINE type now supports multi-mode cases and has its gimbal accessible through :GIMBAL suffix (http://ksp-kos.github.io/KOS_DOC/structures/vessels/engine.html) Added GIMBAL:LIMIT suffix. (http://ksp-kos.github.io/KOS_DOC/structures/vessels/gimbal.html) Better support for DMagic's Orbital Science mod (http://ksp-kos.github.io/KOS_DOC/addons/OrbitalScience.html) Char() and Unchar() functions for translating unicode numbers to characters and visa versa (http://ksp-kos.github.io/KOS_DOC/math/basic.html#function:CHAR) New Range type for iterating over hardcoded lists (http://ksp-kos.github.io/KOS_DOC/structures/collections/range.html). Ability to iterate over the characters in a string using a FOR loop, as if the string was a LIST() of chars. New higher level cpu part. (#1380) HASTARGET and HASNODE functions (http://ksp-kos.github.io/KOS_DOC/bindings.html?highlight=hastarget) :JOIN suffix for LIST to make a string of the elements (http://ksp-kos.github.io/KOS_DOC/structures/collections/list.html#method:LIST:JOIN) KUNIVERSE now lets you read hours per day setting (http://ksp-kos.github.io/KOS_DOC/structures/misc/kuniverse.html#attribute:KUNIVERSE:HOURSPERDAY) The reserved word ARCHIVE is now a first-class citizen with proper binding, so you can do SET FOO TO ARCHIVE and it will work like you'd expect. New Lexicon creation syntax to make a Lexicon and populate it all in one statement. (http://ksp-kos.github.io/KOS_DOC/structures/collections/lexicon.html?highlight=lexicon#constructing-a-lexicon) BUG FIXES Numerous additional checks to prevent control of other vessels the kOS CPU isn't attached to. The error beep and keyboard click sounds now obey game's UI volume settings. (#1287) Fixed two bugs with obtaining waypoints by name. (#1313) (#1319) Removed unnecessary rounding of THRUSTLIMIT to nearest 0.5%, now it can be more precise. (#1329) Removed the ability to activate both modes on multi-mode engine simultaneously. LIST ENGINES now lists all engines and displays part names instead of module names. (https://github.com/KSP-KOS/issues/1251) Fixed bug that caused hitting ESC to crash the telnet server. (#1328) Some exceptions didn't cause beep, now they all do. (#1317) Vecdraw :SCALE no longer applied to :START. Only applied to :VEC. (#1200) Fixed bug that made up-arrow work incorrectly when the cursor is at the bottom of the terminal window. (#1289) A multitude of small documentation fixes (#1341) Fixed a bug when performing an undock (#1321) IR:AVAILABLE was reporting incorrectly () Boot files now wait until the ship is fully unpacked and ready (#1280) The Vessel :HASBODY (aliases :HASOBT and :HASORBIT) suffix was in the documentation, but had been lost in a refactor last year. It is put back now. String sort-order comparisons with "<" and ">" operators were implemented wrongly and just compared lengths. Now they do a character-by-character comparison (case-insensitively) Small documentation edits and clarifications all over the place. KNOWN issues Using lock variables in compiled scripts with a duplicate identifier (like "throttle") throws an error (#1347 and #1253). Occasionally staging with a probe core or root part in the ejected stage will break cooked steering (#1492). The limitations of RemoteTech integration can be bypassed by storing a volume in a variable before the ship looses a connection to the KSC (#1464). CONTRIBUTORS THIS RELEASE (These are generated from records on Github of anyone who's Pull Requests are part of this release.) (Names are simply listed here alphabetically, not by code contribution size. Anyone who even had so much as one line of change is mentioned.) Stephan Andreev (ZiwKerman) https://github.com/ZiwKerman Bert Cotton (BertCotton) https://github.com/BertCotton Kevin Gisi (gisikw) https://github.com/gisikw Peter Goddard (pgodd) https://github.com/pgodd Steven Mading (Dunbaratu) https://github.com/Dunbaratu Eric A. Meyer (meyerweb) https://github.com/meyerweb Tomek Piotrowski (tomekpiotrowski) https://github.com/tomekpiotrowski Brad White (hvacengi) https://github.com/hvacengi Chris Woerz (erendrake) https://github.com/erendrake (repository owner) (name not public in github profile) (alchemist_ch) https://github.com/AlchemistCH (name not public in github profile) (tdw89) https://github.com/TDW89 Edited March 2, 2016 by erendrake Link to comment Share on other sites More sharing options...
Riderfighter Posted March 2, 2016 Share Posted March 2, 2016 (edited) @erendrake Oh lol I had just downloaded the one before this update around 2 minutes before this got updated. Anyways thank you for updating this mod it really is awesome! Just wondering is it possible to define our own commands? I am just wondering this because I would love to make a command that finds Delta V and stuff via referencing a script and executing it like a command. Edited March 2, 2016 by Riderfighter Link to comment Share on other sites More sharing options...
Riderfighter Posted March 2, 2016 Share Posted March 2, 2016 (edited) Also quick question is there a way to see how much power you have and switch off power consuming parts and then extend solars when at a certain amount? (Via scripts of course if it wasn't clear) Edited March 2, 2016 by Riderfighter Link to comment Share on other sites More sharing options...
Dr_Goddard Posted March 2, 2016 Share Posted March 2, 2016 6 hours ago, Riderfighter said: Just wondering is it possible to define our own commands? Yes absolutely! You can create a user function function function_name {parameter parameter_if_desired code} call it anywhere in the program : function_name(optional parameters) kOS manual function page: http://ksp-kos.github.io/KOS_DOC/language/user_functions.html?highlight=function#declare-function Since last night there is also delegates: Link to comment Share on other sites More sharing options...
Kartoffelkuchen Posted March 2, 2016 Share Posted March 2, 2016 12 hours ago, Delta_8930 said: Can your script target certain vessels (such as the LZ1 and the drone barge) as well? Not yet. I'll try to implement that though, but that's where it gets really complex I think. Link to comment Share on other sites More sharing options...
Dr_Goddard Posted March 2, 2016 Share Posted March 2, 2016 7 hours ago, Riderfighter said: Also quick question is there a way to see how much power you have and switch off power consuming parts and then extend solars when at a certain amount? (Via scripts of course if it wasn't clear) You can obtain the aggregate charge for your ship this way: print ship:electriccharge.So to activate the panels before you run out of power: when ship:electriccharge < x then panels on. Link to comment Share on other sites More sharing options...
Riderfighter Posted March 2, 2016 Share Posted March 2, 2016 @Dr_Goddard Sweet thanks so much for clearing those things up I'm going to make my first program today Link to comment Share on other sites More sharing options...
Riderfighter Posted March 2, 2016 Share Posted March 2, 2016 So I was making my script open solars when at a certain level of power but I wanted to know if there is a way to detect if light is facing your way. Link to comment Share on other sites More sharing options...
Recommended Posts