I am working in a line following robot and I'm trying to implement a PID control loop, but i don't know how to tune it effectively. I have two sensors, with the black line in the middle of them. I'm calculating the error with the intensity of sensor1 - the intensity of sensor2, and then calculating the speed. This is my code simplified:
error= sensor1_value-sensor2_value
error_sum+=error
dif_speed=error*kp+error_sum*ki+(error-last_error)*kd
run(speed-dif_speed+speed+dif_speed)
last_error=error