In a broad understanding of control systems, we use a sensor reading as input. we set a target for that reading and try to minimize the difference between target and input reading by performing some action and taking the input again. IN PID control,we use additional parameters(constants) to reduce the difference between input and target faster.
You can follow the following algorithm without PID control and
yet achieve a proper wall following
For your problem :
Input : Distance from Ultrasound sensors.
Output : Motor
Assuming your placement of sensors on front(1),
right(2) and left(3) face of robot.
The simple algorithm can be modelled as follows:
- set constants i.e min dist to move forward,min dist to make right turn,min dist to make left turn.(min dist = minimum distance)
Loop 1
2. read from sensors 1,2,3.
3. if(distance from 1 > min dist to move forward) : actuate both motors.
4. if(distance from 2 < min dist to make right turn) : actuate left motor.
5. if(distance from 3 < min dist to make left turn) : actuate right motor.
end loop1
There is a 2nd loop in actuate function where
1. Set target distance from sensor as min distance + some constant.
loop 2
2. compute error = target - read from the interested sensor.
3. output:using PWM technique control motor ON-OFF actuation
until error is zero.
end loop2
If you are interested in PID control you can follow the link
https://github.com/jdelacroix/simiam
It is a tutorial on matlab for PID control of robot.
you can change few scripts in the SIMIAM controller to suit your needs
It even has a implementation of ultrasound sensor.
hope this helps
I personally fell implementing a simple PID controller on arduino is tough
as it needs a lot of fine tuning to make the robot move parallel to wall.
I suggest you use additional sensors like odometry or IMU to get exact parallel following