Space Engineers

Space Engineers

67 ratings
JRGD-Jerry Rigged Torque Canceling Gravity Drive
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
15.836 KB
24 Mar, 2017 @ 4:04pm
10 Jun, 2018 @ 3:03pm
25 Change Notes ( view )

Subscribe to download
JRGD-Jerry Rigged Torque Canceling Gravity Drive

Description
Gravity drives have always been the most powerful form of propulsion, but they were very unwieldy because they generated massive amounts of torque, an issue this script addresses with complex physics calculations. A 5x5 gravity drive can be the equivalent of 53 large hydrogen thrusters in each direction. A 7x7 drive will be the equivalent of 613 large hydrogen thrusters. Slap the gravity drives anywhere. (exercise common sense.) Put the center of mass anywhere. It is strongly recommended to have 3 or more but you can place as many as you like and the script takes over. With this script mitigating most if not all torque, ships can now soar to new heights! (and speeds)

While this can be similar to other alternatives, JRGD differs in that it requires no gyro override and works with the gravity drives alone. Using complex physics calculations, the drives themselves thrust in all six different directions such that the combination of forces result in a final net acceleration vector in the same direction the player commands it, all the while canceling out each others torque perfectly. As a matter of fact, with three or more gravity drives, you won't even need gyros anymore! The gravity drives act as "gravity gyros" and rotate the ship! Only one gyro would be needed to help the ship stop spinning properly (because the API for moment of inertia is inaccessible). For those who played KSP, these are basically over-powered RCS thrusters.

I've gone ahead and changed a few things so this script now plays well with sim speed! That should solve most if not all lag issues anyone is having with the script!

Example ship 1: Red 1 GravDrive Retrofit
Example ship 2: Newtonian Heavy Frigate

Advanced guide on gravDrives: http://steamproxy.net/sharedfiles/filedetails/?id=906541569
Clang Drive: http://steamproxy.net/sharedfiles/filedetails/?id=910527327
Backup computer banks script if you have a weak bridge: Backup Computer Banks Script

Update 6/8/18
-A timer block is no longer needed. This script will run on its own. Make sure to remove old timers.
-Optimizations!! See if it runs a little better now :) if not, I'll see what else I can do. This script should not have much impact on your sim speed anymore! :D
-CONTROL SEAT AUTHORITY NOW NO LONGER AUTO UPDATE every frame as part of the optimizations
-See the "authorize" command for more

Update 10/8/17
-Adding a + or - infront of a deciaml as an argument will now increase or decrease the output level by the corrosponding amount.
-Fixed gravity field auto config, courtesy of @DifferentLevelDan

Torque cancellation modes:
Based on the number of available drives, the algorithm prioritizes on different goals.
1 gravity drive: Prioritizes movement. Torque cancellation is not available.
2 gravity drives: Prioritizes movement. As much torque is canceled as possible.
3+ gravity drives: Prioritizes zero torque. As much translation force is added as possible. In addition, the drives can now act as gyros, making gyros blocks essentially useless.
Because it is prohibitively expensive on performance to solve for the local maximum of a system of 9+ dimensional equations (as is the case most of the time), the algorithm strikes a balance between counter torquing and pushing.

Special thanks to @taleden for LCD formatting code used in his TIM script.
Credit to @BurninSun for the automatic gravity field size adjustment.

Preparations:
1. When modifying or starting the scipt, always disconnect the ship from any other docked
ships that have gravity drives. (or else it will take over all gravity drives it finds.)
2. Make sure there is atleast one thruster on board. Direction does not matter. (To make sure the dampeners are updated in the code)
3. Make sure there is atleast one gyro on board. (To make sure the ship stops spinning completely)
3. Make sure there is atleast one ship controller. (duh)
4. Make sure each gravity drive is well out of reach of one another. Cleaning up after overlapping gravity fields is NOT be fun. (duh)

Setup:
1. Group individual gravity drives into block groups. NAME THE GROUPS SOMETHING UNIQUE TO THIS SHIP. Put "[GD]" anywhere in the name. The gravity generator field sizes do not have to be configured. It is automatically set.
2. Add a programming block and a timer. Set the timer to 1 second.
3. Copy and paste in this script.
4. Setup actions in the timer block as “Trigger Now” -> Run this script with empty arguments -> “Start"
5. In your ships toolbar, add this script with the arguments "start" and "stop". You will thank me when your ship runs away.
6. Start the timer and RUN as fast as possible to a control seat. If the ship doesn't fly away, you're good. If it did, run the argument "stop" on the toolbar. If the ship hits anything, you made a backup. In all seriousness though, it should be fine. I have test the script quite thoroughly and so far no rapid unplanned deconstruction yet.
7. Profit!?

Arguments:
authorize - Rescans for control seat authorization.
refresh - Refreshs the scipts list of graivty drives. Disconnect the ship to all docked
ships with gravity drives before doing so.
stop - Turn off the gravity drive.
start - Turn on the gravity drive.
gyro_on - Enable gravity gyro
gyro_off - Disable gravity gyro

Passing a number or a decimal between 0.01 and 1 will now scale the power output of the drives. (Dampeners not effected) 0.01 means that only 1% of power will be used. 1 means that all power will be used. This is useful for docking.

LCD Status Summery Screen:
Any LCDs with the [JRGD] tag will be used to display various info on the operation of the gravity drives. For now, this includes a nicely formatted list of all drives, their current output, combined output, torque output, and certain settings of the script.

Status lights:
Any lights with the [JRGD] tag will be seen as status lights.
Green -> Gravity Drives are fully functional.
Yellow -> Graivty drives are funtional but there are some torque the script cannot cancel
Red -> Gravity drives are unable work or is turned off.

Additional usage notes:
*You can add the [JRGD] tag to a controller to make sure that controller takes precedence over all others. You most likely want to put this on the main cockpit if you have one. This can come in handy on multicrew ships in multiplayer. The API for checking for main cockpit is broken so this is the only way.
*If your ship does not fully stop with inertial dempeners on, check the control sensitivity settings bellow.
*Yes, you can dock with any other ship as long as it is setup correctly.

Gravity Drive setup tips:
Because this script works directly with the gravity drive by counter thrusting...
1 will be unstable.
2 will be manageable.
3 or above will be rock solid.
For effective placements of drives, make sure they are spread far apart and spread evenly. Make sure no three drives are in the same line as each other. Though it is not a requirement, try to keep the center of mass of the ship inside the cluster of drives. This will ensure better performance of the drives.

Incompatibilities:
This script is incompatible with any of the following.
1. Gravity drives with no gravity generators in one or more axis.
2. Space Engineers.

TODO:
* Add automatic natural gravity cancellation around moons.
* Make code bullet proof & clean up this mess.
151 Comments
DMMWolf 22 Aug, 2022 @ 3:24am 
This script is incompatible with any of the following.
1. Gravity drives with no gravity generators in one or more axis.
***2. Space Engineers.***

I Love how non specific this is!

It can just as easily mean Space Engineers the game as it does the people Building the ships!
Jerry  [author] 19 Jul, 2022 @ 2:54pm 
I don't recall using anything of that sort. You have perfect information on the ship. You just solve for how much force and in what direction each drive should apply to give you the correct force and torque at the same time.
IchBinUnoriginelWasNamenAngeht 17 Jul, 2022 @ 3:10pm 
When cancelling out the torque how is that done? Because to cancel to torque out you need to apply a force to generate a constant counter-torque. Do you use a controller like PT2 or I?
Mata52 31 May, 2022 @ 2:25am 
A note to my last comment and request for help: with further tests I can confirm it is only related to design matters. For some reason 3 grav drives do not work with certain designs. I have no clue what exactly the obstacle is, though. Definitely not the mass itself, however. Maybe the shape, size, number of blocks, location of the center of mass or something else.
Mata52 29 May, 2022 @ 5:30am 
I realise that this script is not going to be updated anymore by Jerry, however, I have an issue that maybe even somebody else will be able to help me with. For some reason when I build 3 grav drives on my ships they do not work in the up & down axis. When I press space and c (thrusters do work normally) the artificial masses do not even get turned on. The script does not seem to even want to assist my flight when I want to fly downwards and upwards. It works perfectly tho in any other direction and also its gyroscopic function seems to work correctly

I put those 3 drives in a triangular pattern. My ship is triangular itself and basically I have one drive (3x3) in the middle of the front of the ship and also 2 drives in the back of the ship spread from each other. I tried comparing my construction with one of the Jerry's examples (the red ship, whose grav drives work perfectly fine even up to this date). I have no idea what can be the cause and I would be glad to see any advice.
Jeff 28 Jan, 2022 @ 11:39am 
My Ship still speeds up in i think 1 direction
ShadedMJ 14 Apr, 2021 @ 2:03pm 
@Jerry : Script is _not_ broken. Only deprecated code.

// Lines 945-946 are
panel.WritePublicText(before + sf.ToString(width) + after, false);
panel.ShowPublicTextOnScreen();
// but should be
panel.WriteText(before + sf.ToString(width) + after, false);
panel.ContentType=VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
Jerry  [author] 28 Feb, 2021 @ 1:20am 
I don't expect to have time to update this script anytime in the future.

Feel free to use any part of my old code as long as credit is acknowledged. Just put my name under an asterisk in the workshop page or something.

That said, I wrote this in high school and I’m in grad school now so a lot of the math could really be made much more rigorous. I won’t be implementing anything, but I can describe a better and more accurate algorithm for anyone interested.


Chuck 26 Feb, 2021 @ 8:49am 
@Venator Here is a link to a working script that replicates most of the functions. On the downside, it doesn't do torque cancelling, so you will have to build the drive around the center of mass. Torque cancelling is planned for the future, according to the page.

https://steamproxy.net/sharedfiles/filedetails/?id=1878739837
Venator 6 Jan, 2021 @ 10:16pm 
is this being fixed/updated anymore?