# Development of a Robotic Airboat for Online Water Quality Monitoring in Lakes
## 5 Control Software Development  
In order to manage the boat's functions, a software with an internet interface was developed, so that the task of setting the waypoints, monitoring the mission (boat trajectory and data collection), and generating reports was as simple as possible, by using the API of Google Maps. The software was developed using standard HTML5 (HyperText Markup Language 5 has the purpose of facilitating the understanding and maintenance of the code through XML, for the creation of documents that have a hierarchy of data, such as databases and texts), and the programming language PHP (Personal Home Page), with an interface to the database MySQL (a Database Management System (DBMS) that uses the Structured Query Language (SQL) as the interface.). The software consists of a single screen with sections where other screens are loaded, according to the menu buttons, and updated in real time. On the top part of the software, besides the menus, one has information about the mission and its georeferencing as latitude, longitude, next latitude, next longitude, number of waypoints, next waypoint, altitude, date, time, and number of satellites.  
At the beginning of the mission, the aerodrive was turned on, the boat began to move and its trajectory was displayed in real time, as it navigated, highlighting the waypoints delimited by the operator. The latitude and longitude GPS coordinates were read, as well as the registration of the first  
Figure 5: Airboat hardware architecture.  
waypoint stored in the database. With this data, the current boat distance to the next waypoint was calculated. If the distance was less than 5 meters, the next waypoint was loaded and the new distance was calculated again, based on the current GPS coordinates. During this period, the steering angle error (rudder direction) was calculated and corrected so that the boat moved straight, in the direction of the waypoint. This check was made every 1 second, until the boat was aligned with the target's rolling angle. This process continued until the boat had traversed all the recorded points of the mission. To calculate the distance, the Haversine formula was used, as shown in Equations (1)-(3).  
\[a=\sin^{2}(\Delta lat/2)+\cos(lat_{1})\cos(lat_{2})\sin^{2}(\Delta long/2) \tag{1}\]  
\[c=2a\tan(\sqrt{a}/\sqrt{1-a}) \tag{2}\]  
\[d=R\cdot c \tag{3}\]  
where:  
* \(\Delta lat=lat_{2}-lat_{1}\)
* \(\Delta long=long_{2}-long_{1}\)
* \(a\) is the square of half the length of the straight line connecting the two points (waypoints);
* \(c\) is the distance traveled on the surface of the sphere in radians;
* \(d\) is the distance as a function of.  
The rolling angle between the waypoints was calculated as shown in Equation (4).  
\[\theta=a\tan 2(\sin(\Delta long)\cos(lat_{2}),\cos(lat_{1})\sin(lat_{2})-\sin( lat_{1})\cos(lat_{2})\cos(\Delta long)) \tag{4}\]  
Once the distance \(d\) and the bearing angle \(\theta\) were calculated, the trajectory was defined by the GPS location data. The angle error was calculated by subtracting the current angle of the boat by the rolling angle of the next waypoint. The computed result was transferred to the rudder proportional control algorithm, by correcting the boat position until the error reached zero. The rudder correction angle algorithm was given by the equations shown in Figure 6.  
where:  
* error angle is the error of the current angle of the boat, relative to the bearing angle of the waypoint;
* target angle is the bearing angle of the waypoint;
* curr angle is the angle of the boat calculated with the digital compass (magnetometer);
* rudder angle is the angle of correction of the rudder.  
Figure 6: Rudder correction angle algorithm.  
When error angle equaled 0, the rudder position would have been 90 degrees to the boat's stern, causing the boat to move in a straight line. Through the electronic compass, the angle error in relation to the next point to be traveled was calculated and corrected, as shown in Figure 7.  
Figure 8 shows a general flowchart of the boat's software.