pizzaboy150
Members-
Posts
12 -
Joined
-
Last visited
Content Type
Profiles
Forums
Developer Articles
KSP2 Release Notes
Everything posted by pizzaboy150
-
Hi All, So with Chat GPT launch I though it would be fun to test it on a few scripts to see how it would perform. I have very basic knowledge of vector math or PID loops but I am a coder so thought it would be fun to try and write a fly by wire type script for KSP. The script runs surprisingly well, though it is easy to break particularly if you try and yaw / rudder while it is running. The code was created in chat GPT but in a pesudo code format so all I did was translate it into KOS code and run it. There is a lot wrong with it such as exiting cleanly and passing back control to the player again. But as a starting point to send craft in a particular orientation it works pretty well. It does depend how well the craft fly's but if the craft is stable then it seems to have no problems. Anyways I have no real use for the code but thought it maybe fun to share for anyone trying to do something similar. // // FLY BY WIRE SCRIPT // set desiredPitch to 90 - vectorangle(ship:up:forevector, ship:facing:forevector). set desiredRoll to 0.0. set pitch to 0.0. // Pitch value to set the control to set roll to 0.0. // Roll value to set the control to set speed to 0.25. // Max speed we can set pitch and roll at full value // Adjustment speeds for pitch set pitchKp to 0.01. // Big adjustment speed set pitchKi to 0.001. // Medium adjustment speed set pitchKd to 0.0001. // Fine adjustment speed // Adjustment speeds for roll set rollKp to 0.01. // Big adjustment speed set rollKi to 0.0001. // Medium adjustment speed set rollKd to 0.00001. // Fine adjustment speed // Pitch variables set pitchIntegral to 0.0. set pitchError to 0.0. set pitchPreviousError to 0.0. // Roll variables set rollIntegral to 0.0. set rollError to 0.0. set rollPreviousError to 0.0. // Just an infiniate loop to get going set loop to 0.0. until loop > 0.0 { clearScreen. print "FLY BY WIRE PROGRAM". print "=============================". // Get current pitch and roll set currentPitch to 90 - vectorangle(ship:up:forevector, ship:facing:forevector). set currentRoll to arctan2(-vdot(ship:facing:starvector, ship:up:forevector), vdot(ship:facing:topvector, ship:up:forevector)). // Set desired attitude from pilot input if ship:control:pilotpitch > 0 { set desiredPitch to desiredPitch + ship:control:pilotpitch * speed. } if ship:control:pilotpitch < 0 { set desiredPitch to desiredPitch + ship:control:pilotpitch * speed. } if ship:control:pilotroll > 0 { set desiredRoll to desiredRoll + ship:control:pilotroll * speed. } if ship:control:pilotroll < 0 { set desiredRoll to desiredRoll + ship:control:pilotroll * speed. } // Calculate the difference for all axis set pitchError to desiredPitch - currentPitch. set rollError to desiredRoll - currentRoll. // Set the integral and derivative set pitchIntegral to pitchIntegral + pitchError. set pitchDerivative to pitchError - pitchPreviousError. set rollIntegral to rollIntegral + rollError. set rollDerivative to rollError - rollPreviousError. // Calculate control signal set pitch to pitchKp * pitchError + pitchKi * pitchIntegral + pitchKd * pitchDerivative. set roll to rollKp * rollError + rollKi * rollIntegral + rollKd * rollDerivative. // Update controls set ship:control:pitch to pitch. set ship:control:roll to roll. // Update error for next calculation set pitchPreviousError to pitchError. set rollPreviousError to rollError. // Debug to see values print "DESIRED PITCH :" + round(desiredPitch, 2). print "DESIRED ROLL :" + round(desiredRoll, 2). print "CURRENT PITCH :" + round(currentPitch, 2). print "CURRENT ROLL :" + round(currentRoll, 2). print "PITCH INPUT :" + round(pitch, 2). print "ROLL INPUT :" + round(roll, 2). // Wait for next calculation wait 0.02. } P.S if you find you are getting a lot of oscillations when using it then play with the adjustment speeds. the current settings seem to work okay for the stock Aeris 3A but other craft may need tweaks. From what I can tell the 3 adjustments speeds limit how fast it adjust the controls. If they are out further then it uses the larger adjustments then gets finer as it get closer to it target pitch or roll. Have fun!
-
Sorry I should have been more specific, I am creating a mod command pod and would like to see a kerbal in it. Do you place them using the part config file? Thats more the question. I have found this for I believe is an external seat MODULE { name = KerbalSeat seatPivotName = seatPivot ejectDirection = 0, 1, 0.2 } What about internal seating?
-
Hi, I know this has been covered somewhere in the forum but struggling to find it. I have a cmd pod which I have created and want to put a kerbal inside it. Is there any info on how to place kerbals in seats? Thanks!
-
Hi Everyone, Just finished putting some calculators together for some basic tools in ksp. I know mech jeb and engineer do the same thing in game but I find it handy when I am not using those mods or early in career. Anyways the link is here if you would like to use it. http://www.pizzaboyweb.co.uk
-
So I have started testing and the values seem very very high I was expecting small force values? What unit is returned from p.dragVectorDir * p.dragScalar?? - - - Updated - - - Oh perhaps the force is in Newtons not kN which I am now accustomed too?
-
Hi Chaps thanks for the help that has steered me in the right direction!
-
Hi Peeps, I have been searching the forum for information on the drag system. Also looking in the api there are DragCubes. My question is whether there is a function in the api that will give me the current force of drag acting on a vessel or whether I have to find all the variables and try and calculate it myself? Any help appreciated!
-
Help with Math and atmospheric pressure
pizzaboy150 replied to pizzaboy150's topic in KSP1 Gameplay Questions and Tutorials
Ignore my second post it is correct!!!! i didnt spot python adding the e-11 at the end! -
Help with Math and atmospheric pressure
pizzaboy150 replied to pizzaboy150's topic in KSP1 Gameplay Questions and Tutorials
Well I just smashed the correct formula into a simple python script to check the output up to 70km and now have an error at around 47km... Alt : 0 1.0 Alt : 1 0.8187307531056343 Alt : 2 0.670320046080919 Alt : 3 0.5488116361496342 Alt : 4 0.44932896417792534 Alt : 5 0.36787944123356736 Alt : 6 0.30119421197323853 Alt : 7 0.24659696399990763 Alt : 8 0.2018965180492073 Alt : 9 0.16529888827183278 Alt : 10 0.13533528328232175 Alt : 11 0.11080315840349961 Alt : 12 0.09071795332618014 Alt : 13 0.07427357824694523 Alt : 14 0.060810062653971736 Alt : 15 0.049787068393087074 Alt : 16 0.04076220400039389 Alt : 17 0.033373269979487995 Alt : 18 0.027323722463903855 Alt : 19 0.022370771870521344 Alt : 20 0.018315638901106275 Alt : 21 0.014995576831113588 Alt : 22 0.012277339912191026 Alt : 23 0.010051835752442027 Alt : 24 0.008229747055690998 Alt : 25 0.006737947004774766 Alt : 26 0.005516564425605095 Alt : 27 0.0045165809467314095 Alt : 28 0.003697863719979968 Alt : 29 0.0030275547483412006 Alt : 30 0.0024787521791779297 Alt : 31 0.002029430638420578 Alt : 32 0.0016615572749697277 Alt : 33 0.0013603680390641114 Alt : 34 0.0011137751491237945 Alt : 35 0.0009118819666324642 Alt : 36 0.0007465858092844442 Alt : 37 0.0006112527618934322 Alt : 38 0.000500451434082909 Alt : 39 0.0004097349795194947 Alt : 40 0.00033546262835571747 Alt : 41 0.00027465357035247226 Alt : 42 0.00022486732449783064 Alt : 43 0.00018410579393495803 Alt : 44 0.00015073307531947874 Alt : 45 0.0001234098042742452 Alt : 46 0.00010103940199407177 Alt : 47 8.272406568794921e-05 Alt : 48 6.772873660065466e-05 Alt : 49 5.545159952394706e-05 Alt : 50 4.539992983915324e-05 Alt : 51 3.717031874815291e-05 Alt : 52 3.0432483061851678e-05 Alt : 53 2.49160097761043e-05 Alt : 54 2.0399503448377194e-05 Alt : 55 1.6701700821270857e-05 Alt : 56 1.3674196091544086e-05 Alt : 57 1.1195484864143998e-05 Alt : 58 9.166087754203352e-06 Alt : 59 7.504557930031233e-06 Alt : 60 6.144212365779335e-06 Alt : 61 5.030455617475469e-06 Alt : 62 4.1185887161601544e-06 Alt : 63 3.372015241314173e-06 Alt : 64 2.760772578004827e-06 Alt : 65 2.260329411943277e-06 Alt : 66 1.8506012017071356e-06 Alt : 67 1.5151441155718734e-06 Alt : 68 1.2404950828057307e-06 Alt : 69 1.015631473369371e-06 Alt : 70 8.315287210694906e-07 Also checked the individual values in the windows calculator and have the errors. Whether this is a rounding error to do with the precision of the computer or a mathematical error I am unsure... -
Help with Math and atmospheric pressure
pizzaboy150 replied to pizzaboy150's topic in KSP1 Gameplay Questions and Tutorials
Your a hero slashy need to take more care with the format of the equation just assumed i had to multiply never even though about raising to the power! Thank you!!! -
Hi Everyone, I wonder if anyone can help me calculate pressure as I am doing it wrong but cannot figure out why? p = p0 * e * -(alt/scale) ... p0 = 1 atm at at sea level e = 2.718281828 base of natural logarithm alt = 10 km pressure I am trying to find scale = 5km scale height for kerbin so.. p = 1 * 2.718281828 * -(10,000 / 5000) = -5.436563656 I was expecting a value between 1 and 0? My math isn't great though I am trying! Any help most appreciated!