Diy Project
Diy Project
PROJECT
PID Controlled Self
Balancing System
1
OUR TEAM
21CE10002 ABHIRUP PAL HARSH KHASBAGE 21CS10029
Coding and
Circuit Designing
Development of logic
2
1
PARTS AND
COST
3
PARTS AND COST
₹250
ULTRASONIC ₹60
SENSOR BREAD BOARD
(✕2)
SERVO ARDUINO JUMPER
MOTOR UNO WIRES
₹250/- ₹800 ₹150
5
CIRCUIT
6
HOW IT LOOKS
Ultrasonic Sensor
Movable Joints
Servo Motor
Bread Board
Arduino UNO
Ultrasonic Sensor
Block for User
7
3
PID CONTROLLER
8
PID DIAGRAM
9
HOW IT WORKS
The system works by measuring the distance of the cube and the distance of the
vehicle from one end by two sensors. The distance of the vehicle is the Process
Variable (PV) which is desirable to be equal to the distance of the cube (setpoint).
The difference of these distances is computed to be the error and the PID controller
calculates the amount of rotation of the servo motor required to decrease the error to
0 (zero) to align the vehicle to the cube.
10
PID CONTROLLER
The PID algorithm consists of 3 parts that contribute to the output which is fed again to the input. These
three parts are :
1) P which stands for Proportional : This term accelerates the output towards the desired value
depending on the error between them.
2) I which stands for Integral : This terms remembers the past by integrating over the error as time
passes so that noises are suppressed eventually.
3) D which stands for Derivative : This term predicts the future by measuring the rate at which the
output accelerates towards the desired value so that there are no offshoots and reduced
oscillations.
All these terms are associated with their respective gains which determine how much each term affects
the response of the system under varied conditions.
11
CODE
12
CODE CONTINUED
13
CODE EXPLANATION
● The distance of the cube from one of the sensor is taken by the function measure_2() on trigPin2 and
echoPin2 and that of the cart is taken by the function measure_1() on trigPin1 and echoPin1.
● The move_servo() function takes an integer in its parameter and maps it to move the servo accordingly.
● setup() function sets up the circuit and connects the servo to the arduino uno. It also takes two initial
inputs from the two ultrasonic sensors.
● loop() is the main part and here we implement the PID controller. Distance of the cube is taken as input
and filtered using the previous input in setup(). Same is done for distance of the cart from the sensor.
● Next we find the error as the difference in these distances.
● Using this error and previous measurements we find P, I, D terms. Kp, Kd and Ki are respective gains
which have to be tuned to make sure that the algorithm works as expected.
● D is filtered to reduce noise because it is very sensitive to noise.
● U is found in radians and till it’s inside the movable range of the servo, the I term is computed as
saturation is false. Once system settles down saturations turns on thus making the I term count.
● U is changed to degree.
● U is mapped to the corresponding value of the servomotor.
● The servomotor is moved till error is more than some threshold value which is 0.02 here.
● The current values of I, D, P, setpoint is stored for use as previous in the next iteration.
14
4
APPLICATIONS
15
PRACTICAL USES OF PID
● Self driving vehicles can be made much less jerky and more responsive using these PID
controllers.
● Calculating the distance of the line where the vehicle originally moves and where it should, we can
create an offset angle using PID that instructs the wheels when to steer and by how much.
● One of the practical uses is in drone stabilization and many more areas.
16
CHALLENGES FACED
● Friction in wheels of toy car, resisting its movement even on significant tilting of plank.
● The arm length of the servo motor was not long enough to produce a significant angle range in the
plank to overcome the friction of toy car. To solve this, multiple arms had to be screwed together.
● Manual PID tuning is not an easy task as it needs trial and error method which is time consuming.
VARIATIONS OF WORKFLOW
● Manual tuning is a traditional way and instead we could have used auto tuning in MatLAB.
● The tracks on which the vehicle moved could have been made more smooth.
17
OUR PROGRESS
18
THANK YOU
19