PI controller implementation for the two wheels of a differential robot using NI-MyRio

Introduction. Computational power improvement throughout the time combined with the overall technology advancement has allowed the development and use of robotics for several applications, such as supervision in hazardous places, transportation, vigilance, tourism guiding and, cleaning, among others. The mobile robotics field industry is not yet visible in Brazil, since there is no expressive national manufacturer of a platform for robotics development and programming. Objective. Thus, this article aims to show the development of a mobile robot to be used in internal and external environments for didactic purposes and as a development platform. Methodology. The development of a mobile robot includes hardware and software design, and, in this last group, there are the speed controllers, which are an important part of the robot design and building. In our article, it is implemented a PI controller in an embedded system of National Instruments, called NI-MyRio. This system is programmed in LabVIEW and embeds speed control for the wheels, besides the encoders reading. Additionally, it is connected to an Ethernet network, allowing supervision and control from one or more computers in the same network. Results. It was possible to model the wheels and to configure the PI controller by using such models and the internal control model method. In the experiments, it was possible to prove the functionality of the controllers satisfactorily. Conclusion. In conclusion, using the methodology described above, it was possible to model, build, and evaluate the robot and the controller, fulfilling the project requirements.


Introduction
In the last decades, robotics has gained attention in industrial applications, aerospace, and security fields, and even accompanying elderlies (Souza, 2005). Recently, the number of mobile robots increase considerably in industry, and they perform several tasks, such as working in warehouses and controlling the inventory (Faisal et al., 2013). The control systems are present in industrial processes and home appliances, besides being an important part of communication, aviation, logistics, and robotics (Manyika et al., 2013) e (Simoens et al., 2018).
A differential robot is a small autonomous vehicle with differential traction, which means that they have two independent motor wheels, as shown in Figure 1. The motor can be connected to the wheels using different transmission rates, and the terrain can also have an impact on the performance of the wheels, since it may be responsible for slipping as in a sandy or muddy place (Ben-Ari & Mondada, 2018). The differential traction has some advantages, such as the simplicity of having just two motors without additional components to determine the direction, which is defined by the behavior of the motors combined (Y. Abdalla & I. Hamzah, 2013). An autonomous robot should execute intrinsic maneuvers with simple movements. Therefore, the differential transmission is preferred, since it can easily spin into any direction and then, move linearly in that direction (Ben-Ari & Mondada, 2018).
The application of the PID controller (Proportional-Integral-Derivative) based on the difference among the reference value and the response of the system has appeared in the 1940s, and, since then, it has become one of the standards of the control strategies in the processes in both academy and industry (Åström, 2002;Astrom & HÄgglund, 2006). In our article, the PI will be implemented in the embedded system NI-MyRio, which is programmed in LabVIEW. The control system of our robot requires fast and precise positioning, which is only possible when the controllers have a good performance, independently of the complexity (Sharma et al., 2017). It will be applied two PI controllers, one for each wheel, to control the speed of the wheels of a differential robot. To allow an automatic speed control of the differential mobile robot, which, in our case, includes pulleys and belts coupling, it is important to have a parametrization and fine tuning of the controllers.
The controllers are tuned by the internal model control method using MATLAB and LabVIEW to perform simulations and implementation of the controllers (Paiva et al., 2016). Through these practical tests, it will be made the tune refining. The goal of this work is to implement a PI controller to control the speed of each wheel of a differential robot, with empirical evaluations. Research, Society andDevelopment, v. 11, n. 2, e38211225857, 2022 (CC BY 4.0) | ISSN 2525-3409 | DOI: http://dx.doi.org/10.33448/rsd-v11i2.25857 3 1.1 Differential Robot Figure 1 shows the top view of the differential robot. This kind of model behaves in the same way our robot does and is mathematically equivalent, although there is a difference in the construction that will be further explained in Section 2. The robot head is indicated by the speed vector . In the model shown, it is considered that both motor wheels are identical, with radius , and independent actuators. The distance between the wheels, also called virtual axis, is 2L.  (Tommasi et al., 2015).
The robot pose is defined by its position in the space and its orientation. Mathematically, it can be described as shown in Equation (1): , ( where is the robot angle orientation and is the robot position in the Cartesian System. Point C is the robot center of mass, and it is used as a reference point (Tommasi et al., 2015). In the rear part of the robot, there is a castor wheel used to give complimentary support to the whole structure without interfering directly in the robot's movement.
The robot moves in a straight line when both wheels have the same speed, which means , where is the right wheel speed and is the left wheel speed. If both speeds are positive, the robot moves forward; however, if both speeds are negative the robot moves backward. To allow the robot to make curves, the right and left wheels must have different speeds. To rotate right (clockwise), the left speed should be greater than the right speed ( ). On the other hand, to rotate left (counterclockwise), it is necessary the opposite, which means that the right wheel speed should be greater than the left wheel speed ( ) (Ayres et al., 2017).
Due to its nature and construction, this differential robot has nonholonomic constraints, which means it cannot move laterally. To reach lateral points, it should make a combination of maneuvers always moving forward or backward and making rotations. In short, it means that displacements directly over the x-axis are not allowed, since the wheels do not move only over this axis. The goal of this work is to present the strategy, highlighting its theoretical aspects and describing the steps needed to implement such control strategy. Furthermore, the potentials and limitations of this strategy are also analyzed, focusing on its application of autonomous navigation and programming.

Methodology
This work shows a physical structure of a robot that has the goal of autonomous navigation, based on conditions and application techniques that were gathered and compiled from a systematic revision of the literature (Romero et al., 2014). The methodology used is based on designing the robot structure and find the closest model approximation for the real world. All the research and experiments were made in the Grupo da Automação Industrial laboratory (GAIN), located in Instituto Federal do Espirito Santo (Serra -Brazil). The research is of qualitative nature, designing the robot, finding an accurate model of the robot for the real world, and programming a proper controller to allow the robot to be used as an educational mobile robotic platform.
The robot itself is composed of wheels, motors, encoders, and a metallic structure that houses all the embedded systems and devices. Additionally, there are batteries, voltage regulators, power drivers, and encoders, being the last one connected to a NI-MyRio device, from National Instruments, which controls each wheel. Following, it was built the algorithm that implements the PI controllers that actuate on each wheel separately, considering the robot model and its non-holonomic constraints.
One of the greatest challenges of mobile robotics is navigation. Thus, for each phase cited previously some speed evaluations were made in the differential robot to ensure the controller is acting properly.

Robot Structure
The designed robot has two independent parallel motor wheels in the front part and two wheels in the rear part that are connected with their respective in the front part. In other words, there are motor wheels in the front part and pulleys that connect the rear wheel to their respective motor front wheels. The two wheels are similar with a radius of 12.5 cm and the front wheels are separated by 37 cm (which is twice the distance between the centerline of the robot and each wheel). The mechanical structure of the wheels of one side is represented in Figure 1. There is a mirrored structure for the right part. The behavior and mathematical model of this robot are the same as the robot explained in Section 1.1, and, therefore, the same modeling used for that robot can be applied to this one.
Thus, due to its construction and mathematical model, our robot is differential with nonholonomic constraints, which means that some points in the Cartesian plane cannot be reached directly, such as those that require the robot to move laterally.
To achieve some points on the plane the robot should combine rotational and translational movements by controlling the left and right wheel speeds.
In the design and conception of this robot, it should be able to move in both internal and external environments. Due to this feature, the robot should be robust, and its wheels should be neither large (to avoid problems in internal environments) nor small (to be able to move in external environments). Therefore, an intermediary size was chosen, which in the design of this robot corresponded to 25 cm in diameter. Another important specification of the robot is the maximum linear speed, which is 1.1 m/s. The robot design considered this important feature, and the robot has the sizes needed to allow the maximum speed of 1.1 m/s, as shown in Figure 2.
To build this robot it was taken as reference commercial robots, such as the one shown in (RobotShop, 2022) and the robot built by the Industrial Automation Group (GAIn) from the Federal Institute of Espirito Santo, in Serra, Brazil.
Additionally, in the robot design and conception phase, it was considered the availability of motors in the market. Therefore, it was chosen the gear reducer MR 910-VE-120 RPM -12Vcc with a torque of 32.8 kg.cm. However, due to the motor pulleys size relation, there is a speed reduction, which increases the torque in the wheels to 45.4 kg.cm .
where is the rotational speed of the motor pulley, is the speed of the wheel pulley, is the motor pulley diameter, is the wheel pulley diameter, and is the robot left wheel size (the right part of the robot has a mirrored structure with the same features and dimensions). Thus, using the values of , and , it is possible to obtain the value of , which, as aforementioned, is the rotational speed of the wheel. After obtaining such relations, it is possible to calculate the maximum wheel speed , which corresponds to 1.1 m/s.
There are two pulleys on each side of the robot. One is the motor pulley that has a transmission relation with the other pulley connected to the encoder, which, in its turn, counts the number of pulses and, consequently, calculates the wheel speed.
Each wheel has its encoder to measure the speed and the information of the four wheels are processed in the embedded system of NI-MyRio that uses an onboard Xilinx FPGA, thus allowing the encoder algorithm processing.

Control logic and programming
The way the PID controller was implemented followed the ideal configuration, as presented in Equation (3) In a controller with an integral part, if the actuators reach their operational limits, the integral part keeps increasing (accumulating) the error without making any change in the actuator behavior, since it has already reached its maximum capacity. When the error changes its sign (from negative to positive or vice-versa), the integral part provokes a delay in the control action. Due to this feature, known as Wind-up, the process tends to become slow and oscillatory. To avoid this limitation, it was used a PID with anti-wind-up of type back-calculation, as shown in Figure 3, which has all variables in the time-domain (Atherton, 1995;Rundqwist, 1991;Vrancic & Hanus, 1996). The time need for the input integrator to reach zero is determined by the gain , where can be viewed as a time constant that determines how fast the integer input will reach zero. Thus, in the first moment, the choice of small values for can be an advantage. However, that choice should be made carefully, especially in systems with derivative action (Bernardes, 2017). Considering the PID with anti-wind-up configuration, Equation (3) was rewritten as shown in Equation (4).   The measurement of each robot wheel speed and the odometry is shown in the algorithm of Research, Society andDevelopment, v. 11, n. 2, e38211225857, 2022 (CC BY 4.0) | ISSN 2525-3409 | DOI: http://dx.doi.org/10.33448/rsd-v11i2.25857 9 Figure 5. The speed calculation was made by counting the number of pulses in a certain amount of time; thus, knowing the distance related to a single encoder pulse, it is possible to compute the overall traveled distance. Once the information of the distance is known, it is only needed to divide the amount of time needed to travel that distance to find the speed (Bezerra, 2004), as shown in Equation (5). (5) where: is the number of pulses in the time interval and is the distance traveled by the wheel during the time needed to generate a single pulse. In Figure 5, it is shown the algorithm that computes the speed for each wheel, and, at the same time, applies a first-order digital filter to avoid noise (Romero et al., 2014). Source: Own authorship.

Results and Discussion
In this section, it is shown how the methodology applied allows the system to be designed with an adequate controller, which demonstrated to be adequate for the proposed tasks of being able to be controlled moving in a straight path.

Robot Motor Wheels Modelling
In this section, it is presented the models of each wheel that are used as references for the PID controllers' tuning. The input signal chosen to model the wheels was the step response. To obtain the individual model of each wheel the robot was suspended at a stable speed and the value of the initial control action u was further incremented applying a step signal of 20 units. This procedure was made for both right and left motor wheels.

The left wheel model
To obtain the left wheel model it was set a constant initial control signal u in 30 cm/s and, following, it was applied a step of 20 units (20 cm/s). The value of the signal was incremented from 30 cm/s to 50 cm/s, as shown in Figure 6. The features of the speed signal of the wheels were defined as a base to model the process and the tool used to find this model was the ident toolbox from MATLAB. To model the process response, it was used a first-order model with delay, represented by Equation (6).
where is the proportional gain, is the time the process response reaches 63% of the final value, and is the delay of the model to start reacting to the input signal change. To increase the amount of data to be used in the model identification, it was made an interpolation, which increased the data size by 10 times. Thus, the left wheel model found can be written as shown in Equation (7). .
(7) Figure 7 shows the expected and real results of the model found using the process response to a step input, while Figure 8 shows the variation of the input signal. This model was the one that obtained the better fit to the data collected and, additionally, it was the one that adjusted better to the real model behavior, thus helping to adjust better the controller.

Figure 7 -
Step response and model of the left wheel. The "estimated" (blue) line shows the expected modeled output, while the "real" (black) shows the output given by the robot wheel.
Source: Own authorship. The characteristic equation of the right wheel behavior is given by Equation (8).
(8) Figure 9 shows the expected and real results of the model found using the step response for the right wheel. Similar to the left wheel, the mathematical model for the right wheel has high correspondence to the collect data, being close to the real model.

Figure 9 -
Step response to the right wheel. The "estimated" (blue) line shows the expected modeled output, while the "real" (black) shows the output given by the robot wheel.

Tuning
The method chosen to tune the PID controllers was the Internal Model Control (IMC). In IMC, it is defined the performance criteria, represented by λ, to tune the controller considering the features and behaviors of the actuators (Campos, Mario César Massa;Teixeira, 2010). Therefore, a more robust tuning was applied using a high value of λ (about three times the time constant value of the process in open loop). Thus, the parameters of the PID controllers were determined as shown in the scheme of the IMC used to tune the controller presented in Figure 10. Then, it is possible to find the closed loop transfer function, shown in Equation (9), without the process model : IMC is used to determine the best tunning for the controller to the input step response of the system, represented by a first-order result transfer function in closed loop with a time constant , as shown in Equation (10).
The factor , which is the only needed parameter to adjust, is the performance criteria of IMC and it defines how fast it is desired that the output follows the established setpoint. It was defined that equals 1 because it follows the time response in open loop. In Table 1 it is shown the calculations to find the PI or PID parameters using the process model and the value.
The obtained parameters are shown in Table 2. Source: Rivera et al. (1986). The dead time of the model was 0.02 s and, due to this reason, it was necessary to increase the constants and to higher values (especially ) and, thus, the system behaved with high variability. Therefore, it was made a manual adjustment and it was determined the parameters of the PI controllers, as shown in Table 3. Once the PI parameters were set and all the algorithms coded and uploaded to the system, the robot was evaluated.
The data acquired using LabVIEW was, then, exported to Excel to obtain graphics of both wheels in closed loop. Some setpoints were defined to make the robot move in a straight path in the GAIn laboratory, which has a smooth floor. The setpoints used were 13 cm/s, 30 cm/s, 60 cm/s, -20 cm/s and 25 cm/s in the trials performed in the laboratory that are displayed in Figure  11 and Figure 12. The results were considered satisfactory, with small errors and with a constant speed. The time response, however, had a short delay due to inertia. However, this did not affect the control system. Furthermore, it was placed a filter to minimize the noise effect. Figure 11 -Closed loop response for the right wheel. The blue line is the setpoint, the gray line is the controller output signal, and the orange line is the wheel speed.

Conclusion
In this work, it was developed and implemented PI controllers for each motor wheel of the robot and the results showed good performance of the PI controllers. The proposed controllers allowed the robot to reach the speeds they were projected to, and the first set of motor/reduction and power drivers worked properly. Readings from the wheels by the encoders were correct, showing that the FPGA functions in the embedded system NI-MyRio could make the correct measurement of the speed. Furthermore, the embedded system did not show memory issues, and the power drives were correctly triggered.
A PI controller was implemented to control the drive speed in the differential robot that was designed and built. Some improvements were made in the drives, electronic circuits, and embedded instruments of the differential mobile robot.
Additionally, implementations of the PI controller to control the wheel speeds generated reliable results to control the robot.
The experiments using the PI speed controllers tuned by IMC allowed maneuvers closer to the reference (setpoint). Thus, as a conclusion, we found that the IMC tuning allowed an optimal performance and adequate control of the mobile robot.
As future works, this platform will be used for obstacle avoidance, and to build maps of internal environments by doing SLAM (Simultaneous Localization and Mapping), thus increasing the possibilities of the platform for training in automatic control, instrumentation, and programming. To allow this, the robot will receive more sensors, such as laser sensors and cameras, and new codes will need to be implemented.