Robot Features
The robot is powered by two DC motors connected to a 6V battery pack and controlled by an H-bridge chip (TB6612). Each motor is equipped with a hall effect sensor to detect changes in magnetic field strength. The IMU outputs can be derived to determine the pitch and roll angles of the robot. Additionally, a potentiometer controls the speed and direction of both motors. By combining these components, the speed and direction can be adjusted based on the tilt of the robot, forming the basis for enabling it to balance.
Figure 1. Writing Matlab code
Explaining PID
The final step to achieve balance in the robot is to implement a PID (Proportional-Integral-Derivative) algorithm. The pitch angle serves as the set-point variable, controlling the motors to maintain a pitch angle of zero (vertical).
The tuning of the three variables was accomplished through trial and error, testing the robot's balance each time they were adjusted. The proportional term can be likened to a desire to reach the destination as quickly as possible, but it may lead to oscillations as it 'overcompensates'. The derivative term aims to prevent the Segway from reaching the destination too rapidly by sensing a decreasing distance and adjusting based on the rate of change of error. The integral term serves to minimize steady-state errors when the pitch is at zero. Without this term, the motors would cease functioning, leading to errors once more.
Figure 2. Logbook kept during the project