For control purposes, program codes are written in the Arduino IDE and the Processing software. The already available PID Front End code by Brett Beauregard (2009) for Processing is modified accordingly to make the GUI.
The Arduino code runs the main code, which includes the PID algorithm. Processing software is used to plot, in real time, the graphs of the processed variables from the Arduino.
The main code for controlling the position of the slider-nut is written in Arduino IDE. Flow Chart of Arduino IDE code is as follows:
Interrupt service routine is written under the function named as PIDcalculation (). It includes the algorithm for finding the PID output value. analogWrite function for generating the PWM signals w.r.t the PID output and the direction deciding statements the make sure the motor moves in the direction that the error is reduced.
Desired position is defined by the user in the variable ‘Setpoint’. If the user changes the desired position, the motor automatically attains that position through PID algorithm. In the presence of any disturbance, PID brings the motor back to that stable position once the desired position is attained.
The graphical user interface is designed in the Processing software to interface with an Arduino running the PID algorithm. From this, we can adjust PID control gains and observe the system performance by plotting the actual and desired positions in real time.
Three variables are plotted with respect to time i.e.
Input to the controller
Setpoint
Output of the controller