PID Controller for position

Please can someone help me?

http://stackoverflow.com/questions/41969363/c-sharp-pid-controller-for-distance

Have your setpoint be zero
have your input be the distance to setpoint
Kp will handle 95% of the control to land on setpoint
Ki will be set to zero because the setpoint is known and it is zero so no offset is needed
Kd start at zero and adjust after you get a good control with Kp Kd will help your device slow as it reaches the destination

The math looks good in your link or consider using the PID_v1 library
google “PID_v1 arduino github”

Z

zhomeslice:
Ki will be set to zero because the setpoint is known and it is zero so no offset is needed

That completely mis-represents the purpose and function of the I term. It has nothign whatsoever to do with whether the setpoint is known, and it not an offset. The I term produces and output that increases over time, which helps push the position to the setpoint, if it stops slightly off-position. In that scenario, the P term may not be large enough to cause an output large enough to induce motion. The D term will be doing nothing because the error is not changing at all, so the differential error is zero. The I term will cause the output to ramp up slowly over time, until it reaches a level that overcomes friction, inertia, and deadband and causes motion towards the setpoint.

The proper way to tune a PID is to zero I and D, then increase P, and do some moves. Continue increasing P until motion starts to become unstable. Back off slightly from that point. At that point it will almost certainly be over-shooting the setpoint, and likely "ringing". Increasing I will reduce the overshoot and ringing. Once I is set properly, you should be able to further increase P. Iterating will get the best settings. D will, in many/most cases, be useful only with high-quality hardware (high-resolution encoders, backlash-free hardware, etc.), as the differential error calculation will introduce a lot of noise, which can easily lead to severe instability. The primary effect of proper D tuning will be to damp the motion, making accelerations ramp more gently. This will make the motion smoother, but not as responsive.

In general, the P coefficient will be the largest, the I coefficient MUCH smaller, and the D MUCH smaller still.

Regards,
Ray L.

That completely mis-represents the purpose and function of the I term.

I should have mentioned this as a starting point. Set up correctly Proportional only control could be all they need.
Z

I increases overshoot and ringing, D decreases it. Proper attention to suppressing integral-windup is
key to a usable system for position control subject to step-inputs.

I's only use is to cancel the offset (makes the open-loop gain infinite at DC), but its a double-edged
sword that can cause as many problems as it solves.

Feed-forward is a good tool to have, and complements a PID loop, but gets a bit more complicated.

The integral term allows the controller to have a non-zero output when the error is zero. A P-only controller MUST have a non-zero error in order to produce a non-zero output. A D-only controller (a really dumb idea) would require a constantly changing error in order to produce a non-zero output. A PD controller would require at least one of these conditions in order to produce a non-zero output.

zhomeslice:
Ki will be set to zero because the setpoint is known and it is zero so no offset is needed

In addition to everything that zhomeslice mentioned, it is also possible that holding a constant position requires a non-zero output. As an extreme example, consider placing the robot on a conveyor belt.

Jiggy-Ninja:
In addition to everything that zhomeslice mentioned, it is also possible that holding a constant position requires a non-zero output. As an extreme example, consider placing the robot on a conveyor belt.

in his stackoverflow.com post he mentions:

My robot's position goes from [0,130]. He knows everytime in which position he is My problem is that I dont know the timer (1 ms, 1 second,etc..) I should use. Also my integral will keep growing bigger and bigger... and it will keep increasing the value of my output and it has to be between [-1,1] (see down) .

so my setting the setpoint to zero and eliminating the Ki completely preventing windup and using Kd as a breaking feature he should be able to land on setpoint without having to worry about delta T
**Geaper **
Note: Delta T can be anything most use seconds but it could be 100 miliseconds or even microseconds just adjust Ki and Kd to work well with your choice of delta T (Kp is not time based) and keep the interval consistent is the only real requirement.