Jump to content

amiavamp

Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by amiavamp

  1. The difficulty is that I don't have access to parameters such as true anomaly at the start and end locations of the transfer - although, I believe the true/mean/eccentric anomalies at the end point would be 180 degrees since it is an apoapsis. The only parameters that I have to start with are the apoapsis and periapsis of my orbit and that of my target. Everything else must be calculated from this. Many of the equations that I've seen require knowing either the velocity or radius at a given point, but those are the values that I am searching for. A lot of textbook questions that I've seen seem to assume that the orbits in a coplanar transfer are circular, or that the person doing the transfer knows what their start and end altitudes are before beginning. I've now finally gotten to the point where the hohmann transfer itself is calculated to correctly have its apoapsis tangent to the target's orbit even at a long distance, at least for circular orbits. However, now the issue is that I can't get it to actually intercept the target. It seems that the script doesn't properly compensate for the fact that the target is orbiting at a different speed than myself. When the time to burn is calculated to be negative, my orbital period is added to make it wait another orbit. However, the target is not at the same location when I complete an orbit. I'm really not sure how to tackle this issue. Kerbal Engineer Redux seems to be able to calculate the total phase angle to the target including the number of orbits needed with 360 degrees as the denominator even though 1 degree on this readout is less than 1 degree on the interceptor's orbit. EDIT: Scratch that, I have fixed the issue of waiting for the correct time. The calculations are still woefully inaccurate, though. The intercept is typically about 80+ km off if the orbits aren't very close together. I'm about to scrap this idea if I can't get any closer. I have a few more questions to anyone willing to answer: Can kOS read the "target" velocity information as it appears above the navball when clicking the velocity indicator there? If not, how would I go about creating a script that zeroes one's velocity relative to another vessel?
  2. I recently decided to take on the challenge of rescuing a kerbalnaut from orbit early in a career game without any upgraded buildings at the KSC. I concluded that my rescue ship would be guided by a probe core for its lower mass. I am using RemoteTech2, so the probe would have no connectivity except when over the KSC and would need to be guided by autopilot. To this end, I wrote a kOS script to calculate a coplanar rendezvous. On my initial test run, I was astonished when it worked perfectly - a maneuver node was plotted that intercepted the target orbit at precisely the right location via a hohmann transfer. This maneuver node was simply for visualization purposes, and the script will be capable of performing the burn without the node to help it. However, every other time that I've attempted to use the script, it fails in some way. Sometimes the intercept is not at the correct location, sometimes my probe and the target end up exactly opposite from one another, and sometimes the burn is set to an absurdly low deltaV value that doesn't go anywhere. I barely understand the math behind what I'm doing, and I eventually grew fed up with tinkering with code. So, I've come to ask for help. This is the basic logic that the code follows: The chaser ship is me. The target ship is set to a specified vessel. Get the semi-major axis of me and the target, then find the semi-major axis of the transfer orbit. Get the altitude + planet radius for me and the target. Calculate the angular velocity (radians per second) of me and the target. Find the time of flight for the transfer orbit. Find the phase angle I need to be at when starting the burn. Find the time until the burn starts. If the wait time is negative (because the spot is behind me), keep shifting forward full orbits until it becomes positive. Calculate the velocity and altitude I will be at when I start the burn. Calculate the velocity and altitude I will be at when I intercept the target. Find the deltaV needed by taking the absolute value of the velocity when I start the burn and when I intercept the target. Mark the current time and add it to the time until burn so I have the time when it starts. Determine if the burn is prograde or retrograde by comparing the semi-major axis of the transfer orbit and of the target's orbit. Dump all of this onto another script that actually does the burn. I don't expect anyone to go rifling through the actual script, but I do have some questions that would likely help me along. 1. Does a coplanar rendezvous require the orbits to be circular? I noticed that the script seems to grow more inaccurate as eccentricity increases, but this might be because of errors in calculation. 2. How do I properly find the phase angle between myself and the target? Right now, I'm using the law of cosines, and I seem to have problems if the phase angle is > 180. 3. I find the semi-major axis of the transfer orbit by adding the sma of me and the target, then dividing by 2. Is this right? Can I do the same for the semi-minor axis? 4. In order to find the velocity and altitude of the start of the burn and the intercept, I followed the post at http://www.orbiter-forum.com/showthread.php?t=26682. This involves find the orbital period, mean motion, mean anomaly, eccentricity, eccentric anomaly, true anomaly, and flight path just to get those two values. Is there a simpler way to find the velocity and altitude at a given point on an orbit? 5. Finding the eccentric anomaly involves iteration. My current code uses the "simple iterative method" from http://www.stargazing.net/kepler/kepler.html and normally takes 9 to 12 iterations. My original code took anywhere from 5 to 20 iterations. Is there a "best" way to find the eccentric anomaly? 6. How would I go about calculating the burn direction that would normally be given by a maneuver node (the blue dot)? 7. Should I have gone through all of this effort to save Matburry Kerman? A big thanks to anyone who understands this mess.
  3. Thank you for the thorough explanation. I've been beating my head against a wall trying to learn orbital mechanics and programming logic at the same time. I'm not sure what was causing the NaN errors, but they all stopped on their own when I removed "SET CONFIG:SAFE TO FALSE.", perhaps because I'd unknowingly fixed a bug in my scripts at that point. As for the "STATUS" variable, is there a list of all the possible values of it? It took me a bit to figure out that I also need to check for "PRELAUNCH" in scripts that detect whether a vessel is landed. Incidentally, I found that checking altitude for whether a vessel is on the ground is unreliable at best - I had one landed rocket with a "radar altitude" of over 100 meters because of its height. And as for the problem with fuel and staging...well, it was working for a bit, then started breaking sporadically. Then I discovered it was because engines would stop burning at random points - I had solid boosters on the same rocket that stopped at 0, 0.01, and 0.06 fuel during different launches using the same launch autopilot. I adjusted my script, but it still only works half the time, and I know it's not just because of the fuel levels now. I think having two separate conditions check for the same thing within a loop, one of which relies upon a flag set by the other, is a bad idea. My guess is that sometimes one triggers before the other in the wrong order, so the rocket no longer thinks it has solid boosters the instant they run dry and never stages. Anyway, I suppose a slightly wordier alternative script will fix the problem. EDIT: I did indeed fix the staging issue by making it do the fuelType check just before the main UNTIL loop and making it only change fuelType again after staging. Of course, now my ascent autopilot is over 3000 bytes. I suppose one way to shrink a program is to split it into separate programs to function as modules to do repetitive code.
  4. I've been playing KSP for a while now, and I decided to try out kOS after attempting to land a probe on Ike with RemoteTech's signal delay. (I did manage to touch down minus an engine after some F5/F9 spam, but that's beside the point.) I've spent the past few days constructing and tweaking some (extremely novice) scripts to carry a probe from takeoff, to orbit, to reentry, and to landing on Kerbin. I was bustling with questions when I started with kOS, but I decided to try to find answers to all of them on my own instead of pestering the forum. However, I've unfortunately run into a few dead ends that are stymieing my progress toward creating a full catalog of autopilots. Hopefully this post isn't too much of a wall of text. 1. What is the simplest way for a landing script to detect whether the surface beneath is land or water? I've noticed that both Kerbal Engineer and the IVA instruments report the radar altitude as being below sea level if water is beneath the craft. This is an example of how I've been doing it so far: IF ALTITUDE > ALT:RADAR { SET altFlag TO 1. WAIT UNTIL ALTITUDE < 400. } ELSE { SET altFlag TO 2. WAIT UNTIL ALT:RADAR < 400. }. UNTIL altFlag = 3 { IF altFlag = 1 AND ALTITUDE < 15 AND VERTICALSPEED > -1 AND VERTICALSPEED < 1 { SET altFlag TO 3. }. IF altFlag = 2 AND ALT:RADAR < 15 AND VERTICALSPEED > -1 AND VERTICALSPEED < 1 { SET altFlag TO 3. }. WAIT 0.001. }. However, I get the feeling that the usage of variables as arbitrary flags is not a best coding practice, and every character typed further strains storage space. Is there a more concise method to doing this landing procedure? 2. My scripts seem to have a real problem with throttle control. Unless I put "SET CONFIG:SAFE TO FALSE." somewhere in the script, I inevitably get an error message about a value being NaN. This is probably something that can be worked around with the correct logic, although I'm not sure how to set it up. This is one of the bits of code that is causing the error: IF vesselAcceleration > 0 AND vesselAcceleration < 18 AND throttleValue < 1 { SET throttleValue TO throttleValue + 0.01. }. IF vesselAcceleration > 0 AND vesselAcceleration > 18 AND throttleValue > 0.01 { SET throttleValue TO throttleValue - 0.01. I assume the issue is being caused by "throttleValue + 0.01" equaling a number greater than 1 at some points. Is there a way to avoid the issue without disabling CONFIG:SAFE or preventing the craft from using the entire range of throttle? 3. I have a script that is set up to detect the types of fuel that are present on a vessel for the purposes of staging when out of fuel. This is in an attempt to make a more general "takeoff and enter orbit" script instead of needing one that is specifically tailored for each vessel. However, the method I am using simply refuses to work. This is the relevant snippet of code: SET fuelType TO 0. // 0 = none, 1 = solid, 2 = liquid, 3 = both UNTIL APOAPSIS >= targetAltitude { IF STAGE:SOLIDFUEL < 0.02 AND (fuelType = 1 OR fuelType = 3){ PRINT "No solid fuel. Attempting to stage.". STAGE. }. IF STAGE:LIQUIDFUEL < 0.02 AND (fuelType = 2 OR fuelType = 3){ PRINT "No liquid fuel. Attempting to stage.". STAGE. }. IF STAGE:SOLIDFUEL > 0 AND STAGE:LIQUIDFUEL = 0 { SET fuelType TO 1. }. IF STAGE:SOLIDFUEL = 0 AND STAGE:LIQUIDFUEL > 0 { SET fuelType TO 2. }. IF STAGE:SOLIDFUEL > 0 AND STAGE:LIQUIDFUEL > 0 { SET fuelType TO 3. }. WAIT 0.001. }. The "fuelType" variable works as intended - it changes to the correct value when a type of fuel runs dry. However, the IF statements that contain the STAGE function never trigger. I've tried several variants of this, including using "NOT fuelType = 2" or "fuelType <> 2" for the solid fuel section. I've also tried moving the part that sets the value of "fuelType" to the top of the loop. Nothing seems to work. However, if I remove the "fuelType" requirements, the stages trigger, as do the print messages. Previously, I'd been using an arbitrary flag value to control when each type of fuel should have its quantity checked, but I would really like to have a script that requires less modification to transfer between vessels. 4. How do I prevent WHEN statements from interrupting other commands? When I discovered that WHEN statements stop and never resume UNTIL and WAIT UNTIL statements, I started to avoid using WHEN as much as possible. This leads to some repetitive code, which I would also like to avoid - sometimes, I need the same constant condition check for multiple UNTIL loops in a script, like being able to stage both during ascent and during orbital maneuvers. I understand that Kerboscript is not truly multithreaded and instead can only process one action at a time, but it seems odd how it breaks other loops entirely. For example, if I have "WAIT UNTIL maneuverNode:BURNVECTOR:MAG < 0.5." running to determine when to cut the throttle during a burn, and then a WHEN statement triggers before it's done, the program will just instantly end as soon as the WHEN loop is over. I would greatly appreciate any help with these matters.
×
×
  • Create New...