The algorithm has become pretty complex and I use a visualization to simulate how the boat would behave at different locations on the ocean in different wind conditions.
It helped me fix tons of small bugs which I couldn't find by real testing. Here are some interesting points:
- The boat can't sail straight upwind or downwind. In unfavorable wind conditions, it will keep the heading at least 45 degrees to the wind.
- If the wind conditions are unfavorable for some period of time, the boat will follow a zigzag pattern. This way, it can sail upwind as well as downwind.
- If the boat deviates from the shortest path, it will get back to the path rather than going straight to the destination.
- It's most important to minimize the flap adjustments as we are limited by the actuator life-span.
- The boat reacts to the change of the wind almost instantly if the change is confirmed in 3 seconds.
- Most of the time, it will head to the destination plus/minus 7 degrees. There is some tolerance in order to avoid constant steering.