Note: Please scroll down to see all details of this project below ↓
Labview PID Controller Lego Mindstorm
Objective of This Project
The essential goal of this project is to learn how to implement PID (Proportional-Integral- Derivative) control in our Lego Mindstorm EV3 robot by writing our codes in LabVIEW 2016 for my Introduction to Control Systems Engineering class. The task that we have to accomplish with our robot is to create a line follower using PID control to go up a ramp in our first phase. Then when both light sensors see black, they will switch into a state machine, and act as a line follower to track around the edge of the ring in our second phase. Lastly, when the ultrasonic sensor sees an object less than 10 cm away from itself, it will switch the state into PID control to track down the edge of the ring in our third phase.

Design pid algorithm & lego mindstorm robot
I implemented the PID control by trial and error, without implementing any specific method initially. I started with measuring the light sensor values by placing the sensor in the middle of the light and dark areas. Whereby, the values change when we are on-ramp and on-ring, due to the light that is being reflected from certain objects can be different, and this will be our “set point” value. Initially, I made a proportional controller by setting our Kp equal to 1 and slowly tuning the values of both Ki and Kd to make our PID control by testing it numerous times and making various observations when adjusting each value. The graphs below show the final run during our final competition that implements PID control for the first phase and third phases of the competition.

PID Verification graph & benefits
Using LabVIEW 2016 I retrieved the data recorded in the EV3 brick to start making the PID gains graph. By writing a few lines of code on MatLab 2022 I managed to plot out the PID gains graph as shown. By doing so, it is apparent that I've implemented a full PID controller to the robot, not just making a proportional controller. As shown in the video below, we can see how the robot runs very smoothly when it changes its state from a "state machine" to a full "PID controller" as its performing its line following stage and outer ring tracking stage.

pid controller lego mindstorm Final Demo
This is my final demo of the PID controller Lego Mindstorm robot. The robot started in PID state when going up the white ramp (line follower) onto the ring, in which it switch its state to a normal "state machine" to track the outer white ring. Once it sees an object less than 5 cm away from it, the robot changes back to PID state and will stop once we press the button on the top.
