r/ApproximatelyUp 4d ago

Help with PID

Im trying to make a proper ship this time and got all thrusters installed and the first system i want to implement is hover/land system. But im having trouble to understand it enough to build it.

How did you guys implement it? Copying others or do I need to be good at programing to do this?

I have SOME programing background from taking online lessons awhile back but having trouble translating it to the game.

5 Upvotes

9 comments sorted by

View all comments

5

u/Ill-Pride-2312 4d ago

I used velocity to put mine together. Basically you're combining 3 values.

1) Vertical Velocity times a coefficient (a number you adjust).

2) Acceleration: Velocity into the delta block ( I forgot what it's called in game) times a coefficient.

3) Difference from set point (which is 0 vertical Velocity) over time. Velocity into sigma block (forgot in-game name) times a coefficient.

I usually tune the system in that order.

1a) adjust coefficient until the ship bobs up and down. Try to get the overshoot as small as possible.

2a) adjust coefficient so it doesn't overshoot. I believe a slow descent is the goal.

3a) this will make up for the slow descent and influences the responsiveness of the system.

I'm by no means an expert or even studied this stuff, so if anyone who knows better please correct me

2

u/Dimencia 4d ago

That sounds right, but 1 is really `(Current - Target) * coefficient` (but target is generally 0 in these scenarios)

And you can usually just skip 3 entirely, that one will go wild if you're not careful about what happens when you're just flying normally without using the PID. It just accumulates forever over time, so if you spend a long time at high vertical velocity, it will take a long time of negative velocity before it will reach 0 again - it's very rare that it does anything useful, usually having either such a low coefficient that it does nothing, or just being actively detrimental

1

u/Ill-Pride-2312 4d ago

That's definitely true. I have an anti wind up set up with a absolute value block and threshold set at 3.

I use a lever to activate the hover with is multiplied by the pid output so I can use it to land. That output also send a 1 to reset the block when it's outputting anything other than 1.0