how to use this PID if i had ultasonic sensor on pin 2 that sense left side range and i had two unstable motor on pin 3 and 4. what i want to use with PID is that i want to make the ultrasonic sensor always read 10cm even though the motor are unstable by controlling the PWM given to both motor.. so the ultrasonic sensor is like a reference to make both motor runs straight..
by using simple program it is already done.. but the robot would do like zig zag move rather than smooth straight movement..
unstable means that even though its the exact same motor, the speed it yields wouldn't be the same with same PWM.. so if we send 50 PWM to both of the motor, the motor would have an alignment to the left.. as you know that a calibration is always needed for DC motor.. but in this case i want to add PID to smoother the movement rather than calibrating the PWM..
The PID process, as has been pointed out, determines an error value - the difference between the desired measurement and the actual measurement.
This error value, and a relatively complex formula is used to determine the change needed in some other value to bring the measured value closer to the desired value.
If you choose to provide a constant PWM value to one wheel, you could use the PID process to control the PWM value for the other wheel, if your objective is to go in a straight line or stay a constant distance from a wall.
so if PID has 3 parameter, input, output, setpoint, i can say that the input should be sensor measurement, output is the PWM to the motor and setpoint is the desired range?
Greatings, and sorry for my english.
lucandu, if you want to use a pid, you should know the system model, the mathematical model of the process, because some models need pid to work corectly, others need only PI or simple I, a motor is beste controled using a I controler, according to the Optimal Criteria of Kessler, if you have a working board, or system, you should try to do some system identification to get a model. You should not try to use a pid unless the system actualy needs a pid, because if the system is a PT1 system(most motors out there), a I controler is the only controler that would keep your system working http://www.controlguru.com/ for some lite reading
hi Lucandut... in this line:
Input = analogRead(0);
did you establish one PIN of ultrasonic sensor? if you did like that..is it the PIN or echo or trrigger?
or
perhaps you stated in the variable the real distance measured in cm or what did you do?
please let me know if you dont understand what i mean