Space Engineers

Space Engineers

296 ratings
Gravity Aligner
3
2
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
432.288 KB
Dec 2, 2015 @ 9:38pm
Apr 29 @ 8:50pm
27 Change Notes ( view )

Subscribe to download
Gravity Aligner

In 1 collection by p3st|cIdE
Scripts
13 items
Description
A stripped down version of Hover Altitude Aligner!

or a bells-and-whistles version of Leveller?! lol

Are you tired of crashing ships on planets because you weren't paying attention to the alignment as you cruised around and slewed into the ground? This is the script for you! It automatically aligns a ship with the local gravity using gyro overrides. When it detects it's going out of alignment, brings it back into alignment, and shuts off the overrides. It can effectively make a ship yaw-only, or just limit the angle of how much roll and pitch is allowed relative to flat orientation. It effectively turns a spacecraft into an imprecise orbiter. Folks have even been abusing it to keep mechs from falling over!

The main thing it does is prevent a vehicle from flipping over or even tilting too much. I made it because some of my ships were never designed to fly sideways or upside down and will definitely crash when put into those alignments, I got tired of having to manually orient the ship constantly to correct accumulated roll and REALLY got tired of crashing expensive space ships due to negligent piloting.

All it needs is a programmable block (for the script), a cockpit (to discover gravity vector and vehicle orientation; a remote control block will work if manual steering isn't required), some gyros (any orientation), and optional text panel(s) for diagnostic info. Ensure all blocks have access to each other/same owner. Then make a new group in the terminal called "Aligner" and include ALL those blocks. Then Run the programmable block with argument "go" and watch it line up. Just try to flip the ship over, I dare you!

To disable the aligner, just run it with an argument of "stop" (case insensitive). It will ignore further runs for .1 seconds just in case and turn off the text display. "toggle" is convenient for toolbar binding.

The text panel diagnostics will tell you if you're missing a block or some other critical setup error. So far it outputs to the public text the present ship pitch and roll angle in degrees, blinks red when it's aligning, has pretty angle graphs.
Angle graphs go best on corner panels, put into LCD public title "pitch", "yaw", "roll", "steer", "logo", "gravity", "update", a few others slip my mind...

I find it easiest to steer with the keyboard arrow keys. Hey, it even supports the new player input access for true gravity-relative yaw control!

You will definitely want to tune the parameters (RollAngleClipDegrees, PitchAngleClipDegrees etc..) in the CustomData for your ship, but do be careful and make a backup copy of your ship first, I can take no responsibility if you manage to make the thing freak out and crash by tweaking wrong parameters, but the defaults should do ok for most uses. If you need help tuning the parameters, let me know. Often the settings will get cleared or reset mysteriously, so once you find settings you like, it's best to edit the script to make those the new defaults.

It only uses blocks in the group, so you can exclude some gyros for other purposes.

If you would like to see this script working in-game without having to build a ship and set it up, I have some ship blueprints uploaded that already have it installed. Try VixS. Can find more by browsing my recent Workshop submissions. Some old versions are Drilldown, or Flitter, both good examples without mods. Also Overlook scout ship. Some may be using old versions of the script though; my earliest attempts aren't as nice with the response at the limits and did block setup differently, can't handle arbitrary remote orientations. Some include airlock logic!

It's a fairly cpu-friendly script since even though it gets run every frame, most of the script can be skipped if enough time hasn't elapsed and the block searching initialization only runs every 5 seconds and main control logic presently only runs 30x per second by default which is plenty good enough for most ships. Try reducing updatefrequency and disable the text panel to reduce server load on multiplayer.

NOTE: it still depends on inertial dampeners and upward thrusters to keep the vehicle in the air. AND you can totally still crash the ship! It merely assists maintaining alignment.

TROUBLESHOOTING

There's no shortage of problems with a script like this which basically remote-controls the ship.

Ensure block ownership. Permission issues can prevent scripts from manipulating blocks etc. It does check for this now. This is the most common source of error.

If it doesn't seem to be doing anything, did you give it the "go" command? Check the programmable block to see if it threw an exception.. If there's no text panel more exceptions might happen. Try with lcd first, you can remove when it works.

If it won't correct at all, make sure you can actually steer the ship manually (have enough active gyros to move it?)
If you see no debug output on your text panel, make sure you own it and then set to show public text. Is it in the group?

If it seems too stiff and jerky and won't let you steer, try loosening up the angle limits or speed factor in the script parameters. Group a cockpit, not a RC.

If it takes too long to correct, turn up the AlignAngularResponseP or increase the OrientPredict time.

If it never actually gets to the limit and keeps correcting forever, preventing you from steering, try increasing AlignAngularResponseP.

If it overcorrects too far past the boundary limit, or oscillates a lot, won't settle into a small limit window, try increasing OrientPredict time or decreasing AlignAngularResponseP, or increasing AlignAngularResponseD.

Try turning up AlignAngularResponseD especially if it's a huge ship, to prevent gaining excessive velocity.

If you get CLR Detected Invalid Program errors, try installing the latest .NET runtime (4.6.1 reportedly works!) I still haven't figured out the cause.

Dislike cockpit LCD? comment out // line of code: Surfs.Add(ctrl.GetSurface(1));
or is it: chart.Show(ctrlb.GetSurface(1));

KNOWN BUGS

Can reset CustomData config settings to defaults sometimes, on some ship designs, on server load - make a backup!

LCD panels often show the wrong chart; chart configuration doesn't work right anymore.
1,003 Comments
p3st|cIdE  [author] Apr 29 @ 8:30pm 
@PimpMyDog looking at it now; are you sure? From what I can tell, it never filtered the UpdateType argument in Main... so it should just work. If Keen's end of it works, anyway, which is always iffy.
PimpMyDog Apr 27 @ 5:31pm 
Thanks! Yeah the new update seems quite interesting.
p3st|cIdE  [author] Apr 27 @ 5:24pm 
Sure, I could do that. I never thought anyone would use that updateType...
Probably will play a bit on this upcoming update, can work on it then.
PimpMyDog Apr 27 @ 5:13pm 
I have the improved code, let me know if you want
PimpMyDog Apr 27 @ 4:56pm 
Would it be too much to ask if you could make it listen to script updateType commands also? Currently you can only send commands through terminal or button but not from another script.
p3st|cIdE  [author] Apr 26 @ 3:45pm 
I suggest increasing AlignAngularResponseP in PB CustomData (then run "load")
tuning GyroStoppability might help. If it's smallgrid you can maybe increase the RPM limit. There are many settings to fiddle with.
OMEGA Apr 26 @ 3:06pm 
one last question what can i do to make the pitch correction stronger
p3st|cIdE  [author] Apr 26 @ 2:41pm 
@OMEGA this script only uses the gyros in the Aligner group, so whatever blocks you include/exclude.
OMEGA Apr 26 @ 2:31pm 
can i make this exclude certain gyros
WarArk [VL] Apr 20 @ 2:18pm 
Thx