Go Down

Topic: PID - 4 motors car (Read 502 times) previous topic - next topic

rubzir

May 02, 2018, 11:25 am Last Edit: May 02, 2018, 11:28 am by rubzir
Hi,
I'm building a line follower car robot with 4 motors (2 each side. each 2 motors get the same input).
I was following the instructions I read from https://www.pololu.com/docs/0J21/7.c, but this code is for 2 wheels car. I tested it on my car but it doesn't turn as I expected
My robot i capable of 360 degrees turn but this PID algorithm is not using negative values  

Do you have an example of how to modify the PID algorithm  or example, so it will be good for 4 wheels?

signed int position = read_line(sensors,IR_EMITTERS_ON);
int proportional = ((int)position) - 2000;
int derivative = proportional - last_proportional;
integral += proportional;
last_proportional = proportional;
int power_difference = proportional/20 + integral/10000 + derivative*3/2;
const int max = 60;
if(power_difference > max)
   power_difference = max;
if(power_difference < -max)
   power_difference = -max;

if(power_difference < 0)
   set_motors(max+power_difference, max);
else
   set_motors(max, max-power_difference);

Thanks,



vinceherman

If your 4 motor/4 wheel car steers like a skid steer, then it should operate the same way as a 2 motor 2 drive wheel car (usually with a caster wheel).

Go Up