Guided By: Dr Xiaorong Zhang, San Francisco State University
Made By: Purvesh Kulkarni
This project balances a vehicle on two wheels using combination of Tiva TM4C microcontroller and IMU 9255. The following is the block diagram of the system:
The MPU generates two types of data
1. Accelerometer data (X-axis, Y-axis, Z-axis)
2. Gyroscopic data
The IMU communicates with the microcontroller using I2C protocol. The I2C communication frequency is set at 400 Khz . Combination of accelerometer and gyroscopic data from the IMU is processed in the TIVA using the following code to generate the angle of the robot:
MPU data to Angle
The angle of the robot is used to calculate the error values using the PID Controller. The angle is generated such that if the robot is perpendicular to the ground the angle is zero. Leaning of robot to one of the side would increment the angle in either positive magnitude or negative magnitude.
To balance the robot upright, the angle of the robot must stay zero. This can be achieved by moving the vehicle in the direction of the leaning angle. With respect to the code, the speed of the robot is mapped such that the speed is highest when the leaning angle is highest. The speed of the motors are changed with the help of PWM signal. For maximum speed and zero speed, the duty cycle of PWM signal is set to 100% and 0% respectively. The speed is changed by changing the duty cycle.
PID stands for proportional, integral, differential controller. To calculate the error for correction, the angle calculated above is fed to the PID controller which is then passed to the motor controller to control the speed of the motor. The following is the mathematical equation of a PID controller.
PID Controller Mathematical Equation
K stands for the coefficient for each type, Proportional Coefficient, Integral Coefficient and Differential Coefficient respectively (according to equation). The following is the block diagram of the PID controller.
PID Controller Flow Chart
-Proportional Controller - Brings the error to zero by setting output proportional to the error.
-Integral – Brings the error to zero by referring the past error values
-Derivative -Bring the error to zero using the rate of change.
The corrected values from the PID controller is then sent to the motor controller. The motor controller used in this project is based on L298 dual full bridge driver which receives its corrected speed using PWM signal. The duty cycle of the PWM signal changes in accordance to the leaning angle. Higher the leaning angle, higher the duty cycle hence higher the speed. To correct the angle the speed increases in the direction of the leaning of the robot.