Development of Two Wheeled Robot (TWR) by Single Stepper Driver Using PID Controller


 The mechanical stability is an important parameter for the development of specific robots. Nowadays, it has turned into an essential region of research in the current development, due to increased applications of robots in various fields such as biomedical, aerospace, marines etc. In this paper, Two wheeled Robot (TWR) is designed and fabricated following the concept of an inverted pendulum. It balances itself up in the vertical position. The Proportional Integral Derivative (PID) controller was utilized to locate its stable transformed position. The developed two wheeled robot (TWR) was controlled using angle of pendulum (). It consists of two stepper motors, one arduino Nano microcontroller, Inertial Mass Unit (IMU) sensor and stepper motor driver. An IMU sensor comprises of 3-axis accelerometer and 3-axis gyroscope which measure acceleration and angular velocity. The angle of robot () with respect to the vertical position is computed from the mesaured data. It helps the wheel to prevent from fall by providing the acceleration according to its inclination () from the vertical position. Further, complementary filter was used to compensate gyro drifts with the help of accelerometer readings. PID constants were tuned until optimum values are achieved. Performances were compared with ardunio UNO based Self-Balancing Robot [20] & found that the performance of TWR is almost similar to ardunio UNO based Self-Balancing Robot.


Introduction
Nowadays, human life is involved with robots in many ways. They can perform many complicated tasks easily, quickly and with high precision 1 . A two-wheeled self-balancing robot is a classic engineering problem based on the principle of an inverted pendulum and is much like trying to balance a broom on the tip of our finger 2 .
Zimit et al. 1  Inverted pendulum. The human body is an example of an inverted pendulum in which balancing occurred of the upper body around our ankle joints in every step. In the recent decade, Segway, making use of bodily movements for steering, have emerged in the market. These applications share that their center of mass is located above their pivot points, thus requiring active control in order to balance 3 . F. Grasser et al. 5 had developed a mobile robot based on inverted pendulum principle and named it JOE. It was an early version of a self-balancing robot designed using inertia sensors, motor encoders and digital signal processor board (for implementation of the controller). It weighs 12 kg and its height was 65 cm. Junfeng Wu et al. 6 worked on a fuzzy PD controller to prevent the robot from falling and achieved self-balanced control of the robot. They had studied the GBOT1001 7 two-wheeled self-balancing robot manufactured by Googol Technology Shenzhen Limited, and established the mathematical model of this system, using fuzzy PD control theory to control the robot. Jian Fang 8 has used particle swarm algorithm to optimize the parameter matrix of the Linear Quadratic Regulator (LQR) controller, which can help a robot in self-balancing. Brian Bonafilia et al. 9 have also used LQR for feedback and simulated results using Kalman Filter to stabilize robot in upright position. Qingwen Qian et al. 10 had designed parallel double fuzzy controller based on information fusion technology and simulated in MATLAB. Bature et al. 11 have done comparison of different controllers' viz. Fuzzy Logic Controller (FLC), LQR and PID by implementing on their robot. They observed that PID controller robot gives almost similar results as robot with LQR controller robot. Juang and Lum 12 had used PID and Proportional Integration-Proportional Derivative (PI-PD) controller in the same robot individually and compared. They observed that it can achieve more stability with PI-PD controller, and it can also compensate the centre of gravity (C.G.) misalignment. Rasoul and Mehdi 13 implemented three controllers on self-balancing robot viz. PD, PID and Fuzzy-PID. They compared the results using individual controller on Self-Balancing Robot (SBR) and found a slight vibration on the body of the robot due to increased steady state error after implementing PD controller.
They reduced the vibration of robot and made it more stable by implementing PID controller. They also observed that robot body might fell down by applying external forces on it. SBR is developed by tuning various parameters with Fuzzy logic to reduce this effect significantly.
Bhatti Omer et al. 14 have done comparative analysis between a simple PID-controller and an auto-tuned PID controller. They employed relay method to auto-tune PID parameters. They have found reduced steady state error, rise time and settling time with auto-tuned controller. Further, Robot can update its PID co-efficient in case of battery-drainage over time and change of mass during the operation with auto-tuned controllers. The only drawback of this controller is large overshoot. Unluturk Ali et al. 15 observed the effects of P, PI and PID controllers on self-balancing robot with the help of visual computer interface based on Qt-creator 16 . They observed that P-controller, alone is not sufficient for robot's balance. Robot can balance itself for a short period with PI controller and robot can stand in upright position longer with proper values of PID controller.
Francisco and Federico 17 had made a low cost (less than €35) educational robot: Arduino-A1, which included an android and Arduino system. The developed robot can be used as an educational tool in schools and colleges.
They included a combination of sensors and communication resources: GPS, compass, light sensor, accelerometer, camera, Wi-Fi, Local Area Network (LAN), Bluetooth and Internet connection capabilities. It can be easily programmed and modified by users. Yeonhoon Kim et al. 18 used Kane's method of three Degree of Freedom (DOF) modeling to conduct dynamic modeling to analyze the mechanism of two-wheeled robot.
They constructed a mechanical robot with tilt sensors, a gyroscope and encoders. His team has analyzed the effect of inclined surface and turning motion on stability of the robot. They succeeded in implementation of robot in balancing, rectilinear motion and spinning motion on 2-dimensional surface. Azhar et al. 19 have used two DOF PID controller to control self-balancing robot. Motor speed is controlled by inner loop and vertical position of robot is maintained in the specified boundary by outer loop. SBR have faster response, increased disturbance rejection and smaller error in comparison to the traditional PID controlled by Two DOF PID controller.
Zeng et al. 20 have developed self-balancing robot using Arduino UNO R3 micro-controller board. They have used DC motors as actuators, PID control loop as controller and Kalman filter to fuse data of sensors. Further, they also implemented Bluetooth module to send signal to robot via mobile application. An and Li 21 have done modelling and analysis of self-balancing robot by using the principle of energy conservation and Lagrange equation. They controlled two sub-systems namely self-balance and yaw rotation via PID and LQR controller.
In their design, both subsystems were controlled by PID initially and then after self-balance subsystem was controlled by LQR. They compared both sub-systems by doing simulation in MATLAB and found that, for controlling self-balancing subsystem, LQR gives more suitable results than PID. Zhuang et al. 22  In this paper, Two Wheeled Robot (TWR) is designed and developed by using a single stepper driver and PID control loop. It is simple compare to advanced controller such as PI-PD controller, fuzzy PID controller and does not require any matrix manipulation as in LQR. Further, Arduino Nano-micro controller, which is based on open source platform Arduino.cc 24 , is used which has the same functions of Arduino UNO with benefits of compact size and less cost. In addition, stepper motors are used for precise control of the robot. In General, separate motor driver is required for separate stepper motor, but in developed design, a single driver for both the motors has been provided. Here, one thing is to be kept in mind that both the motors should be driven in the opposite direction, since they are facing opposite to each other. The developed unique design reduces the cost, space and simplifies the code (for Arduino Microcontroller). Pulse width will be changed to drive stepper motors according to PID output variable, which in turn changes speed of motors that is proportional to an inclination angle ( ).

Mechanical System Design
Initial Design of robot is modeled in CAD software (Autodesk Inventor Professional) (Fig. 1). Design was taken from Joop Brooking's model 25 for reference. In the developed design, additional mass is provided to upper part of the robot, so that the center of mass will be at higher position relative to the wheel axis. It will increase moment of inertia of robot, which causes reduction in angular acceleration of robot. Further, it will also, help robot to balance better 4 . The dimensions and inertial properties of a robot are listed in the Table 1. The Block diagram is shown in the Fig. 2 for the circuit connection of two wheeled robot (TWR). Arduino Nano control board (Fig. 3) was used instead of Arduino UNO to reduce the cost of the TWR. It can be easily programmable by Arduino IDE open source software 24 . Its code is based on C language and even simpler than C language. DRV8825 stepper driver (Fig. 4) was also, used to drive the stepper motors for micro stepping up to 1/32. It works well compare to A4988 driver which can provide micro stepping up to 1/16 only. Designed TWR is driven on 1/16 th micro stepping with the driver. Further, Li-Po battery provides 12 V to run the stepper motors while, other electronic components like Arduino Nano, MPU 6050 and DRV8825 require 5V. To achieve this, 7805 IC (Fig. 5) was used to convert 12V to 5V as it is compact and not much costly. A lithium-ion polymer battery ( Fig. 6) was used due to its feature to recharge. It is based on lithium-ion technology in which polymer electrolyte is used instead of a liquid electrolyte. It also, provides higher specific energy than other lithium battery types. TWR also utilizes MPU 6050 sensor (Fig. 7) for the angular measurement. Stepper motors (Fig.   8) are used as actuators due to its unique feature to move in discrete steps. Further, it also, shows no performance loss when the battery voltage drops. The Step angle of stepper motor used is 3.75 0 . Also, with micro stepping of 1/16 th , a step angle of 0.234375 0 was achieved. 1N4001 diodes (Fig. 9) were used to ensure safety of components against the reverse connection of the battery. Furthermore, capacitors were used for protection of DRV and IC against voltage spikes.
All the components were purchased from Robokits India 28 except Li-Po battery. Li-Po battery was purchased from robu.in 29 . All components were connected with jumper wires on the breadboard and body of the robot is shown in the Fig. 10. The designed robot is divided in to three parts: the bottom part, the middle part, and the top part. The bottom part has two motors, middle part has IMU and top part includes wooden block, battery and breadboard containing all the (other) components (Fig. 11).
In the developed robot (TWR), bipolar stepper motor is used, which consists of two coils, and one permanent magnet. Leads of these coils are termed as A1, A2, B1 and B2 and Shaft of the stepper motor, which is connected, to the permanent magnet will rotate in the clockwise (C.W) or counter-clockwise (C.C.W) direction.
The angular direction depends on the sequence of voltage supply (through stepper driver) to these leads. Here, '+' means '+12 V' and '-' means ground. Table 2 shows the sequence of supply voltage applied on the lead in order to drive the shaft C.W. or C.C.W. Table 2 Sequence of voltage applied on leads in general case 31 Since, both stepper motors are facing opposite to each other, shaft of both motors should be driven in the opposite direction to ensure motion of a robot in straight direction (i.e. forward or backward). Generally, two stepper motors require two different stepper drivers. However, in the developed robot, both stepper motors are being driven with a single stepper driver only. Connection of these motors is shown in the Fig. 12. The leads of B1 and B2 were exchanged for motor 2 to ensure the opposite direction of rotation for both shafts. Thus, B2 for motor 1 will work as B1 for motor 2 and B1 for motor1 will work as B2 for motor 2. Therefore, a sequence of supplied voltage will be as per Table 3 in our case. By comparing the sequence of Table 3 with the sequence given in Table 2, it is clear that when shaft of motor 1 will rotate in counter-clockwise direction, the shaft of motor 2 will rotate in the clockwise direction and vice-versa. The various parameters of developed robot are listed in Table 4.

Robot Control System
The MPU6050 is a combination of a 3-axis gyroscope, and a 3-axis accelerometer. Angular velocity with respect to three axes is measured by a gyroscope. Acceleration (in terms of g) along three axes is measured by accelerometer. Here, MPU6050 (Fig. 11) is placed such as X-axis, Y-axis and Z-axis act as yaw axis, pitch axis and roll axis, respectively. Library: MPU6050.h inscribed by Jeff Rowberg 30 was used to get the readings from IMU sensor. Inclination of a robot is measured by two axis of accelerometer and single axis of gyroscope.

Using Accelerometer
Acceleration values along x-axis (accX) and z-axis (accZ) are required to measure the angle of inclination of a robot from the vertical position using accelerometer. Angle between the line to the point specified by the coordinates (accZ, accX) and the positive x-axis can be obtained by using tan2 (accZ, accX) with math.h library.
Henceforth, Desired angle of inclination ( ) is computed. Here, the positive sign (+ve) indicates counterclockwise angles (when robot leans forward), and negative sign (-ve) indicates the clockwise angles (when robot leans backward).

Using Gyroscope
Angular velocity along y-axis (pitch axis) is required to measure the inclination of robot using a gyroscope. The Value of a gyroscope with respect to Y axis (gyroY) was obtained from MPU sensor. gyroY value is converted to degrees per second and then converted value is multiplied by 0.005 to obtain angle travelled in loop time (i.e. 5 milliseconds). Finally, calculated angles are added to formerInclination ( ) to obtain presentInclination ( ).

PID Controller
PID is abbreviation for Proportional, Integral, and Derivative. Combination of these three controllers will produce a control signal (Fig. 16). The P-controller gives an output, which is proportionate to the deviation ( ).
For the developed TWR, presentInclination ( ) is represented by deviation (Fig. 17). The P-controller has limitation in the form of steady state error. Further, I-controller is required to eliminate the steady state error. It integrates the deviation over a period until it reaches to zero. Overshoot is the limitation of I-controller. The Dcontroller overcomes above limitations by predicting future behavior of deviation ( ). Its output depends on rate of change of deviation with respect to time, multiplied by derivative constant (K d ). Combining all these results, output can be generated, which is used to drive the stepper motors.

Tuning methods of PID Controller
Various methods 31 are developed to tune PID controller till now such as trial and error method, Tyreus-Luyben method, Damped oscillation method, Zeigler-Nichols method, etc. For developed TWR, trial and error method is used to tune PID constants. In this method, values are tuned when system is working. Here, first K i and K d values are set to zero and then, K p value is increased until robot started oscillating. Afterwards, K i value is adjusted to reduce oscillations and K d value was adjusted to obtain fast response 32 . Table 5 is also taken as reference while tuning PID values. Finally, Kp=30, K i =1 and K d =1 value is obtained.  Table 6   From the Fig. 18, it is clear that PID output variable is limited to 800 µs for inclinations greater than or equal to 30 0 and -800 µs for inclinations lesser than or equal to -30 0 . Equation in the form of pulse width is written to drive stepper motors from PID output value. It means that the pulse width will be changed according to PID output variable which in turn changes speed of motors (which is proportional to inclination angle). When inclination of robot is less, it requires less speed (i.e. more pulse width) and when inclination of robot is more, it requires more speed (i.e. less pulse width). Therefore, different pulse width is provided in code for different range. 800 pulse width (in µs) is supported for 0 0 to 10 0 inclination and 300-pulse width (in µs) is supported for  (Table 7).  [5,11]. Also, Height of developed TWR is 17.6 cm which is almost 1/4 th developed by Grasser et al. [5]. Further, Wheel to wheel distance is 16.6 cm which is half of 32.5 cm in case of robot developed by Bature et al. [11]. Thus, developed TWR is light in weight, smaller in size, runs on simple code with no performance loss and less costly (Table 7).
Further, Kalman filter can be used to achieve smoother data from sensor, PID with fuzzy logic or LQR controller can be used for better control and wireless communication with robot can be implemented via

Bluetooth or
Wi-Fi module.

Availability of data and materials
All the data and materials are included in these manuscripts.

Competing interests
There is no competing interest involved for any author in this manuscript.

Funding
List of Figures   Fig. 1 CAD model of Self-Balancing Robot