NanobyteTrainee Engineer
- Messages:
- 25
Does anybody have any clue on how to approach this?
Nanobyte,Nov 15, 2015
#1
plaYer2kMaster Engineer
- Messages:
- 3,160
sure, here is a suggestion for how to approach it
- get the natural gravity through a remote
- get all gyros you want to use in order to turn
- get the current orientation so you can compute the angular offset from current to ideal orientation
- transform the orientation offset to all gyros to turn them in that direction
- optionally apply some smooth magic like PID or other dynamic meassure system to guess the moment of inertia tensor in order to build a simple physics model
plaYer2k,Nov 16, 2015
#2
NanobyteTrainee Engineer
- Messages:
- 25
Thanks player, i like a coding challenge so ill start with the above, and if that causes me too much headaches ill continue with the last option
Nanobyte,Nov 16, 2015
#3
plaYer2kMaster Engineer
- Messages:
- 3,160
Sure that. Also if you got issues at one of the steps, dont hestitate to ask for help.
For months now i was too busy/lazy to do the "orient gyro towards point" now but i will need it too soon. I will also need to code that myself because i dont like most of the implementations i have seen.
So i dont know all the answers myself but "the community" as a whole does. Not that the tast is particularly hard but i simply didnt bother doing it yetGood luck and enjoy the tinkering.
plaYer2k,Nov 16, 2015
#4
NanobyteTrainee Engineer
- Messages:
- 25
Ok i will keep you updated on anything that works out the way it should, im currently trying to align my vehicles down vector with the data from GetNaturalGravity()
But im not sure if that vector even is a normal direction vector. Its been a long since i've done vector math so im a little rusty on that endNanobyte,Nov 16, 2015
#5
HarrekinMaster Engineer
- Messages:
- 3,077
Vector from ship to centre of planet.
Vector of ships direction of travel.Get dot product and adjust gyros to keep it as close to zero as possible.
Harrekin,Nov 16, 2015
#6
plaYer2kMaster Engineer
- Messages:
- 3,160
But what is a one-dimensional value worth when you got three dimensions to rotate in
So no it aint that simple, but it aint much worse than that too.plaYer2k,Nov 16, 2015
#7
NanobyteTrainee Engineer
- Messages:
- 25
I'm stumped at the moment, i think im getting confused by the gyro itself. Not sure if i'll be able to break this one
Nanobyte,Nov 16, 2015
#8
Youre only looking to maintain a right angle from the ship to the centre of the planet tho so only two options, no?
Harrekin,Nov 16, 2015
#9
plaYer2kMaster Engineer
- Messages:
- 3,160
Yeah but in which direction is important aswell. What is a value of 0.3 worth when you dont know around which of the three axis the gyros have to turn around? Would you want to define that in a fixed manner for every program and physical setup you got?
Instead the car needs to have a defined orientation. Transforming the gravity vector through the inverted orientation matrix gives a local gravity vector. With that local vector you can then form the parameters for rotations around that anchor block. Things like PID come to mind there.
Now that you got your rotational parameters you can transform these to the local orientation of each gyro to kill their three rotational parameters aswell as power as optional parameter.plaYer2k,Nov 16, 2015
#10
NaosythTrainee Engineer
- Messages:
- 9
I actually programmed something really similar yesterday. I can share my code when I get home from work in a few hours. I determine my roll and pitch using my forward and right vectors in relation to the gravity vector. I then use a PID controller to adjust my pitch and roll to bring my ship to a stop, using a helicopter-like flight model.
Naosyth,Nov 16, 2015
#11
AutoMcDSenior Engineer
- Messages:
- 2,369
I have a somewhat related idea that maybe you can include:
To automatically enable/disable UP thrusters so that the ship thrust/weight Going upwards matches the side thruster performance, after factoring in weight and gravity.This would make something with a LOT of cargo lifting capacity much more predictable to fly.
AutoMcD,Nov 16, 2015
#12
NanobyteTrainee Engineer
- Messages:
- 25
Sounds cool Naosyth, if you wouldn't mind sharing, i am still bumping into things to try and figure out how to get it working correctly
Nanobyte,Nov 16, 2015
#13
JoeTheDestroyerJunior Engineer
- Messages:
- 573
Threw this together, seems to work reasonably well:
Just have a timer running the PB and "trigger now"-ing itself. It's setup to align based on the remote control block. (If you have more than one, it will take the first one it finds.) If you want to use a different reference, just changing how "down" is assigned should be enough (down is in grid-local coordinates).By default it will use all the gyros it can find (well, 999). This works best if you don't need any steering. If you need steering try setting the limit lower, then the script will allow you to pitch/roll but will slowly correct it (yaw should be unaffected.)
Last edited: Nov 17, 2015
JoeTheDestroyer,Nov 17, 2015
#14
- Like x 3
NanobyteTrainee Engineer
- Messages:
- 25
I will not need the steering, i just want to make a drone that is able to achieve the above, but i keep having the feeling that im either getting the wrong values, or that i keep doing something wrong in the math
Nanobyte,Nov 17, 2015
#15
NanobyteTrainee Engineer
- Messages:
- 25
Derp, i didnt notice you input code at first, thanks! ill play around with this tomorrow see if i can achieve what i like, im sure it will teach me multiple things
Nanobyte,Nov 17, 2015
#16
NanobyteTrainee Engineer
- Messages:
- 25
Joe thank you very much for sharing ! This does exactly what i was trying to achieve, and i learned that the way i approached it especially the gyro part is what held me back. You saved me a lot of headaches
Nanobyte,Nov 17, 2015
#17
AutoMcDSenior Engineer
- Messages:
- 2,369
Anyone have it shared on workshop?
AutoMcD,Nov 17, 2015
#18
JoeTheDestroyerJunior Engineer
- Messages:
- 573
No problem, I'm glad all that digging I did in the gyroscope code on github finally proved useful Not me, I don't bother much w/ the workshop.
If somebody else wants to clean it up and post it, that's fine by me.
JoeTheDestroyer,Nov 17, 2015
#19
AutoMcDSenior Engineer
- Messages:
- 2,369
Ok. Makes it easier to use in-game when you can paste it in straight off steam.
AutoMcD,Nov 17, 2015
#20
JoeTheDestroyerJunior Engineer
- Messages:
- 573
I keep all my scripts in the local scripts folder, they can be used the same way as from steam that way. (And I can edit them with Notepad++, rather than the awful in game editor.)
You can use the "Browse Workshop" -> "Create from editor" option to do this (after you paste the script into the editor the first time).
JoeTheDestroyer,Nov 17, 2015
#21
NaosythTrainee Engineer
- Messages:
- 9
I reworked my helicopter braking script a bit. It no longer uses a PID loop, just some math to determine angles and rotation rates. You can take a look at it here if you're curious how it works. It's my first Space Engineers program, so any feedback would be great. It takes a slightly different approach to aligning the ship with the planet's gravity, so maybe it will still be useful to you.
Naosyth,Nov 17, 2015
#22
JoeTheDestroyerJunior Engineer
- Messages:
- 573
This will give unexpected results when your simspeed drops (i.e. game time is slower than real time). If it weren't broken atm, you should use ElapsedTime. As it is, the only real choice is to run your script every tick (timer TriggerNow) so that dt=1000/60.Code:
long now = System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond;double dt = now - oldTime;
This isn't necessary anymore. Use the WorldMatrix property of blocks/grids to get a translation/orientation matrix, then the matrix Forward, Right, Up properties to get the directions you want.Code:
// Get orientation vectorsVector3 normalVec = Vector3.Normalize(remotePos - computerPos);Vector3 forwardVec = Vector3.Normalize(gyroPos - computerPos);Vector3 rightVec = Vector3.Normalize(timerPos - computerPos);
Code:
Vector3 gravityVec = Vector3.Multiply(Vector3.Normalize(Remote.GetNaturalGravity()), -1);
I'm not sure about your math, it looks like it just boils down to proportional control to me. But I maybe missing something.Code:
Vector3 gravityVec = -Vector3.Normalize(Remote.GetNaturalGravity());
The thing about gyros is that even though Keen says everywhere (UI, value names) that the 3 values are yaw, pitch, and roll, they really aren't. They are the X (pitch), Y (yaw) and Z (roll) axis of a rotation vector (well, a rotational velocity vector, really). When only one value is non-zero, then the two are equivalent. When the values are small, they are reasonable approximations of each other. But when the values are large, you will get odd behavior if you treat them as if they were truly yaw/pitch/roll.
JoeTheDestroyer,Nov 18, 2015
#23
- Informative x 1
NaosythTrainee Engineer
- Messages:
- 9
Yeah, I initially had a PID controller, but it wasn't working well, and proportional control just worked way better.I didn't consider the sim speed issue, definitely a good point.Ah, I was trying to figure that out, but didn't have much success. I'll take another look. Thanks!
Also, for the gyros, right now it only uses one gyro, which I knew the orientation of. I'm planning on making it work with all of the ship's gyros at some point, so I'll make it use the appropriate axis when I do so.
Edit: Got it working with all gyros now, and changing dt to just be 1000/60 made it much less jittery at low speeds. Overall it's working great, thanks for the feedback and advice
Last edited: Nov 18, 2015
Naosyth,Nov 18, 2015
#24
PsicoPatoSenior Engineer
- Messages:
- 1,097
You think this works with spawnships? I am planing to put this on my mod so my spawnships just orientate by themselfs right after spawning.
Another question. Do i need to set a loop on the Timer block to run the scrip time to time, or running it one time is enough?
PsicoPato,Nov 18, 2015
#25
JoeTheDestroyerJunior Engineer
- Messages:
- 573
So, yes. To expand, you need:
- 1 or more gyroscopes
- A remote control oriented so it's "down" face is pointed towards where you want the planet to be
- A programmable block w/ the script in it
- A timer set to:
- Run the programmable block (the argument doesn't matter, leave it blank)
- Do "TriggerNow" on the timer itself (setting up a loop)
Also, in this case I would recommend using the "LIMIT_GYROS" option (see the comment in the source) so that the player can still steer their ship, to some extent.
JoeTheDestroyer,Nov 18, 2015
#26
- Informative x 1
sepen_Trainee Engineer
- Messages:
- 52
Thanks a lot for this hint! I praise your source code digging dedication! Hah! PID is its very own can of worms, it really is.
sepen_,Nov 19, 2015
#27
- Like x 2
LynnuxJunior Engineer
- Messages:
- 881
Sorry, seeing this late.
Made a script some time ago (before planets): Avionics - Catlanding
In my Zecke vehicle I've added the usage of the gravity vector. Then the ship can be steered left/rigth and forward/backward while keeping the attitude. I'll update the script soon but first I want to know if I also have to add a speed limiter toggling the inertia dampeners and keeping the ship falling at a certain speed.Lynnux,Nov 20, 2015
#28
SibzApprentice Engineer
- Messages:
- 361
Could you explain what this is doing?
I think it changes the normalised vector into one that's relative to the current block. I.e. getting the green vector:
Did I understand this right?Sibz,Nov 22, 2015
#29
- Like x 1
- Informative x 1
JoeTheDestroyerJunior Engineer
- Messages:
- 573
Yep, that's it precisely. (Although your drawing says local grid, current block is actually the correct one.)
JoeTheDestroyer,Nov 22, 2015
#30
- Like x 2
FAQs
How to align to gravity in space engineers? ›
How to align blocks. Before placing a block, you see a ghost preview. At this point you can press (B key) to toggle between free placement mode, local-grid alignment mode, and gravity-aligned block placement, and you can rotate the block.
What does the shifting gravity do to the ship? ›Shifting weight horizontally, no matter where onboard it is, will always cause the ship's center of gravity to move in the same direction as the weight shift. NOTE: A weight shift causing the ship's center of gravity to move off centerline will always reduce the stability of the ship.
How do you get gravity on a spaceship? ›The only known way to create artificial gravity it to supply a force on an astronaut that produces the same acceleration as on the surface of earth: 9.8 meters/sec2 or 32 feet/sec2. This can be done with bungee chords, body restraints or by spinning the spacecraft fast enough to create enough centrifugal acceleration.
Does artificial gravity affect ships Space Engineers? ›Similarly, artificial gravity only affects mobile grids with Artificial Mass blocks. Always keep in mind that it isn't the ship itself, but its Artificial Mass that is affected by Artificial Gravity.
How fast does a ship have to spin to simulate gravity? ›An artificial gravity level of 0.1 g can be achieved by a reasonably low rotation rate (5 rpm) at radius as low as 4 m (see Figure 2-04). Likewise at a radius of 4 m, about 15 rpm would be required to produce Earth gravity at the feet (although gravity would be 50% less at the head), or 21 rpm to produce 2 g.
Where should the center of gravity be on a ship? ›A center of mass/gravity below the waterline ensures that buoyancy pushes the ship directly up and maintains equilibrium. IE: The ship's mast tilts, but buoyancy and the center of mass correct the alignment. A center of mass above the waterline would mean the ship is unstable and could tip over.
How could a ships center of gravity be altered to make it more unstable? ›The boats can be fitted with a styrofoam "deck." Placing a load on the deck raises the center of gravity above the center of buoyancy. The semicircular shaped hull becomes completely unstable in this situation and it is impossible to place even one 1-lb dumbbell on deck without the boat immediately capsizing.
How do you make gravity in space engineers? ›Gravity Generators are 1x1x1 blocks in size and exist for large grid only. Place it in the center of the intended area of effect. The block attaches to other blocks on the bottom side only and has one terminal on the front side. The block needs to be powered to function.
How to set up symmetry in space engineers? ›Using Symmetry Mode in Space Engineers
Get a block ready to place on the spaceship. Enable symmetry mode with its default hotkey (default: N) to get to work. Hit the symmetry mode hotkey (default: M) several times to cycle through the axes. Keep pressing it until you get to the right axis you want to mirror.
One of the realistic methods of creating artificial gravity is the centrifugal effect caused by the centripetal force of the floor of a rotating structure pushing up on the person. In that model, however, issues arise in the size of the spacecraft.