Im trying to run on linear trajectory using DC motors with PID.
The motor are like the one on this link: Micro DC Geared Motor w/Encoder-SJ01 (6V 160RPM 120:1)
Using 2 PID controllers, one for each motor, with the PID setPoint the same for both motors encoders I have manage to get a stable linear trajectory. At a very slow speed as I intended.
But although it goes straight, it does not start straight. It seems that the 2 motors start at a different times, and because of that small time frame error, the robot get a small orientation change, and then follow the linear trajectory.
I read something about acceleration ramp, but the implementation I saw are just PWM sequential increments on one motor, and not see any sample for motors synchronous start.
My try to integrate an acceleration ramp on a PID was not very successfully.
Then I try to start the first PID loop with a pre defined PWM for each motor, that should activate both motors at same time, but also not very successfully.
I can post code later, and also a video to show the current results, But Im wondering what kind of strategy you follow to manage to start both dc motors at same time.
– 1st edit
blue: left encoder pulses
red: right encoder pulses
green: left motor pwm/10 (for scale display)
yellow: right motor pwm/10 (for scale display)
purple: pid setPoint pulses
gray: total pulse error (only in one graph)
PID setPoint = 5
PID sampleTime = 25
You can see on the graph, without gray line, that the blue line start climb first, and the red line takes some more time to climb, maybe 15 pid calculations. So it starts about one third of second later.
That fraction of second give a difference in the total of pulses on both motors (total pulse error), that are special big at the beginning, as you can see on the other graph (its the gray line).
That big accumulation of error on the beginning result on small (or not so smal) orientation change that is never totally compensated.
The first second its the hard one!
– 2nd edit
– 3rd edit
Code is attached
2pidsync.ino.txt (7.97 KB)