Michael E. Holden
California State Maritime Academy Sabbatical Fall 2024
Overview
This report shares the results of my Fall 2024 Sabbatical project. It will get into the details pretty thoroughly, with links and files so I can find all the work in one place in the future, so feel free to skip around to the good parts. For a more visual feel you can follow the insta-blog at n3m0_the_robot_boat.
For my sabbatical leave project, I proposed to develop a small autonomous boat to measure surface sea current flow by drifting at targeted locations. I would then use the drift measurements to optimize the routing of the boat by taking advantage of the “tailwind” that a favorable current offers. The project is described in two phases: the first phase tested current measurement using an existing autonomous vessel, and at the same time used numerical simulation to test navigation algorithms. The phase one results were used to guide the second phase, which investigated a refined vessel design for the measurement task, and incorporated the best navigation scheme into the autopilot system to allow testing on the water. Read the full proposal submitted to the sabbatical committee below.
- Overview
- First Phase
- Modifications to Allow Drifting for Current Measurement with Ardupilot
- Current Measurement Operations
- Current Measurement Results
- Current Measurement Conclusions
- Route Optimization- Mission Description
- Route Optimization- Matlab Simulation Overview
- Route Optimization Minimum Time Results
- Route Optimization Minimum Time Conclusion
- Second Phase
- Concluding Summary
- Citations
First Phase
Modifications to Allow Drifting for Current Measurement with Ardupilot
The autonomous boat n3m02 was selected for the current measurement task. The image below shows n3m02 and the ground control station. This boat was used previously for oceanographic measurements1 and also harbor depth surveys2 , and needed a few modifications to be able to measure drift at specific locations for this project.
New Autopilot
The most significant modification was to replace the old Pixhawk 2.4.8 autopilot with a newer design that has enough memory to support Lua scripting3. A Matek F765-WING4 autopilot was selected from stock at hand, and integrated without too much trouble.
Tuning
During testing of the new autopilot, a persistent problem with the loiter function was finally solved. Loiter, also known as “dynamic positioning” in the maritime industry, is used to hold the vessel at a given position. The old autopilot would become unstable in loiter mode and violently yaw back and forth. I had posted a question to the ardupilot forum5 but didn’t find a solution, and I spent some time reading the code and documentation6 to see how loiter was controlled, and made a list of parameters to try changing, as the new project required loiter mode to stop at each waypoint before drifting.
Changing Loit_type7 between 0 and 1, which changes the direction the boat faces while loitering, did not help.
The critical gain was ATC_STR_ANG_P8: I changed it from 5 to 1 (units deg/sec per degree of error maybe?). and this stopped the violent oscillations. It is still perhaps too high, the boat spins fast acquiring heading in loiter mode, but it is stable and stops at the setpoint.
It was a frustrating issue because the autonomous waypoint navigation, which uses the same parameters, was working quite well. I think the difference is that the pivot turns during autonomous mode are only performed for WP_PIVOT_ANGLE9 degrees then it transitions to moving forward towards the next waypoint, so it regains stability upon transition to that mode even if the pivot would be unstable.
After replacing the autopilot and tuning the loiter performance, the boat was a reliable tool ready to be used for the drift measurement application.
Lua Script for Drift Mode
To measure current by drifting, the boat needs to be able to autonomously stop the motors and drift for a specified amount of time. This is not one of the modes10 supported by ardupilot, but a helpful forum post 11 had a lua script that implemented most of what was required. I modified it for my project and added data logging of the drift measurements to a file. The lua script constantly runs in the background of the autopilot code. When certain waypoints are reached, a flag is set for a given time, notifying the script to stop the motors. The script also calculates the drift distance, drift direction, and drift speed from the navigation GPS data stream, and writes the information to a CSV format data file on the autopilot SD card. The data file is easily pulled from the boat after the mission completes either wirelessly through the ground control station link or physically by reading the SD card with a computer. The script also sends the drift data in real-time via the telemetry link, so it is available to monitor on the ground control station while the boat is operating. The lua script is included below (Note on files: the file suffix was changed to make it easier to upload and download with suspicious web browsers, it should be named drift_log_file.lua
).
Current Measurement Operations
The following section gives an overview of the steps to plan and carry out a drift velocity measurement voyage.
Ardupilot Mission
Drift measurement requires specific waypoint types and some extra waypoint commands be included in the ardupilot “mission” file. Each waypoint type is set to “loiter_time”12, so that the boat reaches the waypoint and then attempts to stop and hold position for 10 seconds. This is to ensure the drift measurements start from rest. The next command is “SCRIPT_TIME”13 with a command ID of 86, timeout of 50 seconds, and Argument1 of 10 meters. The lua script is activated by matching the command ID, and begins the drift for 50 seconds. Arg1 is used to tell the script to abandon the drift if the vessel has moved more than the specified safety radius (10 meters for this mission). Once the drift is stopped, the vessel moves on to the next waypoint on the list. The mission plan file can be downloaded with the link below.
The route optimization algorithm described later uses the measured drift velocities to interpolate a velocity field over the survey area. Matlab interpolation routines work much easier if the velocity field is entirely inside the survey points (no extrapolation only interpolation), so it is helpful if the survey points are in an accurate rectangle to maximize the interior area for the velocity field. The analysis rotates the rectangular grid to a local x-y coordinate system so the orientation is not important. A matlab script was used to set the waypoints in a rectangular grid. The script is linked below; the waypoint mission is shown in the figure above.
Once the mission plan is created and uploaded to the boat, it will autonomously travel to the waypoints and measure the drift. The operator monitors the status of the boat, but should not have to take any action except to watch for and avoid other vessel traffic. If other boats come close, the operator has the option of holding the boat’s position in loiter mode, recalling the boat autonomously to the launch point, setting a rally point for the boat to navigate towards, or manually conning the boat out of danger. The mission may be resumed from any of these options with the click of a button.
Drift Data Format
The drift velocity and direction is sent over the telemetry link for the operator to monitor, and when the mission is complete, the drift CSV file can be downloaded using the MAVFTP function in mission planner, or by removing the SD card from the autopilot. A sample drift CSV file can be downloaded below. At each waypoint the following data is logged: starting latitude, starting longitude, time and date, drift speed, and drift direction,
Operation Video
The video below14 shows n3m02 reaching a waypoint and beginning the drift. In the mission planner screen shown at the end of the clip, the value on the display labeled “MAV_DRIFT” goes from -1 when the boat is navigating autonomously, to showing the actual drift distance (meters) during the drift portion of the mission.
Current Measurement Results
The measured drift is saved as a speed and direction (compass heading) at each waypoint in the survey mission. Each measurement is taken at a different time, depending on how fast the vessel travels and how far each waypoint is from the previous waypoint.
The animation below shows the boat (black arrow) traveling around the Cal Maritime waterfront and taking drift measurements (blue arrows). During the first circuit, you may notice the boat turns off course to avoid a student-operated vessel, then returns to the mission. The return-to-home and loiter commands were used to divert the boat to a safe location.
As each waypoint is visited multiple times, the blue arrows are interpolated in time between measurements, with the actual measurement shown when the boat leaves the waypoint. The red arrows are the velocity field interpolated in space from the blue measurements. The velocity field from this set of measurements is used for the route optimization work described later. While pretty, each level of interpolation adds uncertainty to the data. The animation shows how the currents in Morrow Cove eddy and swirl. There is a lot to see, watch it a few times!
Current Measurement Conclusions
Using n3m02 the autonomous boat to measure drift was a success, and useful information was recorded. The drift data will provide useful information for route optimization as described in the next section. The process for obtaining the data was reliable and easy to perform. The drift can be measured at any point on the surface that the vessel can navigate to, and as a GPS sensor is part of the autopilot electronics, no dedicated sensors are needed on the autonomous vessel.
The time between measurements is significant, and adds uncertainty to the optimal route solution, as conditions may change before the route is calculated and implemented. A faster boat would reduce this delay but it cannot be eliminated if a single vessel is performing the survey.
The drift motion is influenced by current, wind, and waves, and therefore may not be a good representation of tidal currents from an oceanographic data perspective. N3m02 was observed to be noticeably susceptible to drifting with the wind. Drift buoys typically use a drogue so that the motion of the buoy is, as much as possible, the same as the motion of the water. A vessel with minimal area above the waterline would be better than n3m02 for scientific surface current measurements. Additionally, a drogue or similar device could be mounted on the vessel and deployed with commands in the lua script controlling the drift mode.
For the task of optimal route finding, however, the optimal route depends on all forces: current, wind, and waves. Measuring the effect of all of these on the drift is the most useful information for route planning. In this task, the best vessel to use in the drift survey is the actual vessel that will travel the optimum route. Such a route optimization is the topic of the next section.
Route Optimization- Mission Description
There are many possible missions for an autonomous boat, and the goals and constraints must be carefully spelled out before an “optimum” route can be found. Autonomous boats might be delivering cargo, where speed and fuel use are important; or scientific observations, where time on station is important; or many other tasks. For this project, a waterfront surveillance mission is specified.
The mission is to patrol the waterfront on a route that travels between two zones. The vessel must cross the line that defines one side of the box-shaped zone, then travel across the line of other side. Where it crosses the lines, as well as the path and speed between crossings, is open for optimization. The figure below shows the layout of the survey zone in Morrow cove. The red “surveillance box” is the allowable area to navigate in, and the blue dashed line is the baseline survey route that goes from waypoint 1 to waypoint 2 and back again. The current will be surveyed inside the area of the red box in order to optimize the route. The route must extend to the lines that waypoints 1 and 2 are on, but it may move closer or farther from shore.
Route Optimization- Matlab Simulation Overview
To find the optimum route using the surveyed drift data, a kinematic simulation of a boat operating in a vector field was combined with a gradient-based optimization algorithm. The simulation and optimization were based on a code used to optimize aircraft routes for tailwinds, from Matlab15. The code was modified to accurately model the full effect of a following current, and to use the data from the drift surveys described above.
The survey drift data are interpolated into a vector field over the surveillance box. This requires first rotating the surveillance box to align with x-y axes, and then interpolating the surveyed drift data onto an x-y grid. The rotation makes working with the interpolated field data much simpler as the data can be stored in rectangular matrices efficiently. The figure below shows the original and rotated data. It also illustrates the importance of aligning the survey points so that the interior rectangle is as large as possible– the interpolation method used only applies to a rectangle that fits completely inside the measurement points, so survey waypoints far outside the box (such as the lower right arrow) are less useful with this technique. Later surveys used more carefully placed waypoints.
The original Matlab example code optimization objective is to minimize the time on a route, keeping the end points fixed but moving the intermediate waypoints. The code was modified to include waypoints for a return trip, and to allow the end points to move along the lines of the allowed surveillance box as described above.
The time is calculated by first inserting points between the waypoints to discretize the route into small steps. At each step, the drift current is calculated by further interpolating from the rectangular matrices of drift field velocities, and the drift field vector is combined with the vehicle velocity vector to give a total velocity (speed over ground). This velocity is used to calculate the time over the leg segment; the vehicle velocity can also be used to calculate the energy used over the segment.
Route Optimization Minimum Time Results
The optimization code was able to find routes to minimize the time to travel back and forth across the surveillance box, taking advantage of the drift velocity measured at Morrow cove. The figure below shows one optimization solution, where the simple back-and-forth initial route took 193 seconds and the optimal solution completed the route in 177 seconds.
The optimal route shows only small deviations from the original back-and-forth path, but does move the route to a more favorable current location in the box, with a slight following current in each direction. Because the objective is to minimize time, taking a longer route to take advantage of stronger favorable currents just does not pay off, as covering the extra distance to reach more favorable currents costs more time than is saved by the faster speed once in them.
Route Optimization Minimum Time Conclusion
The minimum time route optimization does take advantage of the drift velocity field as desired. The time savings and overall route shape compared to a straight line is somewhat small, calling into question whether the objective is the best for a port surveillance mission. Does the small time savings pay off when the harbor must be traversed ahead of time to measure the current field? Certainly there are situations where this result would be useful, but the solution is not compelling. For the next phase, a different route optimization objective will be considered, where time is not weighted as highly as total energy expended over the route. With the new objective, a slow, drifting route may be found that strongly follows the current field.
Second Phase
The second phase of the sabbatical project was planned to suggest changes to better improve the system based on the results of the first phase. The suggested changes would be documented, and any that were feasible in the remaining time of the Fall semester would be implemented.
Vessel Modifications for Current Measurement
For the route optimization goal, the best vessel to measure the drift is the vessel that will run the route. This is because vessels are affected differently by current, wind, and waves, so drift from one vessel may not predict the effects on a different vessel. However, if the survey data is to be used for more general oceanographic studies, a vessel that minimizes the affect of waves and wind is required to yield reasonable lagrangian current measurements. Equation 1.40 in reference [16] states that the wind-driven component of velocity varies with the square root of the ratio of surface area above and below the water line, so minimizing surface area above the water and maximizing surface below should give the best surface current measurements. Speed is another useful feature in the survey vessel, because the survey can take significant time to accomplish.
One idea for more accurate surface current measurements is a boat that sinks low in the water when drifting. Minimizing the area above the waterline compared to the area below will maximize the current measurement accuracy. Some model boats such as the m-jet supersprint17 are designed with flooding chambers to sink into the water when stopped. While designed to assist in self-righting after a capsize, the feature also lowers the windage of the vessel when drifting. The image below (from the facebook group18) shows this boat at rest . This boat is also fast and small, so would be an interesting option for surface current measurement if equipped with the proper electronics, and with the decorative superstructure removed.
Another idea would be to increase the boat’s underwater surface area when drifting, with a drogue or other deployable system. The figure below, from [16] shows various drogue designs used with drifting buoys. None are designed to be retracted into a boat, so adapting such a drogue to an autonomous vessel would require some additional design work.
Route Optimization Minimum Energy Mission
As discussed in the first phase results, using the drift field measurements to minimize the time to complete a route was successful, but the results were not especially compelling, as the penalty for traveling far to find favorable currents outweighed the gains in most cases. The optimal route generally deviated only slightly from the straight line back-and-forth path, although the path was shifted to wherever the current was most favorable.
An alternate mission would be to take advantage of the drift field to minimize the energy used to complete the route, without considering time. With this approach, if the drift field has a circulating feature, the optimal route should seek to move from start to finish and back again with following currents over the entire route.
The matlab optimization code was modified to minimize the energy (measured by the boat’s speed through the water) over the route. Over each segment of the route, the boat uses the drift current as much as possible, and the engines as little as possible.
With a favorable drift field, the optimal boat velocity is as shown in the diagram below, with the boat’s velocity through the water (from engines) used only to cancel the off-course component of the drift current perpendicular to the route.
If the drift current is unfavorable or very slow, additional boat speed is required to keep a specified minimum speed over ground, with the resulting velocity diagram shown below. This would be penalized in the optimization process, because it uses more energy, so that routes with favorable drift currents would be preferred.
The equations used in the minimum energy route optimization are shown below.
Route Optimization Minimum Energy Results
Using the same drift field data as in the previous minimum-time optimization, the minimum energy method yields routes that clearly take advantage of following drift current velocities. The optimum route is strongly dependent on the minimum speed specified: as the boat speed is increased, following currents have a smaller impact on the energy savings so the boat will tend towards a more direct path.
The image below shows an optimal minimal energy route. The drift current field has a circulating pattern, so the boat is able to stay in favorable current nearly the entire route. Compared to the baseline back-and-forth route, the energy used is reduced by more than half. The time enroute also increases as the distance is greater for the optimal route, and time is not considered in this optimization scheme.
Repeated tests of this algorithm with various measured drift fields, and various minimum speeds, all calculated routes that circulate with the measured drift field. As the minimum speed increases, the optimum route tends towards the shortest distance, because the drift velocities become less and less impactful. Images below show optimal routes with the same drift current field and different minimum speeds, and also different vector fields (measured at different times of the same day) with the same minimum speed. The results of the optimization are all plausible and give confidence that the algorithm is correct. Each solution took a few seconds to calculate in Matlab on an ordinary laptop computer, which makes it seem likely that the route optimization computations could be moved aboard an autonomous vessel in the future.
Effect of Varying the Minimum Speed
As the minimum speed increases, the optimum route tends towards the shortest distance, because the drift velocities become less and less impactful.
Optimal Routes in Varying Drift Velocity Fields
All solutions calculated routes that circulate with the measured drift field.
Future Work
As the semester draws to a close, and although the sabbatical deliverables have been met, a few avenues of research are planned for the future to continue this project.
New Boat
In order to investigate the effect the vessel type has on drift measurement and optimal routing, a second boat build has been started. The goals of the new boat are to reduce the effect of wind on the drift measurements by having a hull that floods when at rest, to decrease the time to travel between measurement points by operating at a high speed, and to make operations easier with a much smaller boat than used in the previous phases. The M-Jet Supersprint, with a jet drive and 3-D printed hull, was mentioned in a previous section, and parts and plans for this boat were purchased at the beginning of the second phase of the project. It was somewhat optimistic to think that a completely new boat could be built from scratch during the last half of the sabbatical semester. The hull has been printed and the drive hardware installed. Initial testing without the autopilot exposed weaknesses in the hatch design that make it somewhat leaky. Some re-design and testing are planned before the autopilot will be installed. Tuning the parameters for a stable, reliable autonomous vessel will take further effort before this boat is ready to measure drift currents. This work is planned for the 2025 Spring and Summer terms. The image below shows the current state of the jet boat: an operational but leaky hull and new autopilot electronics ready to install.
Integrating Software
The other line of work that is planned for the future is to more tightly integrate the drift survey with the optimal route planning. In the first and second phase of this project, drift surveys were performed and the data was saved; the optimal route calculations using this data were done later as the algorithm was developed. The next step will be a mission that performs the drift survey, and then immediately solves for the optimal route. The boat should then navigate the optimal route, and then immediately also navigate the baseline route for comparison. Operating without delay is important or the changing tides will make the drift measurements no longer useful. These tests will give experimental validation to the simulation’s calculations of the energy use. The code for this mission has been written, unfortunately the required weather window of no rain and light winds could not be found at the end of the semester; winter has begun at Cal Maritime. It is hoped that this work can be completed over winter break or early in the Spring semester on a calm winter day. Once these results are obtained, the algorithm could be further integrated into the boat’s computer to completely automate the survey and optimal route solution, if desired. The image below shows an optimal route ready to upload to n3m02 (calculated from drift current measured in October 2024).
Concluding Summary
This report showed that with very minor modifications, a small autonomous boat can be used to measure drift over an area of interest. The drift has components due to surface current, wind, and waves, and the design of the vessel is important if a single isolated component (such as surface current) is to be studied.
Using the drift field measurements to optimize the route of a vessel was also demonstrated using Matlab simulations and optimization routines. The definition of optimal must be carefully considered, as the optimal routes for minimizing time over the voyage are quite different from the routes which minimize energy use.
As the drift velocity can be measured without adding physical equipment to the autonomous boat, and as the route optimization can be performed on a modest laptop in just a few seconds, it seems possible that these techniques could find their way onto autonomous vessels, if in fact they are not already.
Citations
- https://www.holdentechnology.com/2017/08/08/n3m0-the-autonomous-boat/ ↩︎
- https://www.holdentechnology.com/2024/10/06/n3m02-the-autonomous-boat-depth-surveys/ ↩︎
- https://ardupilot.org/copter/docs/common-lua-scripts.html ↩︎
- https://www.mateksys.com/?portfolio=f765-wing ↩︎
- https://discuss.ardupilot.org/t/boat-loiter-unstable/88660 ↩︎
- https://ardupilot.org/rover/docs/rover-tuning-pivot-turns.html ↩︎
- https://ardupilot.org/rover/docs/parameters.html#loit_type ↩︎
- https://ardupilot.org/rover/docs/parameters.html#atc-str-ang-p ↩︎
- https://ardupilot.org/rover/docs/parameters.html#wp-pivot-angle ↩︎
- https://ardupilot.org/rover/docs/rover-control-modes.html ↩︎
- https://discuss.ardupilot.org/t/let-the-boat-drift-until-script-time-continues/108192 ↩︎
- https://ardupilot.org/rover/docs/common-mavlink-mission-command-messages-mav_cmd.html#mav-cmd-nav-loiter-time ↩︎
- https://ardupilot.org/copter/docs/mission-command-list.html#script-time ↩︎
- https://youtu.be/k-JSWyfzLxI ↩︎
- https://www.mathworks.com/matlabcentral/fileexchange/36321-finding-an-optimal-path ↩︎
- Thomson, Richard E, and William J Emery. Data Analysis Methods in Physical Oceanography. Third edition. Waltham, Massachusetts ; Elsevier, 2014. Print. ↩︎
- https://www.cgtrader.com/3d-print-models/hobby-diy/other/m-jet-sprint-3d-printable-rc-jetsprint-boat-model ↩︎
- https://www.facebook.com/groups/623045356071128 ↩︎
- Thomson, Richard E, and William J Emery. Data Analysis Methods in Physical Oceanography. Third edition. Waltham, Massachusetts ; Elsevier, 2014. Print. ↩︎