Modeling of Automatic Sprinkler Irrigation Process Using Finite State Machine (FSM) and Proportional Integral Derivative (PID) Controller

In this paper, the real-time automatic irrigation system was designed to supply water to the root zone of plant only when soil moisture content goes below a certain level known as critical moisture content. Particularly, models for the DC motor driven centrifugal irrigation pump, sprinkler irrigation nozzle, plant water uptake process, a proportional–integral–derivative (PID) controller were obtained using analytical methods. Automatic control logic was designed using the finite state machine (FSM) concept to act as a supervisory controller for the real-time automatic irrigation system. The models for the different sections of the system were assembled on MATLAB workspace, and then simulated and tested to ascertain the workability of the system. Specifically, the model was simulated for 0.5 seconds and the step response and impulse response were also computed. The results showed that the system performance is quite suitable for the irrigation system because a response time of 2 seconds offer a 1.36 seconds rise time for the system to reach its peak unit amplitude of 1.06, although with a much longer settling time of 4.21seconds. The results also showed that 1.7145×10mmH2O/mmSoil was consumed by the plant within the simulation period. In all, the simulation results obtained showed that the irrigation system was able to supply the needed water to replenish the soil moisture deficit without frequent human intervention. The models presented in this research are useful for planning, designing and analysis of automatic irrigation system for mechanized farming.


Introduction
The moisture content is a major factor which affects plant well-being, especially in irrigated fields [1,2,3,4]. The decline of soil water content will result in the decrease of photosynthesis and plant cell expansion [5,6,7,8]. Taking this into consideration, well-defined automatic control logic needs to be developed for the system to adequately check the level of soil moisture. Presently, there are different methods of designing such automatic control logic for reactive systems. However, in this paper, the Finite State Machine (FSM) method is used to check the level of soil moisture content [9,10,11,12,13,14].
Furthermore, the entire control process of the real-time automatic irrigation system is based on the control of the voltage to the DC motor driven centrifugal pump as input and the moisture content of the soil as the output. This is achieved by first understanding the water uptake characteristics of the plant in question, the permanent wilting point, the saturated soil moisture content, and the field capacity of the soil in which the plant is being grown. Although the pump has a fixed maximum flow rate, a proportional-integral-derivative (PID) controller is used to maintain the water flow rate at a desired value [15,16,17].
There are several reasons why a conventional controller such as a proportional-integral-derivative (PID) controller is required in the sprinkler closed-loop. First, the sprinkler without a controller continuously output an increasingly high precipitation rate (gross depth) which is detrimental to the plant well-being in the long run. Thus, a PID controller is needed to achieve a reference pump flow rate and sprinkler gross depth which is the key parameter that affects the soil moisture content and the functionality of the entire irrigation system.
The detailed development of the PID controller for the for effective monitoring of level of soil moisture is presented. The various components of the control system are modelled and the simulated using MATHLAB/Simulink software. The simulation was done with maize as the case study crop. The system components were later integrated and the integrated system was simulated. This later steps was taken so as to identify any integration issues in the modelled system components.

Modeling of the Irrigation System Controller
The entire control process of the real-time automatic irrigation is based on the control of the voltage to the DC motor driven centrifugal pump as input and the moisture content of the soil as the output. This is achieved by first understanding the water uptake characteristics of the case study plant, the permanent wilting point, the saturated soil moisture content, and the field capacity of the soil in which the plant is being grown. Then, a PID controller is designed to maintain the pump flow rate at a specified and desired value.
Considering a unity feedback system, the output of the PID controller is equal to the control input to the plant, in time-domain as shown in Figure 1.
Considering Figure 1, the variable ( ) represents the tracking error, which is the difference between the desired input value ( ) and the actual output( ). This error signal ( ) will be sent to the PID controller, and the controller computes both the derivative and the integral of this error signal. The control signal ( ) to the plant is equal to the proportional gain times the magnitude of the error plus the integral gain times the integral of the error plus the derivative gain times the derivative of the error. The control signal ( ) is sent to the plant, and the new output ( )is obtained. The new output ( )is then fed back and compared to the reference to find the new error signal( ). The controller takes this new error signal and computes its derivative and integral again. The transfer function of the PID controller is found by taking the Laplace transform of Equation (1) with initial conditions at zero, gives; where is the proportional gain, is the integral gain, and is the derivative gain respectively. Introducing an N-order filter into the block diagram of Figure 1 to filter the derivative action of the PID compensator, therefore, Equation (2) yields; where is the filter coefficient which sets the location of the pole of the derivative filter. A proportional controller will have the effect of reducing the rise time and will reduce but never eliminate the steady-state error. An integral control will have the effect of eliminating the steady-state error for a constant or step input, but it may make the transient response slower. A derivative control, will have the effect of increasing the stability of the system, reducing the overshoot, and improving the transient response.

Design of Automatic Control Logic Using Finite State Machines (FSM)
The flow chart shown in Figure 2 shows the steps used in the design of the automatic control logic for the irrigation system. In order to define states for the automatic control logic, it is important to consider the process of soil water dynamics which clearly define the states of the controller. The flow chart in Figure 2 shows the necessary steps needed to realize state machine logic for the automatic controller. The mechanics of soil water movement and soil moisture growth are very complex processes that involve so many attributes and states. However, a few of these states will be used in this paper for the development of the automatic control logic (supervisory controller) in order to keep the controller fairly simple. The states that could be easily identified include but not limited to the following: Soil moisture content state (ii) Soil condition state (iii) Saturation state (iv) Wilting point state (v) Plant water uptake state (vi) Pump state (vii) Sprinkler state (viii) Leaching state (ix) Runoff state, etc. The first seven states are considered and some are combined together to form basic operating modes for the system. Using state flow chart semantics in Simulink, the following states were adopted for the automatic controller as shown in Figure 3.
As one of the sequential logic approach, the automatic controller used Stateflow chart to represent relationships among inputs, outputs and states of FSM representation of the irrigation system. The resulting chart in Figure 3 describes the logic necessary to control the behaviour of the system under study. Generally in state machine models, the next state is a function of the current state and its inputs, as follows: where ( ) represents the state at time step , ( + 1)represents the state at the next time step ( + 1), and represents inputs.
The main input to the automatic controller is the soil moisture which is measured by a sensor through a direct feedback to the unit. It is this value which the controller monitors to determine when to energize and de-energize the centrifugal pump to release water to soil via the sprinkler. Conversely, the output is the supplied voltage to the motor driven pump at every time step. However, the drive voltage value determines when any of the state becomes active, especially the pump states. There are conditions necessary to be met before the automatic controller issue out any voltage value.
The automatic controller is designed in such a way that once the sensor detects soil moisture value less than the stipulated soil wilting point, there is a major transition from the soil-moisture state to the pump-start state. Along this transition, there is an introduction of a temporal logic

Model Simulation, Results and Discussion
The models shown in this paper were modelled using Simulink modelling environment. Table 2, Table 3 and Table 4 show all the parameters used for the simulation of the system. These parameters are sourced from University of Uyo metrological centre, the Department of Soil Physics, Faculty of Agriculture, University of Uyo and some data books.
The model takes in a DC voltage, V a , as an input to the motor and the output is the flow rate, Q. The model was simulated for 0.5 seconds and the step and impulse responses were also computed. The parameters of the PID tuned and its performance are documented in Table 5 while the pump and sprinkler response with PID controller are shown in Figure 4.    The system performance is quite suitable for the irrigation system because a response time of 2 seconds offer a 1.36 seconds rise time for the system to reach its peak unit amplitude of 1.06, although with a much longer settling time of 4.21seconds. The overshoot of 0.737 % is low and depicts the absence of oscillatory behaviour which is an undesirable characteristic. However, the gain margin is negatively infinite because there is no phase crossover frequency at 180° phase margin. The phase margin is always positive and does not become equal to zero, and therefore the system is never unstable as a value of 63.3° was recorded at a frequency of 1 rad/s. The large value of the proportional gain makes the system bandwidth larger (the closed loop system is faster) without causing instability, but increasing it too much also makes the resonance peak higher, and at the same time the phase margin decreases. Therefore, if the system exhibits some un-modelled dynamics which produces some additional phase delays, a poor phase margin can lead to lack of robustness and therefore, instability.  Figure 5, the PID controller in the sprinkler closed-loop has somewhat affected the soil moisture and hydraulic conductivity profiles by causing the model to maintain a non-decaying growth. It is evident from the results that the soil becomes saturated with maximum soil moisture content of about 8.0×10 5 mm 3 H 2 O/mm 3 Soil and hydraulic conductivity of 0.015mm/s. The Soil moisture and hydraulic conductivity response with PID controller is given in Figure 5.
In the plant water uptake (Figure 6), there is a fast moisture absorption rate at the beginning of simulation which later reached a maximum value of 3.4773×10 5 mm 3 H 2 O/mm 3 Soil and the peak of the left over soil moisture content was 6.2855×10 5 mm 3 H 2 O/mm 3 Soil. Results showed that 1.7145×10 5 mm 3 H 2 O/mm 3 Soil was consumed by the plant within the simulated period. Since a well-defined reference sprinkler gross depth and pump flow rate have been determined by the PID controller, its values were used to simulate the overall irrigation system in which the automatic controller is incorporated, as shown in Figure 7. The simulation was carried out within an environment where ample sunshine was expected throughout the day. It was also assumed that the intervention of rain or excessive humidity would not be taken into consideration. The automatic controller was designed to sense the level of soil moisture in the soil when it first turns on. From Figure 8, at the beginning, and at whatsoever moisture is detected by the sensor, the pump is immediately energized with a low starting flow rate of 2.0×10 5 mm 3 /hr which yielded a gradual increase in sprinkler gross depth to 60mm, and this was maintained for the next 4hours. This means that for the period the soil was fed with water at a precipitation rate of 15mm/hr. Just above this time step, the automatic controller allowed the PID controller to fully supply the centrifugal pump with a complete reference achievable flow rate of 2.586×10 6 mm 3 /hr. It is at this flow rate that the sprinkler nozzles were able to supply the required water application gross depth of 800mm which was kept steady by the automatic controller for the next 4 hours with a corresponding precipitation rate of 200mm/hr. At approximately 8hours, the soil becomes saturated and the controller de-energized the pump and the flow to the sprinkler gradually reduced. It is noted from the graph that the gross application depth does not stop immediately, but keep decreasing for 2hours. This is possible as a result of the pressure and quantity of water still piled up within the line.

Conclusions
An automatic irrigation system for supplying water to the root zone of a plant only when soil moisture content goes below the critical moisture content level is presented. The monitoring of the soil water content was done using the finite state machine (FSM) control logic. The entire control process of the real-time automatic irrigation system is based on the control of the voltage to the DC motor driven centrifugal pump as input and the moisture content of the soil as the output. A proportional-integral-derivative (PID) controller is used to control the water flow rate at a desired value. The models for the different sections of the system were assembled on MATLAB workspace, and then simulated and tested to ascertain the workability of the system. The simulation results obtained showed that the irrigation system was able to supply the needed water to replenish the soil moisture deficit without frequent human intervention.