Hi guys, im programming a robot with 2 motors and i got the task to let it drive straight via a pid control program.
I read few books and stuff and wrote my code but i dont get how i decide what speed i have to set.
i get an error which is error=v_desired-v_actual
and i get v_actual from the encoders but i dont really get how the encoders work and how i have to set the speed that it works. The values i used always made it go to full speed.
I can set the motor value from -100 to +100 but i dont know in which form i need to set the v_desired and how i have to work with the encoder values
We use diffrent functions to get the encoder values and im not sure which i should use.
I can use kEncoderGetLeft, kEncoderGetSpeedLeft and kEncoderGetClearedLeft. Which one would work the best
Here is my code for the PID Control that i used till now but i tested it on the robot and it was quite weird bc i read the encoder values and the value was either really low like 2 or too high like 19000:
Every 250ms this function is used:
v_act_r=kEncoderGetSpeedRight;
encoders_clr();
e_func_r = v_des-v_act_r;
r_mot_r = r_old_r +K_P*(e_func_r-e_old_r)
+K_I*(e_func_r+e_old_r)/2
+K_D*(e_func_r-2*e_old_r+e_old2_r);
if(r_mot_r>= +100){
r_mot_r=100;
}
if(r_mot_r<= -100){
r_mot_r=100;
}
r_old_r=r_mot_r;
e_old2_r=e_old_r;
e_old_r=e_func_r;
motors_set(kMotorSetRight, r_mot_r)
But the speed didnt behave like its PID controlled. i just set my motor value and it stayed the same.
Im really not sure how to use the encoder values.
I really hope someone can help me and im sorry if i explained my problem a little bad but english isnt my first language
Thx for the help