Juno: New Origins

Juno: New Origins

Not enough ratings
Simple Scripts
By Aloe
In this guide I share my extremely limited knowledge on rockets, programming, and math to create some simple scripts that you may want to use and adapt to your own needs. I will update this guide with some regularity and add new scripts as I discover them. Hope you enjoy!
   
Award
Favorite
Favorited
Unfavorite
Introduction
I am new to Juno, and know very little about rockets, rocketry, etc. I know programming somewhat well, though I know nothing about Vizzy or whatever the visual editor in this is called. Part of the reason I am making this guide is to document what I personally learn as a result of playing around with this curious game. I hope you find this guide useful, and that it helps you come up with your own ideas and implementations of various scripts and/or concepts in Juno.
Script - Maintain Thrust-To-Weight Ratio(TWR)
Keeping with the theme that I know very little about rockets, I heard that having the highest possible TWR is "inefficient" due to drag and other variables that I frankly can't remember. So, ideally I'd like to be able to automatically adjust my throttle to maintain a steady TWR during a burn. There's a few things to keep in mind if we want to do this "correctly":

1 - Our target TWR we wish to maintain
2 - The mass of the craft.
3 - The gravitational effect of a planet on our craft
4 - Our maximum thrust for the current stage
5 - The loss of mass over time (as we burn through fuel)

Regarding number 5, we don't have to think about it too much. All we're considering is the current mass of the craft, which will change as we burn through fuel, so I only mention it so we keep that in mind as we make our script.

Vizzy is new to me (this whole game is) but I think I get the gist of it. It's a visual programming tool, and it allows us to make some scripts. With this in mind, I realize that I'm probably not going to be making the most optimal scripts here. This is a "Simple Scripts" guide after all. Perhaps in the future I will make better, more detailed scripts.

First, I'll show you a screenshot of what it looks like, and then I'll go over the process and math behind it:


Simple, right? So what's going on here?
On start, we start the script.
We do a couple of display messages at 3 second intervals for no reason other than to pause for dramatic effect.
We set the throttle to 77%, no real reason just an arbitrary number (you can set this to 0 if you want.)
We activate the stage, wait 3 seconds, and then initialize a While(true) infinite loop. Bear in mind, that in this configuration this script will theoretically run forever, so there's no further logic to this script. You'll have to implement your own.

Now, the loop part of this, and the math. We want to maintain a certain TWR. I've created a custom variable called Target_TWR which takes in a float (decimal number) input. In my case I set it to 1.8 because I want to maintain a TWR of 1.8 throughout the entire burn. Obviously, if your craft cannot actually reach the target TWR, this will not work and your throttle will remain at 100% whilst attempting to reach the Target_TWR.
This loop has a single instruction, to set the throttle to a value. As such, this will continue to run and readjust the throttle every single frame (presumably). The value the throttle is being set to will ideally always be between 1 and 0. If the result of this operation is greater than 1, the throttle will default to 1, and if it is below 0, the throttle will default to 0.

Here's the simple math:
Throttle% = (Target_TWR * (CurrentMass * CurrentGravity)) / MaxThrust

Try it yourself and mess around with the Target_TWR variable. Set it to 1 if you wish to maintain a hover. Though, any added force or momentum carried over from any previous action will inevitably force the craft to continue moving. So it won't actually hover in this configuration. It'll just maintain whatever speed is achieved between stage activation and loop start.

In the near future, I will expand upon this simple script, and show you a practical application for it in Juno. I think my next simple script will be a simple hover script at a desired altitude ASL.

I hope this simple script helps you, and gives you some ideas as to what you can do with scripts like these.
Simple Hover v1
I decided to make a simple script that would make my craft hover at a desired altitude.
To do this, we require a few things:

1. A designated altitude to hover at
2. A craft capable of reaching said altitude
3. Adjustable rocket engines to perform a hover
4. A throttle script to maintain our TWR at 1 in order to hover.

If you didn't see my previous simple script, check it out, it has the simple math behind calculating the throttle percentage input need to achieve a desired TWR. So, number 4 is covered.

The next thing I wanted was to be able to set a desired hover altitude ASL, and allow everything else to be automatic-ish. So we'll need to create a custom variable that will represent our TargetAltitude.

Then, we need throttle up and launch our rocket, and we need to cutoff all engine thrust at the right moment such that when we reach our TargetAltitude we are moving at a vertical velocity of 0m/s (or as close as possible). Luckily, the game already does this for us by giving us our Apoapsis, which is exactly what we'll use to compare to our TargetAltitude.

Once we've reached our hover altitude, we need to throttle up and maintain a TWR of 1. At this point, our vertical velocity should be as close to 0m/s as possible.

Note: there are various factors which affect the velocity of the rocket in different directions, and different rockets with different characteristics and different components will behave, well, differently. So the actual hover altitude will not be the same as the TargetAltitude with this script. But it will be pretty close. Well within my own tolerance parameters.

Anyways, here's the script:


Very straight-forward. On start, we set throttle to 100%, lock heading up, and activate our first stage. Once our apoapsis matches our TargetAltitude we set throttle to 0. Then, when our craft's vertical velocity is below 2.5m/s we set our throttle % to an amount to maintain a TWR of 1 (that's the HoverThrottle expression).
Here's the basic math for that:
Throttle% = (Target_TWR * (CurrentMass * CurrentGravity)) / MaxThrust

And finally when our fuel reaches less than 50% we cutoff throttle again. This last bit is unnecessary for the hover itself, but I will keep this as is and later add logic to smoothly land the rocket back on the ground with the remaining fuel. Admittedly II think this fuel cutoff amount should be lower but for my tests this was just fine. The lower the fuel, the lower the mass, and the easier it will be to land the rocket (I think?)

Hope you enjoy, and I hope this helps.
4 Comments
Aloe  [author] 23 Mar, 2024 @ 10:26pm 
@mreed2
Right, I did just read that on a forum post a couple of days ago, I think from one of the devs, 3 years ago.
I might apply that to my scripts, I haven't really tested scenarios where the performance impact was noticeable at all, I've only tested single craft scenarios.
Also not sure if they have improved the implementation of Vizzy to just 'assume' the Wait 0 Seconds inside of infinite loops? But thank you for pointing it out, I will add a note on the guide to cover that!
mreed2 23 Mar, 2024 @ 9:43am 
One comment: If you are in a loop, and you want to perform some actions each physics frame, the "Wait 0 seconds" command will cause Vizzy execution to pause until the next physics frame.

While the way you are doing it does work, it requires more processor cycles -- potentially enough to noticeably reduce the frame rate.
Aloe  [author] 21 Mar, 2024 @ 5:50pm 
Thank you, I will look into it.
tonyiswrong 21 Mar, 2024 @ 2:28am 
This is a really well-written guide - unfortunately, it was immediately taken, run through a paraphrase program, and republished by known content-theft website RiotBits (https://www.riotbits.com/juno-new-origins-how-to-maintain-thrust-to-weight-ration-script-177115/) .

If you didn't give them permission, you can email them at '[email protected]' and tell them to take it down.