Development of a PID Controlled Arduino-Based Stabiliser

Inverted pendulum remained as the most popular topic for control theory researches because of its characteristic of being non-linear, unstable and under-actuated system. It is ideal for verification, validation and enhancement of control theory by stabilizing the inverted pendulum in an upright position using various controller and stabilizer mechanism. For this project, Proportional-Integral-Derivative (PID) controller is used to stabilize the inverted pendulum by tuning the respective gains (kP, kI, and kD) to control the parameters of inverted pendulum which includes the rise time, settling time, overshoot and steady-state error in cooperation with of Arduino microcontroller. The objective of this project is to design and build a stabilizer mechanism with the integration of mechanical and electrical components to stabilize two Directional (2D) inverted pendulum similar to 3D printer mechanism. Besides that, PID controller will be tuned in Arduino microcontroller and control the output of stabilizer mechanism. The stabilizer mechanism is designed in SolidWorks software and built using various manufacturing techniques, raw materials and 3D printing, while the electronics components such as gyroscope and Direct Current (DC) motors are controlled using Arduino Due in C++ language. The gyroscope determines the tilting angle of the pendulum as a feedback in the control loop, and the gains of PID are used to control the speed and direction of DC motor to provide sufficient force/torque to keep the inverted pendulum in an upright position. The stabilizer mechanism with inverted pendulum has been built and the gains of PID have been tuned using “trial and error” method as friction is now taken into consideration. The inverted pendulum is successfully stabilized in an upright position (0o measure at z-axis) using control theory.


Introduction
Inverted pendulum remained as one of the most popular problems existing in control theory and has been studied in many researches for the control community [1].The unstable, nonlinear and under-actuated characteristics of an inverted pendulum system raise a challenging task for testing different control algorithms due to its large uncertainties attached with the system [2].There are many methods to stabilize the inverted pendulum and one of the methods is by using a Proportional-Integral-Derivative (PID) controller.PID controller is a control instrument that is commonly used in the industrial control applications to regulate processes as part of a control loop [1].
Each controller in a PID contains of their respective tuning gain, k P , k I , and k D .Tuning any of the gain in PID controller affects the control system parameters: rise time, settling time, overshoot and steady-state error.Rise time is the time taken for the waveform to go from 0.1 to 0.9 of the final value.Settling time is the time taken for the transient's damped oscillations to reach and stay within ±2% of the steady-state value.Overshoot is the amount of waveform overshoot from the final value or the steady-state value.Steady-state error is the difference between output value and desired output value [3].
A one-dimensional (1D) inverted pendulum is commonly used as study material.The inverted pendulum is placed on a cart and stabilized using linearization method.The distance travelled by the cart produces force to keep the inverted pendulum upright.The distance travelled by the cart alters based on the difference of pendulum angle relative to yaxis [1].The pendulum angle is measured and the difference of the pendulum angle is calculated and fed into PID controller for stabilizing the inverted pendulum by producing an ideal system response with optimal gain value to drive the cart for a certain distance.The limitation of one axis inverted pendulum is that the stability of the pendulum can only be studied for one axis.

Fig. 1. Cart pendulum system. [1]
To further study on the inverted pendulum, a two-dimensional (2D) inverted pendulum will be chosen.Increasing one axis will increase the number of uncertainties and nonlinearity of the pendulum which introduces a wider range for testing control algorithms.A mechanism with the integration of mechanical components and electronics components will be built to stabilize the 2D inverted pendulum using pulley system and sliding mechanism.The difference of the pendulum angle relative to x-axis and y-axis is measured using a gyroscope sensor.
A gyroscope sensor determines the position, orientation and angular velocity using Coriolis force applied to a vibrating object [4].When the gyroscope is rotated, the Coriolis force acts upon the drive arms and produces vertical vibration.The vertical vibration then produces a sensing motion in the sensing arms.The motion on the sensing arms creates a potential difference where the angular velocity is measured and converted into small current signals.The signals are then amplified and fed into a controller.Gyroscope sensor is placed onto the 2D inverted pendulum.The orientation and position of inverted pendulum are measured, converted into signals and compared with the desired output value in the control system and the error is calculated [5].The error is then fed into PID controller and each parameter of the gain is tuned to produce and output angle to drive the mechanism to stabilize the 2D inverted pendulum.

Design of the Stabiliser
The stabiliser design consists of two parts, which are the mechanical and electrical parts.Mechanical part contains the inverted pendulum, pulley system and sliding mechanism.The PID control and communication between the microcontroller and the actuators (motors) are discussed under electrical part.

Mechanical system
Linearisation method is one of the easiest methods to stabilise an inverted pendulum.A cart moves in x-axis and y-axis linearly to a desired position where the pendulum is stabilized when the pendulum tilts but does not exceed the tilting maximum angle (30o relative to zaxis), if tilting angle is exceed the pendulum falls to maximum position.Using this method, the first stage of this project is to build a 2D inverted pendulum on a moving cart and the stabiliser mechanism to stabilize or balance the inverted pendulum to an upright position.
The ideology of the stabiliser mechanism is a mock of a 3D printer mechanism shown in Fig. 2 because of the accuracy and precision exhibited by a 3D printer.The extruder of 3D printer moves on along the Cartesian plane in x-axis and y-axis with four directions on the gantry.The extruder receives xy coordinates from the software, where each part of the object needs to be printed and the heater cartridge on extruder heats and melt the filament to be deposit onto the bed of 3D printer [6].Therefore, 3D printer has high accuracy and precision in coordination to print the objects as they are designed to be.To balance an inverted pendulum requires the accuracy and precision exhibited by the 3D printer, hence the stabiliser mechanism is built similarly to the mechanism of a 3D printer.

Fig. 2. 3D printer mechanism.
From the 3D printer mechanism, a pulley system and four sliding mechanism is implemented to allow the 3D printer to move at x-axis and y-axis.The similar pulley system and sliding mechanism is implemented on the cart to form a stabiliser mechanism and moves the cart of inverted pendulum along the x-axis and y-axis.

Pulley system
The pulley system is implemented to convert rotational motion produced by motors into translational motion for the inverted pendulum cart.The components in this system include timing pulleys, timing belts, flanged bearings and solid rods.A 60T timing pulley is mounted on the shaft of Direct-Current (DC) motor and connected to 20T timing pulley [7], with a closed-loop timing belt [8], as shown in Fig. 3. Due to the friction and requirement of high acceleration to hold the inverted pendulum upright, the DC motor rated speed was not sufficient to provide such acceleration.Therefore, the number of teeth on pulley attached to motor is triple the number of teeth on pulley attached to solid rod to increase the translational speed by three times using pulley system.

Sliding mechanism
The sliding mechanism is integrated with the pulley system to provide guidance for inverted pendulum cart to move along x-axis and y-axis.Since there are two axes, the pulley system of x-axis overlaps with the pulley system of y-axis, therefore the design of inverted pendulum cart requires high accuracy of dimension where the solid rod of y-axis on cart is perpendicular to x-axis and does not collide or touches each other.Similarly, the design of sliding mechanism to hold the inverted pendulum cart by each end of stabiliser mechanism requires high accuracy for inverted pendulum cart to travel in straight line on xaxis and y-axis.The designs are shown in Fig. 4 and Fig. 5.The main component for sliding mechanism is the linear ball bearing.The linear ball bearings assist in reduction of friction by allowing solid rod of y-axis to rotate while the sliding mechanism of x-axis to have precise translational motion [9].Due to high accuracy of dimension, the sliding mechanism parts are manufactured through 3D printing and linear ball bearing is inserted into each block of sliding mechanism.Fig. 6.Inverted pendulum holder.
The gyroscope is attached onto the inverted pendulum to determine the position and orientation of inverted pendulum which will be converted into electrical signals and fed into a microcontroller to control the direction of rotation and speed of both DC motors.

Electrical and electronics methodology
The translation motion of the cart is controlled by 2 DC Geared motor as each DC geared motor is assigned to control one axis of translational motion.Both motors are coupled with the motors through the pulley system and sliding mechanism.The DC geared motor is used to rotate a vertical gear and a horizontal gear for a transmission of torque from horizontal to vertical and rotates the timing belt pulley to pull the timing belt on the cart.In order for the cart to have sufficient force in balancing the inverted pendulum, the torque and speed of DC geared motor are significant in producing the amount of force.The speed of motor is measured in revolution per minute (rpm) and torque would be newton per meter (N.m).Both DC geared motor has the same specification where each motor has the speed of 380 rpm (0.12 m/s) and torque of 637.43 mN.m (6.5 kg.cm) [10], which is able to produce the force needed to keep the inverted pendulum upright.
The tilting angle of pendulum is measured using gyroscope and the current signals from gyroscope is fed into microcontroller to convert angle analog signals to digital signals to provide a feedback.If the angle of pendulum is more than 0 and less than 5 , the difference between desired angle of pendulum ( 0 less than -5 , the difference between desired angle of pendulum (0 ) and measured angle of pendulum is calculated for an error signals to be converted into PWM signals.The PWM signals is fed into DC geared motor and rotate the motor in counter-clockwise direction.However, if the angle of pendulum remains at 0 , the PWM signals are LOW to stop the DC geared motor from rotating.Fig. 7 shows the flowchart for the DC Geared motor.
Methods from Research Methodology are executed in order to achieve the objectives of this research.Experimental testing on the stabilizer mechanism and electrical and electrical components are done such ensuring the stabilizer mechanism is able to move the cart in xaxis and y-axis, inverted pendulum tilt only along x-axis and y-axis, angle of tilt for inverted pendulum is read by gyroscope, microcontroller process the angle of tilt, tuning the PID gains and vary the speed and direction of DC motors.

Mechanical system
The 20T timing pulley is mounted on a solid rod which is connected from one end to another end of the frame of stabiliser mechanism with flanged bearing to allow smoother rotation of solid rod [11], shown in Fig. 8.When the DC motor rotates, it rotates the 60T timing pulley and with the closed-loop timing belt, the rotation is translated to the 20T timing pulley and solid rod.The pulley system is also used to move the inverted pendulum and cart by having two sets of 20T timing pulley mounted on a solid rod that hinged on the frame of stabiliser mechanism as shown in Fig. 9.This is implemented on the right end and left end of the frame of stabiliser mechanism.Both of the solid rod are connected with timing belt to form a closed-loop and the ends of timing belt are attached onto the sliding mechanism of inverted pendulum.This allows the inverted pendulum cart to move along x-axis.The same configuration is implemented for the cart to move along y-axis.As the DC motor rotates clockwise, the 60T pulley translate the clockwise rotational motion to 20T pulleys and solid rod.The rotational motion is then converted to translational motion by rotating the timing belt attached on sliding mechanism allowing the cart to move at positive direction of x-axis.While if DC motor rotates counterclockwise, the cart moves at negative direction of x-axis.This applies in moving the cart for positive and negative direction of y-axis.This creates force through acceleration of motor to keep the inverted pendulum at an upright position,  = 0 .

Electrical and electronic system
The overall schematic diagram of electrical and electronic system is shown in Fig. 10 on how each components are related to each other and the process of the system.

Microcontroller (Arduino Nano)
Microcontroller forms a communication between input devices and output devices through programming languages.In this research, Arduino Nano communicates with gyroscope and DC motors through C++ programming to identify the angle of tilt from inverted pendulum as input and the speed required from DC motor to keep the inverted pendulum upright as output.Acceleration of DC motors are converted into linear force by pulling the timing belt in clockwise and counter-clockwise direction subsequently moving the cart in x-axis and yaxis.However, to keep the inverted pendulum upright, the acceleration is constantly changing and increases the difficulties in providing theoretical value of force required to balance the inverted pendulum.PID controller is used to assist the response of DC motor towards the angle of tilt from inverted pendulum.The ideal response characteristic includes low rise time, small percentage of overshoot and zero steady-state error of DC motor.This is done by tuning the gains of PID controller which can be alternated in C++ programming of Arduino Nano.The angle of tilt is monitored through Serial Monitor from Arduino Nano and the gains are tuned according to measured angle of tilt until desired value of angle of tilt is obtained.The current gains of PID for x-axis and y-axis are -1 to 1 which includes the friction arise from pulley system and sliding mechanism.

Gyroscope (MPU6050)
The gyroscope is attached perpendicular to the inverted pendulum facing downwards because the jumper wires to be connected from gyroscope to Arduino Nano cannot exceed 5cm.This is due to the disturbance of noise and interference on the bandwidth of gyroscope when transferring signals to Arduino Nano.The longer the jumper wire, the higher the resistance, noise and interference of bandwith.Therefore, shorter jumper wires are recommended.The gyroscope is tuned in such way that it only measures the x-axis and yaxis rotational motion.Z-axis and acceleration motion are tuned out to reduce the processing time of signals (faster signal transfer between gyroscope and Arduino Nano) as these two parameters are not in the scope of this research.Gyroscope has an internal voltage regulator to reduce 5V supplied from Arduino Nano to 3.3V as required to eliminate excess of voltage and causes damage to the gyroscope.
3 ports of gyroscope are connected to Arduino Nano namely, Signal Data (SDA), Signal Clock (SCL) and Interrupt.SDA processes the rotational motion (x-axis and y-axis) of inverted pendulum, stores the value as angle of tilt and send it to Arduino Nano.SCL is the frequency of transmission of data between gyroscope and a microcontroller and the built in frequency range about 400kHz which allows one data to be transferred at 2.6 nano second.The Interrupt port is to identify the status of gyroscope.When the gyroscope is ready to function, Interrupt port sends a signal to Arduino Nano and the program in Ardunio will run because the gyroscope requires initialization before running the program.Due to the limitation of bandwidth from gyroscope, the maximum tilting angle of inverted cannot exceed ±5 on x-axis and y-axis.
As all components are assembled, communication of electrical components are programmed by C++ programming and PID gains tuned, experimental testing is done on the stabiliser mechanism to balance the inverted pendulum.Table 1 indicates the achievable tasks by stabiliser mechanism and inverted pendulum.

Conclusion
In conclusion, the stabiliser mechanism has been successfully designed and built.The inverted pendulum cart is able to travel along the x-axis and y-axis and produce force to keep the inverted pendulum in an upright position.The gyroscope is able to measure the angle of tilt of inverted pendulum and sends values to Arduino Nano to be processed.By analyzing the received signals, the PID gains are tuned through C++ programming in Arduino Nano and the response of inverted pendulum and DC motors are observed.The inverted pendulum is balanced in an upright position from negative and positive of x-axis only and y-axis only.
The future work includes balancing the inverted pendulum from various coordination on x-axis and y-axis as with increasing number of coordination, the PID gains will be tuned differently in order to receive same outcome as balancing inverted pendulum from negative and positive of x-axis only and y-axis only.The response curve of an inverted pendulum changes with number of coordination or number of uncertainties.The aim of this future work is to obtain characteristic includes low rise time, small percentage of overshoot and zero steady-state error of inverted pendulum and identifies the mathematical modelling to determine gains for PID controller that stabilizes 2D inverted pendulum.

1 =
Speed of gear on DC motor N 2 = Speed of gear on Solid Rod T 1 = Number of teeth of gear on DC motor T 2 = Number of teeth of gear on Solid Rod 4 MATEC Web of Conferences 152, 02020 (2018) https://doi.org/10.1051/matecconf/201815202020Eureca 2017