Jump to content

ElWanderer

Members
  • Posts

    397
  • Joined

  • Last visited

Posts posted by ElWanderer

  1. 2 minutes ago, FumbeiNumbie said:

    Hi!

    I have encountered a problem with wheelsteering. My rovers go crazy no matter what I lock on.

    See the gif under the spoiler.

      Reveal hidden contents

    video-to-gif output image

    Also I noticed that geoposition returns slightly different values. I never noticed it before.

    Have anyone stumbled across something similar?

    I'm using KSP 1.3 and installed this mod from CKAN.

    Judging from the navball, your control point is facing directly upwards (as opposed to forwards, in-line with the wheels). Have you taken that into account when steering? If not, try putting a probe core or docking port on the front and set it as the "control from here" point (kOS can access that, if you want to do it in a script, but worth doing manually to see if it fixes the issue first).

  2. 15 hours ago, GoodHunter14 said:

    Is there a thread/post about kOS challenges?

    EDIT: Never mind I just realised the forum has a special directory for Challenges.

    If you do start one for kOS in the Challenges sub-forum, it might be an idea to let people know here and on the kOS Reddit. Most players looking at the Challenges won't be using kOS.

    Separately, I did wonder how easy the current "official" KSP challenge of flying through a Mun arch would be to automate with kOS. The official challenge is stock-only, mind, but most people's attempts are very hit and miss as a result. If only I had some spare time!

  3. 11 minutes ago, GoodHunter14 said:

    Can anyone tell me why those if conditions don't work? It straight up jumps to z=10 for some reason.  

      Reveal hidden contents

    CLEARSCREEN.
    SET KWRCS TO SHIP:PARTSTAGGED("RCSFuel")[0].
    SET KWRCSEngine TO SHIP:PARTSTAGGED("RCSEngine")[0].
    SET SRBs TO SHIP:PARTSTAGGED("SRB"). //the rcs engine and fuel are in the second stage. Make sure you have enought deltaV in the second stage to reach orbit
    SET cooldowntime to 0.
    //and make sure the engine in the second stage fires before you reach 100km Apoapsis
    SET VESSEL TO SHIP.
    //Next, we'll lock our throttle to 100%.
    LOCK THROTTLE TO 1.0.   // 1.0 is the max, 0.0 is idle.

    //This is our countdown loop, which cycles from 10 to 0
    PRINT "Counting down:".
    FROM {local countdown is 10.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO {
        PRINT "..." + countdown.
        WAIT 1. // pauses the script here for 1 second.
    }


    //This is a trigger that constantly checks to see if our thrust is zero.
    //If it is, it will attempt to stage and then return to where the script
    //left off. The PRESERVE keyword keeps the trigger active even after it
    //has been triggered.
    WHEN MAXTHRUST = 0 THEN {
        STAGE.
        PRESERVE.
    }.
    FOR SRB in SRBs {
      WHEN SRB:MAXTHRUST = 0 THEN
      {
        STAGE.
        if cooldowntime = 0
        {
        PRESERVE.
          if SRB:MAXTHRUST = 0
          {
            set cooldowntime to 1.
          }.
        }.
        
      }.
    }.


    //This will be our main control loop for the ascent. It will
    //cycle through continuously until our apoapsis is greater
    //than 100km. Each cycle, it will check each of the IF
    //statements inside and perform them if their conditions
    //are met
    SET MYSTEER TO HEADING(90,90).
    SET x TO 100000. //your desired altitude at which you want to orbit
    SET u TO 3.5316*10^12.
    SET r TO 600000 + x.
    SET a TO 600000 + x.
    SET Vel TO SQRT(u*((2/r) - (1/a))).

    LOCK STEERING TO MYSTEER. // from now on we'll be able to change steering by just assigning a new value to MYSTEER
    SET SPEED TO 200.
    SET z TO 90.
    UNTIL SHIP:APOAPSIS > x { //Remember, all altitudes will be in meters, not kilometers
      SET MYSTEER TO HEADING(90,z).
        //For the initial ascent, we want our steering to be straight
        //up and rolled due east
        IF SHIP:VELOCITY:SURFACE:MAG > 200 AND z>10 {
            IF SPEED+19 < SHIP:VELOCITY:SURFACE:MAG AND SHIP:VELOCITY:SURFACE:MAG < SPEED+21.
            {
              SET z TO z-1.
              SET SPEED TO SPEED+20.
            }.
        }.
        IF KWRCSEngine:THRUST > 0
        {
        SET EBTS TO ((VESSEL:MASS*9.80665*KWRCSEngine:ISP)/KWRCSEngine:AVAILABLETHRUSTAT(SHIP:Q))*(1-constant:e^(-LN(VESSEL:MASS / (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS)))). //Estimated burn time of stage
        PRINT "Estimated Burn Time of stage (s):" + ROUND(EBTS,2) AT(0,21).
        }.

    }.
    PRINT "Velocity necessary to stay in orbit at 100km is:" + ROUND(Vel,2).
    SET EBTS TO ((VESSEL:MASS*9.80665*KWRCSEngine:ISP)/KWRCSEngine:AVAILABLETHRUSTAT(SHIP:Q))*(1-constant:e^(-LN(VESSEL:MASS / (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS)))). //Estimated burn time of stage
    PRINT "Estimated Burn Time of stage (s):" + ROUND(EBTS,2) AT(0,21).
    SET SVel TO SQRT(u * ((2/(SHIP:APOAPSIS+600000)) - (1/(600000+((SHIP:PERIAPSIS+SHIP:APOAPSIS)/2))))).
    SET dV TO Vel - Svel. // estimated delta V to complete orbit
    PRINT "DeltaV: " + dV.
    SET R TO KWRCS:WETMASS/KWRCS:DRYMASS.
    SET y TO (constant:e^(dV/(KWRCSEngine:VISP*9.80665))*(VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS) - (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS))/(R-constant:e^(dV/(KWRCSEngine:VISP*9.80665))).
    SET FM TO y*R. //this is the estimated fuel mass needed to complete the manuever
    SET eM TO VESSEL:MASS - FM. // this is the mass after the manuever has completed but I'm using it in the same formula as in EBT for a better burn time estimation
    SET EBT TO ((VESSEL:MASS*9.80665*KWRCSEngine:VISP)/KWRCSEngine:AVAILABLETHRUST)*(1-constant:e^(-dV/(9.80665*KWRCSEngine:VISP))).
    PRINT "EBT: " + EBT.
    SET EBTeM TO ((eM*9.80665*KWRCSEngine:VISP)/KWRCSEngine:AVAILABLETHRUST)*(1-constant:e^(-dV/(9.80665*KWRCSEngine:VISP))).
    PRINT "EBTem: " + EBTeM.
    SET EMBT TO (EBT + EBTeM)/2. //Estimated burn time to complete DeltaV Manuever
    SET APO TO EMBT/2.
    PRINT "APO: " + APO.

    PRINT "100km apoapsis reached, cutting throttle".
    LOCK THROTTLE TO 0.
    SET MYSTEER TO HEADING(90,5).
    //SET EBTS TO ((VESSEL:MASS*9.80665*KWRCSEngine:ISP)*KWRCSEngine:THRUST)*(1-constant:e^(-LN(VESSEL:MASS / (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS)))).


    //At this point, our apoapsis is above 100km and our main loop has ended.
    //time to reach orbit
    IF (APO - 0.1) < ETA:APOAPSIS AND ETA:APOAPSIS < (APO + 0.1). //if the ETA until apoapsis is half of the estimated burn time
    {
      PRINT "Burning sequence to circularize orbit engaged".
      UNTIL SHIP:PERIAPSIS > x
      {
        SET MYSTEER TO HEADING(90,0).
        LOCK THROTTLE TO 1.
        IF KWRCSEngine:THRUST > 0
        {
        SET EBTS TO ((VESSEL:MASS*9.80665*KWRCSEngine:ISP)/KWRCSEngine:AVAILABLETHRUSTAT(SHIP:Q))*(1-constant:e^(-LN(VESSEL:MASS / (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS)))). //Estimated burn time of stage
        PRINT "Estimated Burn Time of stage (s):" + ROUND(EBTS,2) AT(0,21).
        }.
        SET SVel TO SQRT(u * ((2/(SHIP:APOAPSIS+600000)) - (1/(600000+((SHIP:PERIAPSIS+SHIP:APOAPSIS)/2))))).
        SET dV TO Vel - Svel.
        PRINT "DeltaV remaining to complete burn (m/s):" + ROUND(dV,2) AT(0,22).
      }.
    }.

    //This sets the user's throttle setting to zero to prevent the throttle
    //from returning to the position it was at before the script was run.
    PRINT "100km periapsis reached, cutting throttle".
    LOCK THROTTLE TO 0.
    SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
     

     

    I can't see anything obvious, though there are a couple of things to say that I can see:

    1. you could do with a "WAIT 0." inside that UNTIL loop, so that it doesn't go through the contents more than once per tick.

    2. You're giving your velocity magnitude a 2m/s window to hit each time. That would probably work, but towards the end of a stage you might have such high TWR (>5) that it could skip right past it (i.e. go from speed plus 18.9 to speed plus 21.1 in one tick)

    Those two points wouldn't explain why your rocket is immediately trying to pivot over to 10 degrees pitch angle. Can you add a bunch of display lines to print out the values for surface velocity magnitude, "speed" and z, and to indicate whether it's going inside the IF blocks or not? That might help track down what's going on.

  4. 37 minutes ago, GoodHunter14 said:

    IF (APO - 0.1) < ETA:APOAPSIS < (APO + 0.1).

    "Tries to compile" ...

    "Error: Cannot ordinate BooleanValue < ScalarDoubleValue"

    I give up. This language right now, i cant even... I don't know how to fix this. Please give me a solution.

    This behaviour is true of almost all languages. You can't test for X < Y < Z, you have to test for (X < Y) AND (Y < Z).

  5. 6 minutes ago, GoodHunter14 said:

    I'm throwing my keyboard out the window. WHY DOESN'T THE IF STATEMENT WORK WHYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY. WHY DOES IT IGNORE THE GOD DAMN STATEMENT (condition*) AND JUMPS TO UNTIL LOOP WHY???? TELL ME WHY??!?!?!?!?!

      Reveal hidden contents

    CLEARSCREEN.
    SET KWRCS TO SHIP:PARTSTAGGED("RCSFuel")[0].
    SET KWRCSEngine TO SHIP:PARTSTAGGED("RCSEngine")[0]. //the rcs engine and fuel are in the second stage. Make sure you have enought deltaV in the second stage to reach orbit
    //and make sure the engine in the second stage fires before you reach 100km Apoapsis
    SET VESSEL TO SHIP.
    //Next, we'll lock our throttle to 100%.
    LOCK THROTTLE TO 1.0.   // 1.0 is the max, 0.0 is idle.

    //This is our countdown loop, which cycles from 10 to 0
    PRINT "Counting down:".
    FROM {local countdown is 10.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO {
        PRINT "..." + countdown.
        WAIT 1. // pauses the script here for 1 second.
    }


    //This is a trigger that constantly checks to see if our thrust is zero.
    //If it is, it will attempt to stage and then return to where the script
    //left off. The PRESERVE keyword keeps the trigger active even after it
    //has been triggered.
    WHEN MAXTHRUST = 0 THEN {
        STAGE.
        PRESERVE.
    }.


    //This will be our main control loop for the ascent. It will
    //cycle through continuously until our apoapsis is greater
    //than 100km. Each cycle, it will check each of the IF
    //statements inside and perform them if their conditions
    //are met
    SET MYSTEER TO HEADING(90,90).
    SET x TO 100000. //your desired altitude at which you want to orbit
    SET u TO 3.5316*10^12.
    SET r TO 600000 + x.
    SET a TO 600000 + x.
    SET Vel TO SQRT(u*((2/r) - (1/a))).

    LOCK STEERING TO MYSTEER. // from now on we'll be able to change steering by just assigning a new value to MYSTEER
    SET SPEED TO 200.
    SET z TO 90.
    UNTIL SHIP:APOAPSIS > x { //Remember, all altitudes will be in meters, not kilometers
      IF SHIP:VELOCITY:SURFACE:MAG < 100 {
      //This sets our steering 90 degrees up and yawed to the compass
      //heading of 90 degrees (east)
      SET MYSTEER TO HEADING(90,90).

    //Once we pass 100m/s, we want to pitch down ten degrees
    } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 100 AND SHIP:VELOCITY:SURFACE:MAG < 200 {
      SET MYSTEER TO HEADING(90,80).
      PRINT "Pitching to 80 degrees" AT(0,15).
      PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).

    //Each successive IF statement checks to see if our velocity
    //is within a 100m/s block and adjusts our heading down another
    //ten degrees if so
    } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 200 AND SHIP:VELOCITY:SURFACE:MAG < 300 {
      SET MYSTEER TO HEADING(90,70).
      PRINT "Pitching to 70 degrees" AT(0,15).
      PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).

    } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 300 AND SHIP:VELOCITY:SURFACE:MAG < 400 {
      SET MYSTEER TO HEADING(90,60).
      PRINT "Pitching to 60 degrees" AT(0,15).
      PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).

    } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 400 AND SHIP:VELOCITY:SURFACE:MAG < 700 {
      SET MYSTEER TO HEADING(90,50).
      PRINT "Pitching to 50 degrees" AT(0,15).
      PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).

    } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 700 AND SHIP:VELOCITY:SURFACE:MAG < 800 {
      SET MYSTEER TO HEADING(90,40).
      PRINT "Pitching to 40 degrees" AT(0,15).
      PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).

    } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 800 AND SHIP:VELOCITY:SURFACE:MAG < 900 {
      SET MYSTEER TO HEADING(90,30).
      PRINT "Pitching to 30 degrees" AT(0,15).
      PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).

    } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 900 AND SHIP:VELOCITY:SURFACE:MAG < 1300 {
      SET MYSTEER TO HEADING(90,11).
      PRINT "Pitching to 20 degrees" AT(0,15).
      PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).

    //Beyond 800m/s, we can keep facing towards 10 degrees above the horizon and wait
    //for the main loop to recognize that our apoapsis is above 100km
    } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 1300 {
      SET MYSTEER TO HEADING(90,10).
      PRINT "Pitching to 10 degrees" AT(0,15).
      PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).

    }.
        IF KWRCSEngine:THRUST > 0
        {
        SET EBTS TO ((VESSEL:MASS*9.80665*KWRCSEngine:ISP)/KWRCSEngine:AVAILABLETHRUSTAT(SHIP:Q))*(1-constant:e^(-LN(VESSEL:MASS / (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS)))). //Estimated burn time of stage
        PRINT "Estimated Burn Time of stage (s):" + ROUND(EBTS,2) AT(0,21).
        }.

    }.
    PRINT "Velocity necessary to stay in orbit at 100km is:" + ROUND(Vel,2).
    SET EBTS TO ((VESSEL:MASS*9.80665*KWRCSEngine:ISP)/KWRCSEngine:AVAILABLETHRUSTAT(SHIP:Q))*(1-constant:e^(-LN(VESSEL:MASS / (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS)))). //Estimated burn time of stage
    PRINT "Estimated Burn Time of stage (s):" + ROUND(EBTS,2) AT(0,21).
    SET SVel TO SQRT(u * ((2/(SHIP:APOAPSIS+600000)) - (1/(600000+((SHIP:PERIAPSIS+SHIP:APOAPSIS)/2))))).
    SET dV TO Vel - Svel. // estimated delta V to complete orbit
    PRINT "DeltaV: " + dV.
    SET R TO KWRCS:WETMASS/KWRCS:DRYMASS.
    SET y TO (constant:e^(dV/(KWRCSEngine:VISP*9.80665))*(VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS) - (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS))/(R-constant:e^(dV/(KWRCSEngine:VISP*9.80665))).
    SET FM TO y*R. //this is the estimated fuel mass needed to complete the manuever
    SET eM TO VESSEL:MASS - FM. // this is the mass after the manuever has completed but I'm using it in the same formula as in EBT for a better burn time estimation
    SET EBT TO ((VESSEL:MASS*9.80665*KWRCSEngine:VISP)/KWRCSEngine:AVAILABLETHRUST)*(1-constant:e^(-dV/(9.80665*KWRCSEngine:VISP))).
    PRINT "EBT: " + EBT.
    SET EBTeM TO ((eM*9.80665*KWRCSEngine:VISP)/KWRCSEngine:AVAILABLETHRUST)*(1-constant:e^(-dV/(9.80665*KWRCSEngine:VISP))).
    PRINT "EBTem: " + EBTeM.
    SET EMBT TO (EBT + EBTeM)/2. //Estimated burn time to complete DeltaV Manuever
    SET APO TO EMBT/2.
    PRINT "APO: " + APO.
    PRINT "100km apoapsis reached, cutting throttle".
    LOCK THROTTLE TO 0.
    SET MYSTEER TO HEADING(90,5).
    //SET EBTS TO ((VESSEL:MASS*9.80665*KWRCSEngine:ISP)*KWRCSEngine:THRUST)*(1-constant:e^(-LN(VESSEL:MASS / (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS)))).


    //At this point, our apoapsis is above 100km and our main loop has ended.
    //time to reach orbit
    IF ETA:APOAPSIS = APO. //if the ETA until apoapsis is half of the estimated burn time
    {
      PRINT "Burning sequence to circularize orbit engaged".
      UNTIL SHIP:PERIAPSIS > x
      {
        SET MYSTEER TO HEADING(90,0).
        LOCK THROTTLE TO 1.
        IF KWRCSEngine:THRUST > 0
        {
        SET EBTS TO ((VESSEL:MASS*9.80665*KWRCSEngine:ISP)/KWRCSEngine:AVAILABLETHRUSTAT(SHIP:Q))*(1-constant:e^(-LN(VESSEL:MASS / (VESSEL:MASS - KWRCS:MASS + KWRCS:DRYMASS)))). //Estimated burn time of stage
        PRINT "Estimated Burn Time of stage (s):" + ROUND(EBTS,2) AT(0,21).
        }.
        SET SVel TO SQRT(u * ((2/(SHIP:APOAPSIS+600000)) - (1/(600000+((SHIP:PERIAPSIS+SHIP:APOAPSIS)/2))))).
        SET dV TO Vel - Svel.
        PRINT "DeltaV remaining to complete burn (m/s):" + ROUND(dV,2) AT(0,22).
      }.
    }.

    //This sets the user's throttle setting to zero to prevent the throttle
    //from returning to the position it was at before the script was run.
    PRINT "100km periapsis reached, cutting throttle".
    LOCK THROTTLE TO 0.
    SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
     

     

    You appear to be checking for the equality of a floating point number (ETA:APOAPSIS) with either another float (or an integer, it doesn't really matter). This will almost never work. Instead, you need to check to see if the floating point value falls within a range.

    Note: if an IF check doesn't seem to be working, it can help to debug it by printing out the values being compared.

  6. 9 minutes ago, GoodHunter14 said:

    I have an issue regarding the engine:ISP structure. It won't show the ISP of the engine I'm using (it gives an error) (i have it nametag:ISP). I need this code to work (tho I do recognize I barrely read about the syntax of the language, please help, I'm to lazy to read all that.)


     

    Where you have PARTSTAGGED() the return is not a single part, but a LIST of parts, even if there is only one part in the list.

    If you will only ever give one part that particular tag, you can stick [0] on the end to get the first object from the list. e.g. SET mypart TO SHIP:PARTSTAGGED("mytag")[0].

    Edit: if you have multiple parts sharing a tag, you would need to loop through them (e.g. if you wanted to total their mass).

  7. 2 hours ago, Blaarkies said:

    No, that is not true.

    In stock vanilla KSP, a "Relay" dish can:
    - Communicate directly to KSC
    - Communicate indirectly through another relay to KSC
    - Be a relay for other crafts(dish or antennae) trying to communicate

    Simply put, a Relay dish is everything that a direct antennae is, plus it also has the connection relaying / bouncing ability. If a direct antennae can do something, then a dish of the same strength can do the same thing and more. For comms, there is no "blocked because dish is in use" effect...a single dish can handle a thousand craft.
     

    Ah, okay. I could've sworn it worked like that (and this had caused a bunch of Question threads), but I'm happy to be wrong!

  8. How many antennae do you have on the mothership? As I understand it (incorrectly, it seems. Ignore what follows): To act as a relay, the mothership needs two antennae: any antenna (or antennae) that can connect back to Kerbin, and a specifically-described-as-a-relay antenna (or antennae) that can connect to your probe. It sounds like the mothership is using (both?) the "relay" antennae to talk to Kerbin, so it's unable to relay anything from the probe.

  9. I'll second the reference to OhioBob's page. 

    I wrote up my solution to launching into an inclined plane here (specifically the etaToOrbitPlane function):

    https://github.com/ElWanderer/kOS_scripts/blob/master/documentation/lib_launch_geo_readme.md

    The hard part was finding out where the orbit plane would be, as opposed to the ground track of whatever's in the orbit plane. The latter seems a lot more common in the results of Google searches. The kOS code I've written and am still writing is available if you want to go exploring from that link.

    My rendezvous code isn't too bad, though it's not very realistic. The approach I take is to make sure the orbits intersect then set-up a phasing orbit of the right period so that the two craft meet at the intersection some number of orbits later. The maths of that was a headache to figure out, particularly trying to account for all the combinations of being ahead of/behind the target and in a shorter/longer orbit.

    In real life, I'm pretty sure they go through a series of phasing orbits that are entirely below the altitude of the station so that in the event of loss of control, there is no collision risk. Effectively, intersection occurs very late on in the process.

  10. 1 hour ago, kerboman25 said:

    hello fellow kerbonauts

    i'm having a bit of a strugle with a program that stabilises my dragon 2 derivate when landing (by using thrustlimiting). I cannot properly subtract the difference of the UP direction to the direction that im going in. i tried to do this by doing UP-FACING but that didn't work out well. Can you guys tell me the best way to keep the craft facing perfectly up (or retrograde for when i'm burning at higher altitude) by using differential throttling?

     

    thanks in advance :)

    UP and FACING are directions, the addition and subtraction of which is a bit of a mystery to me. It might work better if you take their vectors e.g. LOCK diff_vector TO UP:VECTOR - FACING:VECTOR.

    Edit: but this doesn't answer your question about differential throttling, sorry.

  11. 18 minutes ago, maculator said:

    Does anybody know how to make this work?:

      Reveal hidden contents
    
    
    function printhud {
    	parameter message.
    	
    	hudtext(message, 5, 2, 20, green, false).
    }
    
    function hasfile {
    	parameter name.
    	parameter volume.
    	
    	switch to volume. list files in filecheck.
    	for file in filecheck {
    		if file:name = name {
    			switch to 1.
    			return true.
    		} else {
    		switch to 1.
    		return false.
    		}
    	}
    }
    if hasfile("test.ks", 0) { printhud("test.ks exists on 0:/"). wait 5.} //doesn't print anything :/
    
    printhud("we made it to the end of test.ks!").

     

    The 2 functions seem to work, the programm runs until the end and confirms it's done. But I cant get it to tell me wether hasfile() is true or false :/

    You're only comparing the desired filename to the first file in the list, then immediately returning true or false depending on whether that file is the one you were after or not (so it's probably always returning false). 

    Move the bit that sets the volume to 1 and returns false outside of the for loop, so it is only executed if you've looped through every file and didn't find what you want.

    Alternatively, the EXISTS(file_path) function exists so that you don't have to loop through the files yourself.

  12. 1 hour ago, maculator said:


    Will it check both parameters if they're seperated with an "and" or is it better to put in a second "if" for the second parameter"?

    I'm curious about some knowledge about KOS.

    The concept of not checking further parts of an expression once we definitely know the overall result is called short-circuiting. kOS does this:

    http://ksp-kos.github.io/KOS_DOC/language/features.html#short-circuiting-booleans

    This means it is useful to order checks within expressions, so that simple checks are done first that can prevent something complicated being checked unnecessarily. It can also be used as a safety measure, to avoid doing something potentially crashy (though this is less obvious to someone reading the code, so it's not necessarily best practice). The two comparisons in your example are both on the simple end. I'd just go for whatever seems more readable to being with, though I'd later viciously reduce it in size to the minimum possible as I am always running out of hard disk space until the KAL-9000 is available.

  13. 18 minutes ago, maculator said:

    Okay I feel really stupid because I dont get the following:

    Works so far:

      Hide contents
    
    
    //start v9.9.9
    //name: 	ttko.ks
    //location: Kerbal Space Program/Ships/Script/ttko.ks
    //by maculator
    
    //preparations:
    clearscreen.
    set kuniverse:timewarp:mode to "PHYSICS".
    set TARGETAPOAPSIS to 75000.
    set TARGETPERIAPSIS to 75000.
    set PTAPOAPSIS to 60000.
    set TALTITUDE to 500.
    list ENGINES in ELIST.
    set STEP to 1.
    print "set STEP to 1.".
    
    //actuall program in until loop:
    until STEP = 12 {
    
    	//launch
    	if STEP = 1 {
    		lock THROTTLE to 1.
    		lock STEERING to UP + R(0,0,180).
    		stage.
    		print "set STEP to 2.".
    		set STEP to 2.
    	}
    
    	//initial angeling
    	else if STEP = 2 {
    		print TALTITUDE at (10,10).
    		print ALT:RADAR at (10,11).
    		if ALT:RADAR > TALTITUDE {
    			lock STEERING to UP + R(0,-5,180).
    			print "set STEP to 3.".
    			set STEP to 3.
    		}
    	}
    
    	//getting to 10km altitude
    	else if STEP = 3 {
    		set TALTITUDE to 10000.
    		if ALT:RADAR >= TALTITUDE {
    			print "set STEP to 4.".
    			set STEP to 4.
    		}
    	}
    
    }

     

    And until I put my staging sequence in, it stops working. It prints "set STEP to 2." but wont trigger step 2.

      Hide contents
    
    
    //start v9.9.9
    //name: 	ttko.ks
    //location: Kerbal Space Program/Ships/Script/ttko.ks
    //by maculator
    
    //preparations:
    clearscreen.
    set kuniverse:timewarp:mode to "PHYSICS".
    set TARGETAPOAPSIS to 75000.
    set TARGETPERIAPSIS to 75000.
    set PTAPOAPSIS to 60000.
    set TALTITUDE to 500.
    list ENGINES in ELIST.
    set STEP to 1.
    print "set STEP to 1.".
    
    //actuall program in until loop:
    until STEP = 12 {
    
    	//launch
    	if STEP = 1 {
    		lock THROTTLE to 1.
    		lock STEERING to UP + R(0,0,180).
    		stage.
    		print "set STEP to 2.".
    		set STEP to 2.
    	}
    
    	//initial angeling
    	else if STEP = 2 {
    		print TALTITUDE at (10,10).
    		print ALT:RADAR at (10,11).
    		if ALT:RADAR > TALTITUDE {
    			lock STEERING to UP + R(0,-5,180).
    			print "set STEP to 3.".
    			set STEP to 3.
    		}
    	}
    
    	//getting to 10km altitude
    	else if STEP = 3 {
    		set TALTITUDE to 10000.
    		if ALT:RADAR >= TALTITUDE {
    			print "set STEP to 4.".
    			set STEP to 4.
    		}
    	}
    	//staging:
    	until ELIST:LENGTH = 1 {
    		list ENGINES in ELIST.
    		if STAGE:LIQUIDFUEL < 1 and STAGE:SOLIDFUEL < 1 {
    			stage.
    		}		
    	}
    }

     

    I guess I'm just missing the obvious, but for me the second one should work I just don't get why it doesn't.

    Apologies for quoting the whole thing, but on a mobile device, it's hard to edit properly.

    I'm guessing you have more than one engine, in which case the until loop you've added will... loop, repeatedly. LIST ENGINES IN xxx will list *every* engine on the vessel, active and inactive. It should still stage when the stage empties, but it can't do anything else until there is only one engine left.

  14. 5 hours ago, Not Sure said:

    I have the issue that the lock command doesn't work, i have taken the code from the simple autolaunch and even that does not work on the lock command, everything else does. here is the code 

    
    // landing #1
    print "this is a test".
    lock throttle to 1.
    lock steering to up + R(0,0,180).
    stage.
    print "Launch!".

    it prints the text and stages but does not do anything else. I only started this a day ago and this is very disencouraging.

    edit: I can lock throttle and steering by manually typing it into the terminal, and I have also uninstalled all other mods, but it will not read the code, it also does not show error messages. 

    If you lock the throttle or steering within a script, those will only last as long as the script is running. They'll unlock once your script ends, which is happening immediately in your case.

    If you put something like WAIT UNTIL FALSE. at the end of your script, it'll keep running until manually cancelled (Ctrl-C, typically).

  15. 53 minutes ago, danielboro said:
    
       FOR M IN SciP {print m:part:name+" : "+m:inoperable+"                     " at (0,26).
        if (not m:inoperable)and  ( not onlyrerunnable or (onlyrerunnable and m:rerunnable)) 
             {
                 if not M:HASDATA {M:DEPLOY.}
                   else if M:Data[0]:TRANSMITVALUE=0 {M:DUMP(). M:RESET().  wait 5. M:DEPLOY.
             } 

    i have this for to run all sciance parts in the ship
    but evry 2ed time it gets to GOO it fails on "GOO is inoperable"
    what am i doing wrong?

    Is the data worthless? Try it without the m:dump that you've currently got before calling m: reset. From memory, dumping the data will leave goo & science juniors inoperative and you have no protection that checks that ahead of the m:deploy in that section. Resetting dumps the data anyway, I believe.

    It'd be interesting to know for sure which commands it is trying (and the one it falls over on). Some debug print statements might help.

    Edit: my reset function does this:

    m:RESET().
    WAIT UNTIL NOT (m:DEPLOYED OR m:HASDATA).

  16. 5 hours ago, Steven Mading said:

    Did something change to make this the case?  I swear I've used kOS on manned capsules with no robotic probe core (just a "probe core" made of meat).  I realize this makes no sense (is the Kerbal being commanded by a chip in its head that kOS is talking to?) but it had always been how it worked, as far as I remembered.

    Rereading old threads, it seems to be the case that this is required for Remote Tech+kOS, because RemoteTech only allows remote control of those parts with a certain control module (that RT adds to most probe cores). I guess stock+kOS probably doesn't have this requirement.

    https://www.reddit.com/r/Kos/comments/5q1yuj/kos_no_signal_when_remote_tech_signal_mode_is/

    https://github.com/KSP-KOS/KOS/issues/1538

  17. 1 hour ago, danielboro said:

    i have a scrip running, then if i turn off the antenna it will stop steering

    if i turn on the antenna it will start steering 

    this problem was mention in this tread after the update to 1.03/1.2.2

    but i didnt see any solution of work around posted

    all my scrips start running using autoboot

    edit: i just run on pages 186(pre 1.02) to page 195 and didnt find a post abut this lost steering wen not connected
    i do remember reading it ?!

     

    I remember reading something similar, but it wasn't about Remote Tech.

    With KSP's CommNet and the difficulty option that disables all control if there is no connection aactive, KSP won't let kOS control a vessel if there is no connection. That wasn't meant to happen (KSP was meant to allow autopilot mods to control vessels even when there is no signal) but appears to be a KSP bug/oversight. As to Remote Tech, I would've thought it would be completely independent of the CommNet behaviour. I don't remember hearing of a similar issue.

  18. 1 hour ago, MrabEzreb said:

    so I need a probe core no matter what, and I must have a connection even if there are kerbals on board?

    I don't use remote tech, but this seems to come up a lot: you need either a probe core or a part modded to contain the probe core module (e.g. combining the kOS CPU and probe core into one part).

    I don't think you need the connection unless trying to access the archive, or to enter commands without local control. I don't use remote tech and may be wrong.

  19. 59 minutes ago, MrabEzreb said:

    (I use remote tech) If I have crew on the vessel, giving the vessel local control, kOS tells me I have no signal, and I can't do anything! Why is this happening!

    kOS+RT requires a probe core (and a connection?) to do anything. Bear in mind the kOS CPU is a computer that tells the probe core what to do, it isn't able to order around (or be ordered around by) Kerbals.

    In reply to stargateat77:

    Can't get the referencing to work on my phone, but is it possible you ran out of electric charge? That would cause the CPU to die, then reboot on power being restored. This would be unusual during a launch, but not impossible.

    @stargateat77

  20. On 02/22/2017 at 10:00 PM, podbaydoor said:

    I'm trying to call the trajectory prediction functions (`positionat` and `velocityat`) on a landed vessel to do some precision landings. I was hoping this would be a clean way to account the changing absolute position of the landed vessel as the parent body rotates. However I just get NaN vectors back. Am I doing something wrong or does `positionat` not work on unloaded or landed vessels?

    If trajectory prediction won't work here, does anyone have code for computing the position of a landed vessel in the future, accounting for rotation speed, elevation, latitude, etc?

    I wouldn't expect POSITIONAT to work for anything landed. Landed vessels have an orbital velocity based on the body's rotation, but their trajectory does not follow the Keplerian orbit that corresponds to this velocity (e.g. a 175m/s orbital velocity at Kerbin's equator corresponds roughly to a 0m by -598500m orbit, but the vessel can't fall through the planet towards periapsis). For the same reasons, VELOCITYAT is likely not to predict their future velocity.

    At least body rotation is predictable. Can you rotate the landed craft's current position vector (converted to be from the body's centre to the craft) around the body's axis of rotation by the angle the body will rotate over the time that will elapse? That could then be converted back to be relative to the active vessel. I've not done any accurate landings yet, so I don't really have anything useful to share, I'm afraid.

×
×
  • Create New...