meyerweb Posted February 12, 2018 Share Posted February 12, 2018 On 2/9/2018 at 4:02 AM, Steven Mading said: It's not that simple. Under the hood, kOS is doing some fancy footwork to make TERRAINHEIGHT work because of the fact that the game doesn't load the actual physical (collider) polygons for the terrain until you are very close to it. Most of the terrain you are looking at on the screen is a "hologram" so to speak - it has visual appearance but no physics interactions. As you move across the terrain, the game populates the terrain colliders in front of you as you move, and despawns them as you leave them behind you. Anything more than about 6 or 7 km away from you isn't "really there". At least it isn't "really there" as far as the Unity's raycast call is concerned, and that's what matters here. Ah, very interesting—that does make things more difficult. I’d be happy to have a slope method that only worked for loaded terrain, but I can see why that would be undesirable from a support point of view (“why does this function work here but not there?!?”). Thanks for the thorough explanation! This is one of the things I really love about the kOS community: the openness and interest in helping people understand. I’ve been on the web a long time, and communities like this are rare. I hope everyone here appreciates it, and especially the community leaders who set that tone. Quote Link to comment Share on other sites More sharing options...
Nich Posted February 12, 2018 Share Posted February 12, 2018 I am attempting to write my launch code for RP-0 but my clamps keep dropping my engines before they are spooled up So vessels have MAXTHRUST MAXTHRUSTAT() AVAILABLETHRUST AVAILABLETHRUSTAT() But these appear to have the post spool up values before the engines spool up And it appears what I have been looking for is THRUST is only available for single engines. I hate working with lists. How would I step through the list for all engines summing current thrust? local function Thrust { Set TotalThrust to 0. List Engines in AllMyEngines. For i in AllMyEngines { TotalThrust = TotalThrust+i:Thrust. } return Thrust. } Quote Link to comment Share on other sites More sharing options...
MaximumThrust Posted February 12, 2018 Share Posted February 12, 2018 I want to use kOS for the first time, but I suck at programing. If someone could give an example, I would be immensely grateful. I've made a rover for the Mun, with engines pointing down. Sometimes the rovers jumps too high, and can break on the fall. To avoid that I fire the engines to keep the vertical speed low, around -15 or -20 m/s. I've set the engines to actions groups, and want a script that: 1. Activate the engines when the vertical speed decreases more than -20 m/s. 2. Shutdown the engines when the vertical speed increases more than -10 m/s. So it will do short bursts, keeping the vertical speed between -20 and -10 m/s in the long falls. Some pics of it, and a failed try to do this with SmartParts (sometimes they don't react quickly enough). Thanks! Quote Link to comment Share on other sites More sharing options...
scimas Posted February 12, 2018 Share Posted February 12, 2018 16 minutes ago, Nich said: And it appears what I have been looking for is THRUST is only available for single engines There is a SHIP:AVAILABLETHRUST variable, which gives the total thrust of all active engines taking into account thrust limiting (not throttle). Check out the kOS wiki, specifically the vessel structure page. Quote Link to comment Share on other sites More sharing options...
Nich Posted February 12, 2018 Share Posted February 12, 2018 (edited) @scimas I tried that but AVAILABLETHRUST does not appear to take into account the RSS real engines spool time. So my script stages the engines and then drops my rocket on the pad because it thinks it has a TWR of 1.39. Since none of my engines are thrust limited AVAILABLETHRUST = MAXTHRUST. Edited February 12, 2018 by Nich Quote Link to comment Share on other sites More sharing options...
scimas Posted February 12, 2018 Share Posted February 12, 2018 @Nich ah, my bad, totally missed the paragraph about availablethrust from your post somehow. Hmm, I don't see any other way of getting the total current thrust value. But, assuming that you are having this problem only at launch, couldn't you just add a WAIT command? If I remember correctly, most engines have spool up times around 1-2 sec, so "WAIT 1.5" after ignition and then decouple clamps. The clamps have fuel pumps, so there isn't a problem of wasting fuel. Does that work? Though you will need to write special conditions for when your lowest stage is a solid motor instead of liquid fuel. Quote Link to comment Share on other sites More sharing options...
Nich Posted February 12, 2018 Share Posted February 12, 2018 That is my current workaround but it failed me when My new engines took 4 seconds to spool up. I was lucky it bounced on the engine bell and went up but it was a real black eye for the space program. I would like to avoid wasting 10 seconds of my engines burn time on the pad and I would also like to finish this in a more elegant manor. I am thinking stage. wait until stage:ready. wait until Thrust()/MAXTHRUST > .97 stage. Quote Link to comment Share on other sites More sharing options...
Basedoesgames Posted February 13, 2018 Share Posted February 13, 2018 (edited) I'm having some trouble with communication between processors. I'm working on a Falcon Heavy recreation and i have multiple CPUs on the rocket (One on each side booster, One in the core, one in the second stage). I'm trying to get the second stage CPU to send a message to the side boosters right before staging to have the script get ready to set some variables after staging to receive the message properly from the second stage to start their boostback. I'll include both the side booster script along with the core script. Parts of the script pertaining to the problem are bolded. UPDATE: I've fixed the problem. Spoiler Side Booster script: WAIT UNTIL NOT CORE:MESSAGES:EMPTY. // make sure we've received something SET RECEIVED TO CORE:MESSAGES:POP. IF RECEIVED:CONTENT = "wait" { PRINT "Configuring for staging...". wait 2. set sb to vessel("FH Probe"). WAIT UNTIL NOT ship:MESSAGES:EMPTY. // make sure we've received something SET RECEIVED TO ship:MESSAGES:POP. IF RECEIVED:CONTENT = "rtls" { PRINT "Boostback starting...". wait 1. rcs on. sas off. LOCK STEERING TO heading(270,0). wait 15. lock throttle to 1.0. wait 15. lock throttle to 0.0. print "Running HoverSlam Script". set radarOffset to 14. // The value of alt:radar when landed (on gear) lock trueRadar to alt:radar - radarOffset. // Offset radar to get distance from gear to ground lock g to constant:g * body:mass / body:radius^2. // Gravity (m/s^2) lock maxDecel to (ship:availablethrust / ship:mass) - g. // Maximum deceleration possible (m/s^2) lock stopDist to ship:verticalspeed^2 / (2 * maxDecel). // The distance the burn will require lock idealThrottle to stopDist / trueRadar. // Throttle required for perfect hoverslam lock impactTime to trueRadar / abs(ship:verticalspeed). // Time until impact, used for landing gear WAIT UNTIL ship:verticalspeed < -1. print "Preparing for hoverslam...". rcs on. brakes on. lock steering to srfretrograde. when impactTime < 3 then {gear on.} WAIT UNTIL trueRadar < stopDist. print "Performing hoverslam". lock throttle to idealThrottle. WAIT UNTIL ship:verticalspeed > -0.01. print "Hoverslam completed". set ship:control:pilotmainthrottle to 0. rcs off. } } Spoiler Main script: clearscreen.set sbc to processor("SBS"). set wat to "wait". set rtls to "rtls". print "Falcon Launch Script Running...". wait 1. print "3".rcs off. lock steering to up. wait 1. print "2". wait 1. print "1". wait 1. print "0". lock throttle to 0.5. wait 1. stage. print "Liftoff". lock throttle to 1.0. wait until ship:altitude > 1000. lock steering to heading(90, 85.5). wait until ship:altitude > 2000. lock steering to heading(90, 81). wait until ship:altitude > 3000. lock steering to heading(90, 76.5). wait until ship:altitude > 4000. lock steering to heading(90, 72). wait until ship:altitude > 5000. lock steering to heading(90, 67.5). wait until ship:altitude > 6000. lock steering to heading(90, 63). wait until ship:altitude > 7000. lock steering to heading(90, 58.5). wait until ship:altitude > 8000. lock steering to heading(90, 54). wait until ship:altitude > 9000. lock steering to heading(90, 49.5). wait until ship:altitude > 10000. lock steering to heading(90, 45). wait until ship:orbit:apoapsis > 41000. set ship:control:roll to 0.5. wait 2. set ship:control:roll to 0.0. lock throttle to 0.0. lock steering to heading(90, 45).rcs on.set sbc to processor("SBS"). wait 3.IF sbc:connection:SENDMESSAGE(wat) { PRINT "Config Message sent!". } stage. set sb to vessel("FH Probe"). wait 2.IF sb:connection:SENDMESSAGE(rtls) { PRINT "Boostback Message sent!". } wait 2. lock throttle to 1.0.rcs off. wait 5. lock steering to heading(90, 30). wait until ship:orbit:apoapsis > 100000. lock throttle to 0.0. wait 5. stage. lock steering to heading(90, 0). wait until ship:orbit:apoapsis - 1000. lock steering to heading(90, 0). lock throttle to 1.0. wait until ship:orbit:periapsis > 80000. lock throttle to 0.0. Edited March 12, 2018 by Basedoesgames Quote Link to comment Share on other sites More sharing options...
Pand5461 Posted February 14, 2018 Share Posted February 14, 2018 On 12.02.2018 at 7:28 PM, RagnarDa said: Btw, do you know how faithful KSP is to real-world aerodynamics? Things like this: https://www.grc.nasa.gov/www/k-12/airplane/flteqs.html I am testing it a bit and having mixed results. Want to know if it is something I did, some simplifications I did or that KSP just doesnt follow those types of equations. I must follow the equations, more or less. Thing is, drag coefficient Cd itself depends on the airspeed, so it's not exactly that easy. Quote Link to comment Share on other sites More sharing options...
Nich Posted February 14, 2018 Share Posted February 14, 2018 How do rotations work? I am trying to lock on to 5 degrees below prograde but the following code seems to lock 3 degrees right yaw and 3 degrees pitch up. lock steering to mysteer. lock mysteer to srfprograde+R(pitchcorrection,0,0). set pictchcorrection to -5. Quote Link to comment Share on other sites More sharing options...
bitbased Posted February 15, 2018 Share Posted February 15, 2018 (edited) 9 hours ago, Nich said: How do rotations work? I am trying to lock on to 5 degrees below prograde but the following code seems to lock 3 degrees right yaw and 3 degrees pitch up. lock steering to mysteer. lock mysteer to srfprograde+R(pitchcorrection,0,0). set pictchcorrection to -5. Not completely sure if it is the problem, but srfprograde is not the same as orbital prograde so maybe you just want prograde. Also rotations are euler rotations, so order can be a problem, but shouldn't e the case here. something like AngleAxis might help, but regardless the documentation page has all the details on kOS rotations https://ksp-kos.github.io/KOS/math/direction.html?#function:ANGLEAXIS . Edited February 15, 2018 by bitbased spelling/grammer fixes Quote Link to comment Share on other sites More sharing options...
Nich Posted February 15, 2018 Share Posted February 15, 2018 (edited) From that section on directions // Initializes a direction to prograde // plus a relative pitch of 90 SET X TO SHIP:PROGRADE + R(90,0,0). so if I take the cross produce of SRFPROGRADE and UP I should get a vector that points out the left side of the ship (assuming I am pointing in the direction of prograde). Then a positive rotation would be up and a negative would be down correct? UG so many operations to do something so simple Edited February 15, 2018 by Nich Quote Link to comment Share on other sites More sharing options...
scimas Posted February 15, 2018 Share Posted February 15, 2018 1 hour ago, Nich said: so if I take the cross produce of SRFPROGRADE and UP I should get a vector that points out the left side of the ship Not quite correct. As you said, SRFPROGRADE and UP are directions not vectors, so there is no cross product defined for them. Multiplication of directions does exist, but it's not the same as vector cross product. What you will need to get the expected vector is use the :VECTOR suffix on both directions take cross product of those vectors. And remember that KSP's coordinate system is left handed when taking cross products. Quote Link to comment Share on other sites More sharing options...
radio Posted February 15, 2018 Share Posted February 15, 2018 I ran into a problem while building a GUI. 'Addtextfield' doesn't allow me to type in any characters into the box. It appears to be refusing user input. The error I get in the console is: "Exception: NullReferenceException: Object reference not set to an instance of an object" Pasting values into the field by using CTRL+V does work. Here's the piece of code in question: LOCAL gui_ascent is box_options:addlabel("Orbit altitude"). SET gui_ascent:style to style_label_compact. LOCAL gui_orbit_altitude is box_options:addtextfield(""). SET gui_orbit_altitude:onconfirm to { parameter int. SET int TO int:tonumber(0). IF int = 0 SET gui_orbit_altitude:text to "0". IF int < 0 SET int to 0. SET orbit_altitude to int. }. Is that a bug I'm unaware of? Quote Link to comment Share on other sites More sharing options...
Dunbaratu Posted February 16, 2018 Author Share Posted February 16, 2018 1 hour ago, radio said: I ran into a problem while building a GUI. 'Addtextfield' doesn't allow me to type in any characters into the box. It appears to be refusing user input. The error I get in the console is: "Exception: NullReferenceException: Object reference not set to an instance of an object" Pasting values into the field by using CTRL+V does work. Here's the piece of code in question: LOCAL gui_ascent is box_options:addlabel("Orbit altitude"). SET gui_ascent:style to style_label_compact. LOCAL gui_orbit_altitude is box_options:addtextfield(""). SET gui_orbit_altitude:onconfirm to { parameter int. SET int TO int:tonumber(0). IF int = 0 SET gui_orbit_altitude:text to "0". IF int < 0 SET int to 0. SET orbit_altitude to int. }. Is that a bug I'm unaware of? When you get NullReferenceException, that's not your fault. We're supposed to be preventing those in the C# code. That's on us. Do you have the output log from KSP itself? It should also mention this error when you get it, and it usually has more information about where in our code it happened. Quote Link to comment Share on other sites More sharing options...
radio Posted February 16, 2018 Share Posted February 16, 2018 Sure thing. Just generated one. The same error every time. There's also the "Look rotation viewing vector is zero" going on. Keeps spamming in the console. As a side note, I crashed the game by drawing vectors and pressing "M" to enter the map view. Crashes every time I do it. Not sure which vector is responsible for that. All of them, or a particular one. But that's another issue. Here's the log: https://ufile.io/41zye Quote Link to comment Share on other sites More sharing options...
Dunbaratu Posted February 16, 2018 Author Share Posted February 16, 2018 13 minutes ago, radio said: Sure thing. Just generated one. The same error every time. There's also the "Look rotation viewing vector is zero" going on. Keeps spamming in the console. As a side note, I crashed the game by drawing vectors and pressing "M" to enter the map view. Crashes every time I do it. Not sure which vector is responsible for that. All of them, or a particular one. But that's another issue. Here's the log: https://ufile.io/41zye Hmm. Whatever is wrong it must require your exact program to trigger it. When I perform this much simpler test, it works fine: set my_gui to GUI(100). my_gui:addtextfield(""). my_gui:show(). wait 20. // time to play with it a bit before it goes away. my_gui:dispose(). Does that simpler example work when you try it? If it does, then the problem probably requires that I run your *exact* script. I see that you are making custom style changes. It is possible there is something in the style code that is not set up right so when it tries to draw the GUI it hits this error. Can you perform a test where all the custom style changes you made aren't there and it just displays the stock appearance, but other than that it's the exact same GUI widgets? It might help narrow down the cause of it. Quote Link to comment Share on other sites More sharing options...
radio Posted February 16, 2018 Share Posted February 16, 2018 Thanks for the tip. You are right. This is the line causing the issue: SET gui:skin:font to "Corbel". Quote (Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42) kOS: 62 fonts found 'Corbel' is not one of the supported fonts. So that's all it was. I changed it to a different font that's on the list and it works. Thanks! Quote Link to comment Share on other sites More sharing options...
kcs123 Posted February 16, 2018 Share Posted February 16, 2018 I recently got similar NullReferenceException error in otherwise prooven working script that I used a lot of time. It is set to be executed at boot time. Rather simple script, to execute maneuver node burning. Case when it failed is on complex craft with lot of parts and possible other installed mods too. I solved issue by adding wait 1. command, to allow game physics to settle down before starting any calculation when some of ship parts/properties not being completely unpacked on scene change. Or something similar that caused issue. Just something to keep on mind when starting up scripts on boot/scene change. Quote Link to comment Share on other sites More sharing options...
ElWanderer Posted February 16, 2018 Share Posted February 16, 2018 3 hours ago, kcs123 said: I recently got similar NullReferenceException error in otherwise prooven working script that I used a lot of time. It is set to be executed at boot time. Rather simple script, to execute maneuver node burning. Case when it failed is on complex craft with lot of parts and possible other installed mods too. I solved issue by adding wait 1. command, to allow game physics to settle down before starting any calculation when some of ship parts/properties not being completely unpacked on scene change. Or something similar that caused issue. Just something to keep on mind when starting up scripts on boot/scene change. Yes, I've had my common initialisation script call 'WAIT UNTIL SHIP:UNPACKED.' for a while, to avoid weird issues. Though I think most of mine were due to booting up (after regaining power) during time warp. Quote Link to comment Share on other sites More sharing options...
MindChirp Posted February 20, 2018 Share Posted February 20, 2018 (edited) Humm... Seems like my kOS computers aren't utilizing the RCS modules attached to my rocket.. Excuse me for my nasty coding. It's because I'm kinda new to C# / kerboscript, since I have only coded in javascript before. Code is as follows: print "Initiating launch procedure". sas off. rcs on. wait 2. lock throttle to 1.0. until ship:maxthrust > 0 { wait 0.5. wait 1. stage. wait 2. stage. } wait 5. from {local pitch is 90.} until pitch = 45 step {set pitch to pitch - 45/10000.} do { print "Pitching to... " + pitch + " degreeds.". lock steering to heading(90,pitch). if pitch <= 45 { print "Gravity turn achieved.". lock steering to heading(90,pitch). wait until alt:apoapsis > 90000. lock throttle to 0.0. wait until alt:radar > 70000. global pitch is 90. lock steering to heading(90,pitch). } } lock throttle to 1.0. wait until alt:periapsis > 90000. lock throttle to 0.0. print "Orbit successfully created!". While some of this code is not tested yet (Because I edited it slightly in preparations for this post), the problem should still occur. It is when i want to pitch my rocket to heading(90,90) that it only steers the vessel when thrusting, but not with rcs or inline reaction wheels and so on. Any suggestions (Btw, I haven't found anything that solves my problem, so I am asking here). Edited February 20, 2018 by MindChirp Quote Link to comment Share on other sites More sharing options...
linuxgurugamer Posted February 20, 2018 Share Posted February 20, 2018 Turn on rcs? Quote Link to comment Share on other sites More sharing options...
Kerbal101 Posted February 20, 2018 Share Posted February 20, 2018 @MindChirp Hello and welcome to the forums, MindChirp! I am sorry to ask, but perhaps your topic gets better attention in kOS thread? I can move it for you, if you wish so. In addition, I would like to ask you to not double post. Our spam-fighting system requires that all messages from new users must go through approval by moderation team (which is fully automatic), thus your messages may not be instantly available publicly. After certain amount of messages, this requirement is removed. I hope you will find the solution to your problem and wish you best of luck! Quote Link to comment Share on other sites More sharing options...
MindChirp Posted February 20, 2018 Share Posted February 20, 2018 (edited) 43 minutes ago, linuxgurugamer said: Turn on rcs? Doesn't matter. Btw I have already done that rcs on. Edited February 20, 2018 by MindChirp Quote Link to comment Share on other sites More sharing options...
MindChirp Posted February 20, 2018 Share Posted February 20, 2018 14 minutes ago, Kerbal101 said: @MindChirp Hello and welcome to the forums, MindChirp! I am sorry to ask, but perhaps your topic gets better attention in kOS thread? I can move it for you, if you wish so. In addition, I would like to ask you to not double post. Our spam-fighting system requires that all messages from new users must go through approval by moderation team (which is fully automatic), thus your messages may not be instantly available publicly. After certain amount of messages, this requirement is removed. I hope you will find the solution to your problem and wish you best of luck! Yes please ^^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.