Auto Pilot for Tiny Yacht

Greetings . . . I started on this project some time ago in connection with a simple GPS + Arduino controlled Tiller Pilot but got nowhere with it at that time. However, My boat/project has started and I wish to follow up on the automated steering system (Tiller Pilot).

This is what I have:

The ASUS Notebook Computer running Windows 7 + OpenCPN Chart Plotter software. My GPS is a Marine waterproof Evermore SA320 USB. I have the full set of CM93 World-Wide Charts! This system works well.

I also output the MNEA Data from the GPS via a Prolific USB to serial (RS232) Adapter and select this as an output in the OpenCPN program (The data is working as the Lat/Long and heading appear on my VHF DSC Radio when connected).

I want to feed this GPS NMEA data to my Arduino to control a secondary "Trim" rudder on my boat to maintain direction. What ever the current heading is (say 270º) is stored into the Arduino when the button is pressed and if any deviation from that coarse, the appropriate PWM output must go + or - to correct the heading until it agrees with the current 270º.

If at any time I want to change heading, simply press the button to lock in the current heading.

I hope that makes sense. It's something I've been planning for some time but have no idea how to write the code! I hope that someone can help.

Bye for now

Steve
http://www.aroundinten.org
http://www.calvertonweather.co.uk

Steve,

I have been working on an autopilot for my boat for several years. This summer It steered my boat over 500 miles in the Pacific NW. My suggestions for your project. First of all I will be glad to share what I have done and help you with coding. Some general comments about your layout.

In my experience using GPS course is a slow parameter and will not respond quickly to rudder commands. I use a heading sensor(Pololu IMU9). This changes when heading changes. This will have the advantage of un-tethering you from the computer for normal operation.

One thought on steering your trim rudder with a servo. I think this is the place to start. Start with a small Arduino project that will operate a servo using a potentiometer as input. Then see if you can mechanically hook it up to the boat and that it will give you adequate control of the boat. You can do this with any Arduino but for your bigger project I suggest a MEGA because of the larger number of I/O lines and code memory.

My suggestion is an Arduino Mega, a Pololu IMU-9 heading sensor, a four line LCD and a telephone keypad, plus your servo drive. If you choose to go this way you will be able to use my autopilot code. As I said, this system steered my 40 foot sailboat 500 miles this summer.

I use a second Arduino Mega to read a GPS. I use a second Arduino because the GPS runs at 1 Hz and the IMU-9 heading sensor runs at 50 Hz. The GPS slows it down too much but the results are sent to the main Arduino using Easy Transfer library.

I am currently working on integrating the GPS so it will steer waypoint to waypoint with cross track error correction.

Here is a link to my code and documentation, some of it is out of date contact me if you decide to use this stuff.

Login - Dropbox.

Jack

Many thanks for your reply and the information Jack.

Your design sounds good and lends it's self to further expansion and more facilities later. Mine is simple, not requiring a keypad or LCD display but as you say, requires the notebook computer and GPS (A lot more total current from the battery system). It was based on the idea that I will have openCPN running + GPS for navigation . . . . . . . but, no, I really don't need it on all the time.

My original design was a stand-alone unit with Fluxgate compass, Arduino and servo plus a push button to transfer current . . . 4 basic components but at the time I could not get the Fluxgate compass anywhere in the UK. Just press the button and load the current heading into memory. Any further deviation to the input pin will cause the pwm output to the servo to send it and the rudder-blade to port or starboard to correct the course. The total consumption is only a few tens of mA unless the Servo is working!

I see that the Pololu IMU9 is discontinued. The replacement requires different code. Now I will be lost!

Steve
http://www.aroundinten.org
http://www.calvertonweather.co.uk

Microyacht:
My original design was a stand-alone unit with Fluxgate compass, Arduino and servo plus a push button to transfer current . . . 4 basic components but at the time I could not get the Fluxgate compass anywhere in the UK.
...
I see that the Pololu IMU9 is discontinued. The replacement requires different code. Now I will be lost!

So why not connect your GPS receiver directly to the Arduino? Many GPS units have RS232 NMEA output, which the Arduino can read (possibly with the help of an RS232-to-TTL adapter). I believe the GPSr's currently selected waypoint is also available in the NMEA sentences, so the Arduino can do cross-track correction. No compass or IMU needed.

If 1Hz updates are too slow, a PID algorithm should smooth things out.

So why not connect your GPS receiver directly to the Arduino?

Because I use it for navigation using OpenCPN Chart plotter program.

My Marine GPS is USB. Within the OpenCPN program it's easy to to select an MNEA output in to feed Autopilot, Marine DSC VHF Transceiver etc . So with a spare GPS output available, it seemed logical in an integrated system. I already have a few Prolific USB to Serial adapters which I've found to work faultlessly. (D9 pins 3-TXD 5-Ground).

Steve
http://www.aroundinten.org
http://www.calvertonweather.co.uk

Gotcha.

I recommend starting with the Tiny GPS library: TinyGPS | Arduiniana

Start with a test sketch to read the NMEA data from the Arduino's hardware serial port (pins 0 and 1) and then output the lat/long using SoftwareSerial to a second serial port on the laptop. (This is just for debugging purposes, the SoftwareSerial and second port can be eliminated from the final project.)

Once you can get the lat/long from the OpenCPN and print it back to the laptop's Arduino Serial Monitor, you can move on to see if you can get waypoint bearing from OpenCPN -- $GPBWC (http://aprs.gids.nl/nmea/). You can compare this with your own heading and move the servo as appropriate. Or perhaps use $GPWPL and do your own bearing calculation.

Steve,

I did look up the Pololu IMU9, and you are right it is discontinued but they have a new version V2 which is in stock.
MinIMU-9 v2 Gyro, Accelerometer, and Compass (L3GD20 and LSM303DLHC Carrier) .

Here is the PID I use.

PID_output = K1 * (heading_error) - K2 * bearing_rate

The bearing rate term is the feed back. Take the case of sailing downwind in a following sea. Lets say the following sea slews the boat 15 degrees. The GPS based system will do nothing immediately. Where as the negative bearing rate term which comes from the IMU will apply an immediate rudder correction. I like to think of it this way, the GPS tells you where you are and where you have been. The heading sensor tells you where you are going.

The LCD and keypad are not needed. a single push button to tell the A/P to steer the current course is adequate. With a keypad I can increment that +/- 1 or 10 deg. Switch to Tack mode where you can tell the A/P to turn R/L 90 deg ( or some other number).

Anyway, for what it is worth. Let me know if I can help you.

Jack

Many thanks for all the information.

A main consideration I'd not really thought about and re-think . . . . Everything is driven from two 12 V batteries* totalling 52 amps (2 X 26A) and a small solar panel. I'll mainly use the Tiller Pilot when I hope to get some sleep. I won't need the Notebook/Chart Plotter program on and can save up to 2 amps/hr while it's off. So perhaps a stand-alone Arduino Tiller Pilot is the way to go. Either with separate GPS or Compass unit.

Perhaps I'll set it up on the bench over the weekend and have a play. I need to get into the Arduino code. It's a long time since I used Basic STAMPS in automated light fittings. I'll also order a V2 Gyro/Compass unit.

*Also has to supply nav lights and radio as required.

Back soon . . . . .

Steve
http://www.aroundinten.org
http://www.calvertonweather.co.uk

PS: Haa . . just found the sketch of the packaging for the original idea. I remember it now. Was going to build in it's own re-chargeable battery pack and a solar panel!

. . . In my box of bits I've found a EM406A GPS Module attached to a shield. I really don't remember buying it but have an invoice attached to it and it appears that I got it in 2010. I wrote on the back a link to where I downloaded a bit of code for the Arduino. This is the code:

void setup()
{
Serial.begin(4800);
}

void loop()
{
if (Serial.available()) Serial.write(Serial.read());
}

I've connected the Arduino+EM406A GPS via the USB cable to my computer and loaded the above code and after clicking on "Serial monitor" (under Tools, remember to change baud rate to 4800), I do get rows of GPS data containing date/time and my location etc etc.

Tomorrow I will connect a push button and a small RC Servo for test purposes and then I will really need HELP!

Thanks all

Bye for now

Steve
http://www.aroundinten.org
http://www.calvertonweather.co.uk

you ight want to have a look at my god daughters web page

she has a rather complex but working auto system,

1 Like

Many thanks drjohnsmith. I have that link already and follow Natasha's journey! She's doing GREAT! I must read through more carefully as I've not seen her automation system.

Steve
http://www.aroundinten.org
http://www.calvertonweather.co.uk

I've now connected up the bits. For test purposes I've fitted a Global EM406A GPS on a Sparkfun shield with through connections. To digital I/O pin 9 I've connected a standard RC Servo. To digital I/O pin 3 I've connected the "SET" switch.

I've run the GPS test program and can see streams of data fly up the screen on my computer monitor.
I've run the Servo test program "Sweep" and the servo rotates back and fwd 180º

Pictures:


I've used digital pin 3 for the "Set" input. The spare un-connected wires in the picture are from Pins 2 and 4 and will be for +1º -1º if added.

H E L P !

Microyacht:
I've now connected up the bits. For test purposes I've fitted a Global EM406A GPS on a Sparkfun shield with through connections. To digital I/O pin 9 I've connected a standard RC Servo. To digital I/O pin 3 I've connected the "SET" switch.

I've run the GPS test program and can see streams of data fly up the screen on my computer monitor.
I've run the Servo test program "Sweep" and the servo rotates back and fwd 180º

Pictures:


I've used digital pin 3 for the "Set" input. The spare un-connected wires in the picture are from Pins 2 and 4 and will be for +1º -1º if added.

H E L P !

hi
You generally wont let inputs float, as it will when switch is open. You may get random levels at uC input..
A pullup/pulldown may solve this.
Using switch may produce short voltage peaks (bouncing). Solve this either by software or hardware method.

What You might want next in program is to look for the sentence(s) that contains the informations you want to use.

Ship Ohoi

regards

Many thanks janiek.

Despite what I have said, I think this project will grow and I will end up adding a keypad and LCD Display, a copy of Jack's (coyotewaits) unit. These components cost so little now. In the meantime, I've ordered some breadboards and a pack of jumpers which will make it much easier to add pull-up resistors and other components.

Steve
http://www.calvertonweather.co.uk
http://www.aroundinten.org

The arduino has internal pull-ups - see the pinmode documentation, so no need for your external resistors (at least for this purpose)

My feeling is that using the GPS to determine which way you are going, is bound to fail.

If you take a GPS and walk around with, it will calculate it's position from time to time and calculate an apparent direction you are moving based on those points. If you plot them on a map ( Google earth is the easy way ), you will see a zig-zagging series of straight lines. This would be useless for steering a yacht.

Secondly, I think it would be futile to try steering a boat without knowing which way the boat is facing. A GPS cannot tell you which way the boat is facing. A digital compass which costs about $4 will tell you which way the boat is facing. In simple terms, the boat needs to be pointing in the direction that you want to go. You can then adjust this for leeward sideways drift, currents or whatever else you like. In the short term, to control the tiller to keep the boat pointing in the direction you want to go, you need a digital compass chip, not the GPS. Then, in the medium term, you use the GPS position to compare where you are, to where you want to go, and adjust the course reference that the compass is using. I wouldn't use the GPS course heading information for anything, because it is basically useless IMHO.

Thanks for that wildbill. I have found that with many microcontrollers, even with internal pull-up R's, with un-avoidable long leads on pins, it can be a problem, cured only by the lowest value resistor that will still permit a valid difference between 0 and 1! I've been involved in electronics all my life but NOT programming!

Steve
http://www.calvertonweather.co.uk
http://www.aroundinten.org

Thanks michinyon. Before I started this, I did take the GPS from my car for a walk (Internal battery now only lasts 5 mins!). I walked down the pavement (sidewalk) for almost 1/4 mile before a bend. In compass mode, It displayed 271º almost constantly! On my return, it displayed 89º. As the battery warning light came on, I quickly completed my tests by rocking the unit to simulate waves but still trying to point the GPS forward. At worst I saw only a degree error.

My small, chubby boat won't sail much closer to the wind than 40º. Progress will be slow. A few degree error on each tack won't make a whole hell of difference. If I can get a few hours sleep from time to time, it'll be a bonus. I can make overall route error steering manually while I'm awake!

You are misunderstanding what the GPS actually does. The GPS device does not know which way you are holding it ( unless it also has some kind of compass device inside it, some do.

A GPS device inherently calculated its position. Thats all. It estimates its position roughly once a second, with an uncertainly of 2 or 3 metres.

Any estimate of the direction in which you are going, is based on the difference between successive position estimates, and GPS does this quite poorly. Often much worse than you could do for yourself by plotting successive position estimates on a piece of graph paper and then drawing a line through them.

Here's why. If you are driving in a car, or you are Usain Bolt, then each position estimate is going to be 10 or 15 metres apart. Even if your latest position estimate and the one before that, are off by 2 or 3 metres ( and often much more ), it is still fairly clear which direction you are going.

But if you are walking down the street at normal speed, or in a very small boat, the successive position estimates are closer together than the uncertainty of each estimate. Suppose a particular GPS reading estimates your position to be 2 metres in front of your actual position. Suppose you walk 1 metre forward in 1 second. The next GPS reading estimates your position to be 2 metres behind your actual new position. The GPS will conclude that you are walking at 3 metres per second, backwards. This sort of nonsense would be absolutely useless for tiller control. Worse than random.

The second reason your plan will fail, is that GPS has no idea about the orientation of the boat. You could take the sails down, and the boat could be drifting sideways in the direction that the wind or current is taking it, and your GPS course would have no idea. Controlling the tiller of a yacht is about controlling the orientation of the yacht, it is not actually controlling the direction in which you are going.

. . . I'm tied-up with storm damage after monday's battering. Back soon.

Steve

Sent from a Blackberry