[PAID] Sail boat straight from point A to point B

I have such a problem, namely I would like to go straight from point A to point B with my boat. The boat is steered by two engines. I have tried many things but unfortunately I am too weak to comprehend it. The boat is flowing like a sine wave http://212.59.240.9/boat.png).
I am looking for a person who would help me understand how to correctly calculate the data for the boat to go straight, i.e. the shortest route between points A and B. The code in Arduino is enough for me. Any platform: Arduino, STM32, ESP32 The current code that I use for testing is attached. http://212.59.240.9/sketch.ino
I tried to use the compass, the boat hits the target perfectly but unfortunately it flows in a curve http://212.59.240.9/boat2.png

I have time to complete the project by October.
Budget: 300USD

Hello PYJTER
Take a view to get some ideas here:

Have a nice day and enjoy programming in C++ and learning.

1 Like

This is the second case when the boat veers off course, the bow is always straight on the target but will depart from the line on which it is sailing.

You calculate the GPS heading (my CMG) and subtract from Beranig from the compass. The difference goes to the engines
http://212.59.240.9/boat2.png
The boat then goes like this if there is a wave. The boat does not know if it is going straight on the designated line from A to B it only always checks where the target is From the place where it is

There are multiple forces at play here. Wind and current are also influencing the position of the boat.

How are you testing this?

Quellbild anzeigen

This is a pretty nice picture to have clear naming of the forces and directions. Tidal current is missing.

1 Like

I know that the wind, the wave has an influence, even uneven running of engines.
I tried to calculate the offset distance from the XTE line, but unfortunately the GPS can give a point of 2m on the right or left side of the line.

1 Like

So I am supposed to understand it like this:
TRACK-COURSE = 0 AND HEADING-BEARING = 0
Which difference should I prioritize? can the result just divide by two ?? And give the difference to the engines ??
I'll try to test it tomorrow.

I have a starting point and an ending point on the lake, I sail the boat forward and deviate off course then turn on the autopilot and watch what happens. In addition, an LCD display that shows me the data. In addition, I have telemetry turned on.
I check the calculations first through the simulation: sketch.ino - Wokwi Arduino and ESP32 Simulator

Yep.. but have you actually tested any of this is the real world?

I've been testing this for over five months ... tomorrow I can make a video if it helps. Without real testing, I don't even know how else you can test it, you have to check it on the water and I always do it.

OK.. cool. Good to hear that you are not relying on a software simulator. Did you look at @paulpaulson's post #2... it has some very good information.

In post no 3 is my answer I tested this.
Tomorrow I will test what was given in post 5 from @paulpaulson

int motorSpeed=130, motorSpeed1, motorSpeed2, kp1=1, kp2=1, errorBH =0, errorCT =0, bias=0, error=0, errorInt = 0;
float Bearing;
//Motor:-
void steering()
{
     Bearing = gps.courseTo(presentLat, presentLon, gotoLat, gotoLon;
     errorBH = heading_error(int(Bearing), int(Heading));
    

     
     courseGoTo = gps.courseTo(fromLat, fromLon, gotoLat, gotoLon); // Desired Track in degrees (forward azimuth)
     trackGoTo = gps.courseTo(fromLat, fromLon, presentLat, presentLon);

     errorCT = (courseGoTo + trackGoTo)/2;
     
  
     bias = errorBH+errorCT;

...

    motorSpeed1 = (motorSpeed - bias);
    motorSpeed2 = (motorSpeed + bias);
...
}

I assumed that I am adding up two errors, both Heading-bearing and Course-Track, and divide by 2 so as not to amplify the error on the motors too much.

The yacht I raced on had a similar need, although the desire was to arrive at a specific point, preferably by the straight line between points but not necessarily vital to do so.

We displayed the current bearing to the mark and the helmsman would try to keep it constant with steering adjustments.

That is because you are not taking the cross track error into account. You need a bit more math to fix that.

I tried to calculate the offset distance from the XTE line, but unfortunately the GPS can give a point of 2m on the right or left side of the line.

What did you try? Errors of +/- 2m should not be a problem.

1 Like

Hello PYJTER

All in all for your project a PID controller to minimize the x-track error is essential needed.

There are a lot of PID controller lectures and tutorial in the WWW available.

Take some time study and and understand this technology before start with coding.

Have a nice day and enjoy programming in C++ and learning.
Дайте миру шанс!

1 Like

I did the calculations to get the XTE and the result was correct it always showed how many meters I am from the right or left line.
I made CMG and DTK calculations to determine where the boat is. But I see that my assumption was very wrong because the boat did not know where the bow was.
And it flowed in this way for me with the appropriate Kp
http://212.59.240.9/boat.png

I was supposed to test today but it's raining terribly for me. But tomorrow I will do it in the morning and record a video of how I did I have two things to test, I will check how it behaves in the case of calculating (Bearing-Heading) and (CMG-DTK) and the second test for calculating (Bearing-Heading) and XTE.
When I tested XTE, this bug was very small so you will definitely need to strengthen it with Kp. But I will test it.

As I wrote incorrectly, I made assumptions and now I can see it in yours posts. I wanted to give up the compass and calculate everything from GPS.

The compass is absolutely critical!

Since the cross track error is orthogonal to the course error, as pointed out above, you can use two PID loops.

2 Likes

Damn, I'm shocked it flows as straight as an arrow thank you in particular @jremington @J-M-L @paulpaulson
Thank you all
Later I will paste the video when I process it :wink:
1.5 years from the flashing diode to the boat flowing straight;)
Of course, the lake was calm, so I will check how it will be in the side wind, but I will control the PID maybe ... but this is enough for me now.

Hello PYJTER
The wind in direction and speed is a disturbance variable for the PID control loop and must be included in the control loop calculations.

Have a nice day and enjoy programming in C++ and learning.
Nog een fijne dag en veel zeilplezier.

Yes, I know. For those, of course, who want to understand how PID works, apart from the theory, a nice video that allows you to understand how to control PID.

3 Likes