Jump to content

PEGAS - Powered Explicit Guidance Ascent System - devlog


Reddy

Recommended Posts

OK so I started messing around with a kOSDelegate function to try and keep a constant acceleration.  I tried adding the function declaration and an event to call it in the SEQUENCE part of the boot file for the craft, but this just gives me a message about a dead delegate.

I think I understand why (it's out of scope after the craft is loaded during boot) but... where do I put the function declaration and the instruction to add it into the sequence?

Link to comment
Share on other sites

On 1/19/2023 at 7:05 AM, Kurld said:

Well I messed around with setting up a pitch program this morning.  Maybe I don't really understand "gravity turn" but in no case have I been able to hand things over to active guidance and not have it pitch up to nearly vertical and reset throttle to 100%.  This results in the apo being 600 to 700km on a planned 115 km flight path (remember I am in vanilla KSP.)  At the handoff I am somewhere around 60km altitude and nearly horizontal with a predicted APO of about 90km  I can't recall what my velocity was but I'm guessing the algorithm must feel it is much too low to continue on to the planned orbit.

I also made PEGAS crash.  If it gets to the end of the pitch program before handing over, it blows up with another index out of bounds error.  I'll try to make a more full report on github after work.
 

To be honest, PEGAS isn't actually particularly well suited for stock KSP, as it can't do a coast. Stock rockets generally have fairly high TWR, which when combined with the Earth-like atmospheric density and the relatively low orbital velocity, often makes a coast to apoapsis the best ascent path. The RP-1 wiki actually has a section on MechJeb's PVG, which is a similar algorithm to PEGAS (though it can incorporate a coast) and it explains a bit why the rocket it doing what it is: https://github.com/KSP-RO/RP-0/wiki/TroubleshootingMechJebPVG#my-rocket-is-burning-down-not-a-problem

You could probably fudge it a little bit by either setting a pretty low g-limiter in PEGAS, or actually set the throttle limiter on the engine to a lower value, just don't forget to tell PEGAS what the maximum limited throttle is.

Link to comment
Share on other sites

22 hours ago, Razgriz1 said:

The RP-1 wiki actually has a section on MechJeb's PVG, which is a similar algorithm to PEGAS (though it can incorporate a coast) and it explains a bit why the rocket it doing what it is: https://github.com/KSP-RO/RP-0/wiki/TroubleshootingMechJebPVG#my-rocket-is-burning-down-not-a-problem

Thanks, lots of material to digest there.
 

Link to comment
Share on other sites

  • 1 month later...

Some errors you've encountered have been fixed (e.g. the one @asdasdgf pointed out). If PEGAS behaves weirdly, always check github for the freshest code - I sometimes push fixes which can only be grabbed if you download the code directly (i.e. not as a release). The plan is to fix several outstanding problems and package them as a v1.3.1 in the near future.

I'm aware of the pitch program "issue" you mention @Kurld, but haven't yed decided whether that's a bug or a feature (and it should be the user's job to specify proper control points). Perhaps it would be nicer if the script didn't crash...

As to tuning PEGAS to vanilla atmosphere - I don't have a clue; haven't played vanilla in over 6 years, don't remember how the atmosphere looks. But @Razgriz1 is right: surprisingly, you will likely have a harder time launching in vanilla than in RO. The idea to set the engine thrust limiter is good, just remember to change the thrust value in your vehicle configuration accordingly.

If you spot any other problems, please do keep updating me via github or this thread (I've fixed the email notifications for the forum which I haven't previously been receiving) :)

Link to comment
Share on other sites

@Reddy  I wound up punting on the stock-size system and have been playing 2.5x   Things are a lot more balanced as to performance in that it actually takes most of the big orange tank to get into orbit, etc.  I haven't loaded up kOS or PEGAS yet, as the ascent guidance in MJ seems to work well enough there.  I do intend to get back to it at some point becuase there is some other stuff I want to try to use kOS to automate, and MJ has it's own set of challenges.

Link to comment
Share on other sites

I have "fixed" the pitch program issue. The problem was that PEGAS crashed when altitude exceeded the final keypoint in your pitch program. I say "fix" not fix, because I made it no longer crash in this situation, but emit a critical error instead - your flight will probably still be doomed. You should never allow this situation to happen, and in order to help people understand why, I added this extra bit of documentation. Give me a thumb up if this makes sense.

Link to comment
Share on other sites

  • 7 months later...
On 2/24/2023 at 9:33 AM, Reddy said:

 But @Razgriz1 is right: surprisingly, you will likely have a harder time launching in vanilla than in RO.

PEG assumes a flat linear gravity model and then tries to correct for that, which works for Earth, but Kerbin is made of some substance that is 1,000x denser than Earth so that a 600km ball has a gravity of 1g, which means that space is more curved, which means PEG doesn't work as well.

Plus the delta-V requirements to orbit are lower while the high-TWR rockets that people build will cause burntimes to hit that delta-V to be much lower which mandates a coast, and the coast needs to be placed somewhat optimally.

At some point I want to wrap PVG with a SQP solver that marries a zero-lift gravity turn with PVG on the "top" for insertion into the orbit, along with supporting a single optimal stage at an arbitrary time (rather than just at stage jettison) which would solve a lot of these problems.

Link to comment
Share on other sites

  • 4 months later...

Hello, hope it isn't frowned upon to necro this old thread - but I have some questions that I consider relevant.

So, in the interest of farming contracts in my JSNQ (2.7x scale) playthrough, I've been developing ascent guidance algorithms. I have implemented the guidance algorithm outlined in Teren (1966) with some simplifications (I keep seeing this referred to as Linear Tangent Guidance, but is that the correct name for this scheme?), allowing me to launch into an orbit with specified eccentricity, apsis, and argument of periapse. The yaw control in Teren (1966) however doesn't allow precise control over the orbital plane and as such I have been working on my own implementation of UPFG. The work outlined in Noiredd's GitHub has been of great value and my main loop is basically a copy of his work. I did add a method for controlling the argument of periapse:
 

  • After establishing the projected burnout position rp, we project it onto the plane defined by iy. Basically a vector-exlude.
  • We find the true anomaly of rp. This is done using a vector angle (and sign check!) of a vector pointing towards desired periapse and rp
  • The desired velocity and position vd and rd are then updated, to reflect the desired velocity and position of the desired orbit at burnout conditions.

The cutoff criterion is to watch for the desired magnitude of orbital velocity to be reached.

image.png

Generally, this works. Injection takes place at the desired altitude, however, I've noticed that the radial (vertical) velocity is nearly always off. Is this a 'feature' of UPFG? My implementation of Teren's algorithm seemed to handle this quite well, even with some gross simplifications in estimates of T-to-go and burnout position (both do converge to correct values near the end of the burn). See attached a screenshot of my console - and note that while most parameters do match the desired values quite closely, the vertical velocity (vr) is off and this causes a slight deviation in apses as well as a 15 degree shift in the argument of periapse.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...