Design and Development of Unmanned Surface Vehicle for Meteorological Monitoring

In view of the paucity of hydrometeorological data, inefficiency and high cost of manual detection, a design scheme of meteorological monitoring unmanned surface vehicle (USV) based on STM32 MCU (Microcontroller Unit, which is also known as Single Chip Microcomputer) is proposed in this paper. The path planning is designed by combining the image data acquired by camera with improved RRT-path algorithm (rapidly-exploring random tree algorithm based on auxiliary path), and then motors are controlled so as to realize autonomous cruise control of USV using the incremental PID algorithm. In addition, the design can also realize real-time monitoring of meteorological data detected by meteorological sensors on the USV through upper computer. Compared with the traditional scheme, the path planning, autonomous cruise is as well as online monitoring function of the scheme presented below enable USVs have full autonomous capability to realize on-line monitoring of meteorological data.


Introduction
Hydrometeorological data has a wide range of needs in industries such as fisheries, tourism and meteorology, and the demand of the precision and timeliness of hydrometeorological data is substantial increase now. Besides, due to the wide range of waters in our country, the range of hydrometeorological data need to be collected is large. If the method of manual collection of water samples is adopted, which may cause delay in updating the data, the safety of operators is not guaranteed in many harsh environments.
The path planning algorithms used by the robot include A* algorithm, artificial potential field algorithm, mean field annealing algorithm and RRT algorithm et al. The RRT (Rapid-extended Random Tree) algorithm is most suitable for use in nonholonomic motion planning and motion planning for multi-self-robots [3][4][5]. But it has the disadvantages of lacking stability and slow convergence [6]. This paper proposes a fastspreading random tree algorithm based on auxiliary paths to improve the above disadvantages.
Online monitoring of meteorological data has great advantages, and one of the key points of this technology is data transmission [7]. After studying various communication technologies such as Beidou satellite, digital radio and GPRS [8][9][10][11]. We found that the 4G mobile communication technology can meet requirements of low use-cost, long transmission distance, high transmission speed and low latency [12]. Therefore, this design will use 4G mobile communication technology to achieve the goal of online monitoring.
To sum up, this paper proposes a meteorological unmanned ship with path planning, autonomous cruise and online monitoring. Firstly, the path planning function is implemented by the RRT-path algorithm. Secondly, the autonomous cruise function is implemented by the incremental PID algorithm. Thirdly, the online monitoring function is mainly using 4G mobile communication technology to implement wireless transmission function. Finally, the upper computer is built by LabVIEW, which has the ability to extract, display, process and store meteorological data.

Overall Design
The design of meteorological monitoring USV proposed in this paper is mainly composed of three subsystems, which are USV path planning system, USV autonomous cruise system and USV online monitoring system. The USV is designed by stm32 MCU, which is connected with the motor, camera, ultrasonic sensor, electronic compass and various meteorological sensors. Firstly, the STM32 uses an ultrasonic sensor to capture the distance between the USV and the obstacle, then it uses the OV7725 camera to collect the information of obstacle. After the collected information being sent to the server through the data transmission system for image processing, the path planning is performed by using the RRT-Path algorithm. In the end, the planned path is sent to the STM32 which through the data transmission system to let the USV execute the path. Secondly, the STM32 uses the electronic compass to calculate the coordinates of the USV and the angle between the USV and the route. Then it uses the incremental PID algorithm to control the speed of the motor which can achieve the goal of the autonomous cruise. Finally, the STM32 can use meteorological sensors to collect meteorological data such as temperature, humidity, air pressure, wind speed, and wind direction. And the data will be sent to the upper computer through the data transmission system. What's more, the data transmission system is built by 4G DTU, and the upper computer has the ability to extract, display, process and store meteorological data. The diagram of the overall framework is shown in Fig. 1.

Overall Design of Path Planning System
In the path planning system, the system uses the OV7725 to acquire image and use the HC-SR04 ultrasonic sensor to measure the distance between the USV and obstacle. When the distance is within the safe range, the USV is not threatened by obstacles. But when the distance between the obstacle and the USV is less than the preset threshold, the STM32 MCU controls OV7725 camera to collect the obstacle image and transmits the obstacle information to the server via the 4G DTU. After the path planning is performed by the RRT-path algorithm on the server, it is retransmitted to the STM32 MCU via the 4G DTU. Then the USV can start the obstacle avoidance navigation according to the planned path. The structure of path planning system is shown in Fig. 2.
The specific process of path planning system operation is shown in Fig. 3.

Algorithm of RRT-Path Path Planning
S.M. LaValle proposed rapid-expansion random tree (RRT) algorithm in 1998. This algorithm can perform path planning without environment construction, but the basic RRT algorithm is slightly cumbersome, heavy workload, high search cost and low stability in the stage of constructing random tree. Therefore, in order to improve the efficiency of path planning, this system uses the RRT-Path algorithm which is based on the auxiliary path to plan the path. The algorithm uses an auxiliary path that attracts trees growing along the path from the initial configuration to the target configuration. Besides, this algorithm avoiding the purposeless exploration of the global environment and reducing the computational cost to save search costs.
The basic idea of the algorithm is described below. Firstly, system constructs a feasible auxiliary path from the starting point to the target point by using the obstacle avoidance algorithm. Secondly, the system explores and randomly samples the surrounding environment along this path and guides the random tree to grow towards the target point. It avoids the purposeless sampling in the global environment to build a  : Process of path planning system operation random tree, which improves the efficiency of the algorithm greatly. Finally, when the random tree is close enough to the target point, the target coincides with the target on the auxiliary path. Then the random tree reaches the target point, and the auxiliary path completes the guiding task which means the end of path planning. The state of RRT-Path algorithm extended phase diagram is shown in the Fig. 4.
The specific workflow of the algorithm is shown below. First of all, the path planning function PlanPathRRT() and the tree RRT is initialized to add the location of the USV to the tree as the initial state, that is, which is the root node. Then, according to the auxiliary path, when the random node generating function generates a random node around the path, the collision detecting function InCollision_Node() is used to check whether the point qrand collides with an obstacle in the space. If the point is far from the obstacle, system will find the node qnear closed to the point in the tree. Then the collision detection function InCollision_Edge() will check whether the straight path between the sampling point qrand and the nearest point qnear in the tree has a collision. If the straight path doesn't collide, system will use the node add function AddNode() to directly add the sample point qrand to the tree which use the closest point qnear as its parent node. Else if the straight path collided, this point will be thrown. What's more, the system uses the step size adjustment function each time to take the minimum step size as a criterion for generating random points.
Finally, a node is added to the tree each time. When the distance of the node from the target position qgoal is less than a certain threshold distance, the system will check whether the target point qgoal can arrive from the added node in a straight path. And if the target location is reachable, system will add the target location qgoal to the tree with the nearest node as its parent. At this point, the path planning is complete. Besides, if the target location is still unreachable, the system will sample other points.

Process of Path Smoothing
After the system finds the path, it can apply path smoothening to make a smoother and more direct target route. Firstly, the sample points between nodes on the entire path are iterated by using the path smoothening function which is SmoothPath(). Secondly, the system checks whether two points can be connected directly to reduce the length of the entire path. Thirdly, the system makes the path shorter and smoother by removing the redundant points between the two points and connecting the two points directly. As shown in Fig. 5, the red path isn't smoothed and the green path is smoothed.

Simulation and Analysis
This paper uses MATLAB to design a simulation platform. Firstly, the starting point of the experimental environment is represented by a green circle, and the target position is represented by a red circle. Secondly, the obstacle is represented by a blue circle. Thirdly, the area where the USV will sail is the area surrounded by a thick black line. Fourthly, the side length of each grid is set to 1, and the radius of the circle is set to 0.5. Fifthly, the coordinate of starting point is (-3, 10), and the coordinate of target position is (1, -4). Sixthly, three rectangles composed of blue circles represent obstacles, and USV can only sail in the area restricted q init q near q rand Figure 4: The state of RRT-Path algorithm extended phase diagram by the thick black line. In the simulation, the random expansion tree is represented by a pink line that the width is 2; and the unsmooth path is represented by a red line that the width is 3. Besides, the smoothed path is represented by a green line that the width is 5. The specific working environment of USV is shown in Fig. 6.
When the random step length (param.res) is equal to 0.3 and the distance parameter (param.thersh) between USV and destination is equal to 0.5, the planned path (red) and the path (green) smoothed by path smoothening function are shown in Fig. 7a (The number of times is 619). As can be seen from the planning results, the algorithm overcomes the drawback of being trapped in a local minimum.  It can be seen from the above two simulations that the smoothed path shortens the path length, making the path from the starting point to the target point shorter and smoother. But the repeatability of the planning is poor.
When the random step size (param.res) is equal to 0.7, and the distance parameter (param.thersh) between USV and destination is equal to 0.5, the smoothed path is shown in Fig. 8 (the number of iterations is 399).  It can be seen that the probability of decreasing the number of iterations is inversely proportional to the increase of the random step size.
When the random step size (param.res) is equal to 1, and the distance parameter (param.thersh) between USV and destination is equal to 0.5, the situation of fail to avoid obstacles is shown in Fig. 9.
If the random step size is larger than the free space range that can be navigable, when the extended random tree finds the path, the path will directly pass through the obstacle which means the algorithm loses the ability to avoid obstacles. Therefore, the random step size needs to be set reasonable by the distance between USV and obstacles.

Overall Scheme Design of Autonomous Cruise Control System
The autonomous cruise system uses STM32 MCU and electronic compass to calculate the coordinates and heading of USV. Then the MCU calculates the angle between the heading of USV and the target route. Finally, the incremental PID algorithm is used to precisely adjust the state of motors, and USV is always allowed to sail along the target route. The block diagram of overall design is shown in Fig. 10.
The design flow of this system is as follows. Firstly, the STM32 MCU reads coordinates acquired by the electronic compass after the system is powered. Then MCU processes the angle between the heading of USV Figure 9: The case of fail to avoid obstacles Figure 10: The block diagram of overall design and the target route. If the direction angle is greater than the preset value, the MCU will adjust the duty cycle of the PWM which is equal to adjust the motor speed. If it is not greater than preset value, the MCU will continue to acquire coordinates. This is easy to implement [13]. The overall flow chart of software design is shown in Fig. 11.

Algorithm of Incremental PID Control
The incremental PID control algorithm is a control algorithm that performs PID control on the increment of the control amount. In general, the basic PID formula is shown in formula (1): In the above formula, the u(t) is the output of controller, and the e(t) is the input of controller. The Kp is the proportional amplification factor of controller. The Ti is the integral time of controller. And the Td is the differential time of controller.
Let u(k) be the output value of the controller at the kth sampling time. So, a discrete PID formula can be deduced.
In the above formula, K i ¼ K p T =T i is the integral coefficient and K d ¼ K p T d =T is the differential coefficient. The formula of incremental PID can be deduced by formula (1). It is shown in formula (3).
Furthermore, we can rewrite the formula (3) into the formula (4).
In the above formula, If the appropriate coefficient is selected, it is only need to calculate deviation values a few times before. Then the increment (Δu(k)) can be deduced from the formula (3) or the formula (4).

Implement Incremental PID on STM32
Formula (1) is written as a form that is easy to program in STM32. It is shown in formula (5).
U ðkÞ ¼ U ðk À 1Þ þ K p ½eðkÞ À eðk À 1Þ þ K i eðkÞ þ K d ½eðkÞ À 2eðk À 1Þ þ eðk À 2Þ DU ðkÞ ¼ U ðkÞ À U ðk À 1Þ (5) The system uses PWM wave to control motors. The output of the PWM wave in STM32 MCU is equal to output by TIM3 timer. And the USV only needs two motors to drive. So, the TIM3 timer will directly outputs two PWM waves to drive USV. What's more, the MCU uses TIM1 timer and TIM4 timer to capture two feedback signals. And use TIM6 timer for PID sampling and processing.
The specific control process is as follows. Firstly, the MCU set initial values of the PID algorithm to calculate the current error, and the values are Kp, Ti and Td. If it is within the allowable range, the incremental calculation (ΔP(k) = P(k)-P(k-1)) will be performed, and the PID will calculate sampling values. Then MCU will store error values for next calculation. If the sampling time is reached, the interrupt will be updated after the interrupt processing. Then the TIM1 timer and TIM4 timer will start capturing PWM waves and calculating the frequency. Finally, MCU will output PWM duty cycle. The duty cycle in this design is represented by a number [14]. The flow chart of PID program is shown in Fig. 12.

Overall Plan of Online Monitoring System
The data acquisition system of online monitoring system is made up of STM32 MCU, DHT11 temperature and humidity sensor, BMP180 air pressure sensor and HS-FS01 wind speed and wind direction sensor. The communication system is made up of 4G DTU, base station, server, virtual serial port software and VISA serial communication interface. The data monitoring system is made up of the upper computer which is built by LabVIEW. Besides, the adapter board is used to connect the MCU with The working process of online monitoring system design is as follows. Firstly, STM32 MCU is connected to each sensor and receives the meteorological data which are collected by meteorological sensors. Secondly, the adapter board will convert the TTL level outputted by the MCU into an RS232 serial port signal and send it to the 4G DTU. Thirdly, the 4G DTU packs the data and sends it to the base station. Fourthly, the server obtains the data from the base station and sends it to the virtual serial port software for data conversion. Then the upper computer can process the received data and send control signal to MCU. The flow chart of online monitoring system is shown in Fig. 13.

Design of Data Acquisition System
The data acquisition system can acquire meteorological data such as temperature, humidity, air pressure, the wind speed and wind direction. The system adopts DHT11 to acquire temperature and humidity. The system adopts BMP180 to acquire air pressure. And the system adopts HS-FS01 to acquire wind speed and wind direction.
The DHT11 temperature and humidity sensor communicates with the STM32 MCU via a single bus. The BMP180 air pressure sensor communicates with the STM32 MCU via the I2C protocol. It uses realtime temperature to compensate for the air pressure value, improving accuracy. HS-FS01 sensor is a wind speed and wind direction sensor of voltage output type.
The operation process of the data acquisition system is as follows. Firstly, the STM32 MCU performs an initialization operation. After the initialization is completed, the MCU starts reading the data of each sensor. When the MCU reads all the data, it will integrate all the data and output the integrated data through the serial port. Finally, the 4G DTU and the STM32 system board are connected together using an interposer board that converts TTL levels and RS232 signals.

Design of Communication System
When the STM32 MCU sends the serial port data to the USR-G780 (4G DTU), the USR-G780 can convert the serial port data into a TCP packet and send it to the base station. Then the data will be sent from the base station to the server, which will send the data to the virtual serial port software. Finally, the virtual serial port software converts the TCP data into serial port data and sends it to upper computer. The transmission format of the data between the USR-G780 and the virtual serial port software is TCP data packet, and the transmission format between the virtual serial port software and the upper computer is serial port data. The overall architecture of communication system is shown in Fig. 14. The serial communication interface of the upper computer is written by VISA node function which is built in LabVIEW. The working principle of the VISA serial communication interface is as follows. After configuring the parameters of the serial port by "VISA Configure serial port", use the "VISA Read" and "VISA Write" in the loop to read or send the serial port data respectively. Finally use "VISA close" and "Clear errors" to end the communication of the serial port. The program of VISA serial communication interface is shown in Fig. 15.

Design of Data Monitoring System
The data monitoring system has functions of data display, data storage, data processing, data query, USV control and autonomous cruise. The main operation interface of data monitoring system is shown in Appendix A.
When the system is running, the operator can set the serial port parameters in the main interface and click the "Read Data" button. If the serial port has a signal, the system can read serial port data. Firstly, the system extracts the serial port data and displays the result on the main interface. Secondly, the system processes the data that has been extracted. Thirdly, both of being extracted data and processed data are automatically stored in the corresponding document. Fourthly, the system will judge data at the same time. And if it is an abnormal value, it will be rejected and will not be further processed. Fifthly, if the operator clicks on the "temperature alarm" button and sets the alarm value of temperature, an alarm will be issued after the temperature exceeds the preset value. Sixthly, if the operator clicks on the "autonomous cruise" button, the system will send a command to the USV, and if the operator intervenes in the speed and heading of the USV during this process, the autonomous cruise will be terminated. The specific flow chart of data monitoring system is shown in Fig. 16. This paper takes the air pressure value of BMP180 as an example to explain the process of extracting the data of each meteorological sensor in upper computer. Firstly, the "String subset" function is used to intercept 5 characters as the air pressure value of BMP180. Secondly, the "Fract/Exp string to number" function is used to convert a string to a numeric value. Finally, the "Quotient & Remainder" function is used to convert the numeric value to the correct air pressure value. Since it is necessary to save the above air pressure values, the "Number to fractional string" function is used to convert the correct air pressure value to the string.  Once the data has been extracted, the system uses the waveform chart control to display the air pressure realtime curve. The extraction process for data such as temperature, humidity, wind speed, wind direction, latitude, longitude and heading are similar to the extraction air pressure value. The program of data extraction is shown in Fig. 17. Some of the elements collected by this system have multi-group data. So, they can be fault-tolerant. Taking the altitude value as an example, the system performs fault-tolerant processing on the altitude values that is acquired by air pressure sensor and GPS sensor, which improves the stability of the data. The specific judgment rules are as follows: 1. The difference between the distances of the two sensors is greater than 0.5 m; 2. The output of one of two sensors is 0.2 m higher than the maximum value or 0.2 m lower than the minimum value. The program of altitude fault-tolerant is shown in Fig. 18.
The system uses "statistical" and "histogram" functions in LabVIEW to process extracted data. Taking the temperature value as an example, firstly, the "Feedback Node" and "Create Array" functions are used to generate a one-dimensional array. Then the system converts it into the dynamic data. Finally, the "statistics" function is used to count multiple statistics such as the total number of samples, average value, maximum value, and minimum value. And the "histogram" function is used to display temperature values as a histogram. The program of data processing for temperature is shown in Fig. 19.
In this system, the way to store data is described below. Firstly, the "Strip path" and "Build path" functions are used to save the file in the "historical data" folder of the path where the main function is located. Then the "Format Date/time string" function is used to extract the date. Finally, a onedimensional array created from each meteorological data and date is converted into a two-dimensional array by a "Feedback node" and stored in a spreadsheet. The program of data storage is shown in Fig. 20.
The operator can open the spreadsheet that needs to be queried by typing the file name. The process of querying historical data is similar to the process of storing data described above, except that the "write  : The program of data processing for temperature spreadsheet" function is changed to "read spreadsheet file" function. The program of query historical data is shown in Fig. 21.

Conclusions
The design proposed in this paper basically realizes the goal of designing and developing the meteorological monitoring USV. Firstly, the USV can use the camera, ultrasonic wave sensor and RRT-Path algorithm to realize the path planning function. Secondly, the USV uses coordinates which are acquired by the electronic compass to calculate the angle between the heading of USV and the target point. Then the incremental PID algorithm is used to adjust speed of motors to control the heading of USV. Thirdly, the USV can acquire meteorological data such as temperature, humidity, air pressure, the wind speed and wind direction. These data are transmitted through the communication system and they can be processed in the upper computer to realize the online detection function. The upper computer is built by LabVIEW, which has the ability to extract, display, the process and store meteorological data.
The program can be further improved on the following two points. Firstly, Multiple sensors are used to detect a certain meteorological value at the same time, which can improve the accuracy of monitoring data. Besides, this measure can also increase the stability of online monitoring. Secondly, use the hardware visualization extension provided by the ARM MCU to construct a secure display path between the applications and the display device [15], which can increase the security of communication system when transferring data.