I need the step by step Arduino IDE Algorithm with comments and explanation for implementing PID control on 2 Servo motors (sg90) connected perpendicularly for directional movement. Servo1 Left/Right ; Servo2 Up/Down. Kindly help.
Servos already include their own PID control within them. I don't understand why you would need to implement PID on the Arduino as well.
If you provide a good description of the project you are trying to create it will be much easier to give useful advice.
...R
Other post/duplicate locked
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.
Could you also take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
prozak7:
I need the step by step Arduino IDE Algorithm with comments and explanation for implementing PID control on 2 Servo motors (sg90) connected perpendicularly for directional movement. Servo1 Left/Right ; Servo2 Up/Down. Kindly help.
There's absolutely no difference driving two servo loops as driving one, other than needing to run both
loop update functions regularly.
So any guide to creating a PID loop around a motor and encoder will be sufficient.
The basic idea is that you need an encoder to provide a an actual position input, a
position setpoint variable, then run the PID on the error between these. The output
value is a signed number encoding both the direction and drive-strength that goes
to the motor driver.
In pseudo code:
every n microseoconds:
for every motor/encoder pair:
encoder_position = read_encoder()
error = set_point - encoder_position
output = PID (error)
direction = sign (output)
strength = abs (output)
control_motor (direction, strength)
And of course the rest of the code has to update the set point(s) appropriately.
You can do the same thing with velocity rather then position if you want.
For position control the motor driver should ideally be using synch rectification mode,
not fast/slow/mixed decay modes.
More sophisticated systems monitor the current to the motor and have an inner PID
loop controlling current from the drive strength input. The requires a fast current
sensor and such an inner loop needs to run fast, perhaps 10kHz or higher (usually
at the PWM frequency used).
If you want to take this further, there's advanced motor control theory/practice lectures
here: https://www.youtube.com/watch?v=fpTvZlnrsP0&t=1984s
Robin2:
Servos already include their own PID control within them. I don't understand why you would need to implement PID on the Arduino as well.If you provide a good description of the project you are trying to create it will be much easier to give useful advice.
...R
Trying to implement PID control into solar tracker project using LDR's and Servos. Need an algorithm for it.
prozak7:
Trying to implement PID control into solar tracker project using LDR's and Servos.
The sun does not move very fast so I can't see the need for PID. Just move a little bit towards the light and check again. Stop when the two LDRs show the same light level. Or go one extra step and then back-up one. Even if there is a small error in the angle it won't matter for the solar panels.
There is a nice simple PID function in this link.
...R