Sunday, December 29, 2013

The Arduino autopilot that Jack built

Autopilot kit for sale. Only $350, some assembly required. Jack Edwards, a mechanical, engineer, loom builder (yes as in weaving), and many other things in his professional career has built a functioning Ardunio based sail boat auto pilot system. The little Ardunios have piloted his aptly named boat the Wile E. Coyote over 400 miles this summer using both heading, and GPS track mode with cross track error correction. There are some chores left to complete such as wind instrument integration, but it's an impressive success with such a tiny capital outlay. 


Jack's boat is a 1983 Robert Perry designed 40 Nordic Yachts sloop with a vintage (1986) Wagner compass steer autopilot. So why build an Ardunio based system?

In Jack's words, "I always wanted to have an autopilot with modern capabilities and thought about building one using PC based programming but couldn't figure out how to handle the interfaces with inputs and outputs. About three years ago my son showed me an Ardunio a friend had loaned him. Wow, that was exciting and now I have it to a point where it is a working system."

Although functioning, parts of it are still packaged in a prototypical way. From small cardboard encased electronic prototype acorns, mighty oak autopilots grow. You can watch this video of Jack showing it operating and discussing it here.


The elements in Jack's autopilot, are the same as found in any autopilot. We have a computer processor. In this case he is using two Ardunio Megas. One for the GPS processing, and the second one for everything else.

There is a display to view data, and a DC motor drive system for the hydraulic pump. A nine degree of freedom IMU (Inertial Measurement Unit) with a magnetometer, gyro, and accelerometer along with a rudder position sensor.


The block diagram shows the primary components and their basic connections. The left side Ardunio has the GPS interfaced to one of its four serial ports.

The other Arduino is handling the data from the IMU, rudder reference, DC hydraulic motor drive, and the data display. The two Ardunios communicate with each other using serial data ports, and a fast software routine called "Easy Transfer".


The Ardunios are 2560 Megas. The one I purchased from Sparkfun cost me $62.10 with shipping.

Don't let the small 4" x 2" size fool you. There is considerable computing horse power in this little board. 16 analog inputs, 54 digital input and output pins, 14 of which can be used as PWM (Pulsed Width Modulated) outputs. Add to this 4 serial ports USB port, and a 16 MHz clock, all driven by an Amtel AT2560 RISC (Reduced Instruction Set Computer) processor.

The quarter sized Pololu IMU is the heading compass. It has a retail price of about $40.00. Like any digital heading compass on a boat it needs to be located about a meter away from any ferrous metals, and requires initial calibration.

Jack used a Honeywell hall effect sensor to build the rudder reference. As the rudder turns, the shaft in the sensor rotates, and the voltage changes. The voltage output varies from .5VDC to 4.5 VDC.

This voltage range covers up to ninety degrees of rudder movement (+-45 degrees). So a reading of 2.5 volts would mean the rudder is centered. The rudder sensor voltage readings are read by the analog inputs on the Ardunio. The rudder centered is at 2.5 volts.

For $18.00 you can have a data display from Adafruit. It's 20 characters wide, by 4 rows, and you can create up to 8 special symbols. This is available for a couple of dollars more in a variety of LED colors. It has PWM adjustable dimming capability, and contrast control.



Jack's boat has a Wagner heading steer only autopilot. Translated this means the autopilot will keep the bow pointed to a compass heading but can't compensate for currents, winds, or waves that are all shoving on the boat. The existing Wagner hydraulic pump on the boat, is being used in the system. The Wagner pump is a 12VDC (PV100-12-TR) and draws 11 amps. This is not unlike a Raymarine Type 1 hydraulic autopilot pump.

The difference in this system is the solenoid valve that when open allows manual steering, and when closed the pump does the steering. The pump is managed with a Pololu Qik 2s12v10 serial DC motor controller.

"Its only possible because I'm standing on the shoulders of giants." Robert Huiteme.

Jack, like Robert is also standing on the shoulders of giants. Ardunio software is open source and is licensed under Creative Commons. This means a vast array of software is available for free use with attribution. For example in Jack's software module A_GPS routine that is parsing the NMEA sentence RMC (position, speed, track) you see the line "GPS Reading based on code by Igor Gonzalez Martin. 05-04-2007." Instead of having to start from scratch, there was existing software that could be just tweaked, if needed at all to use. This is the miracle of the open source community. In the case of a marine autopilot there was a lot of existing usable code, but a good chunk Jack had to write himself.

Looking at the diagram above you will recognize a lot of the acronyms such as COG (Course Over Ground). There are a couple that your chart plotter doesn't typically show you. They are BOD (Bearing Origin to Destination) and CTS (course to steer).

BOD is a NMEA 0183 sentence that has the origin and destination waypoints, and the bearing between them to the destination. CTS is the direction you need to steer to get back on your original course line.

Rule one! Your autopilot is not allowed to just make up a new bearing to get to the waypoint. It's supposed to keep you on your original course line (BOD). CTS is not the direction the bow is pointing, but the direction you want to travel in. As an example, a sailboat may have to crab upwind to maintain the desired course.

This is done by calculating a XTE (Cross Track Error) correction factor that is added or subtracted from the existing bearing to waypoint. Using this correction a new heading can be derived to take you towards your original course. I've simplified this a lot, but this is a tricky bit of calculating software.

The system is operational. It steers by compass heading (Button 1), GPS steering to waypoint (Button 2), adjustable tack mode (button 3), and yet to be completed wind angle steer (Button 4). The system can also make incremental changes to the heading direction, has a helm data display, and control pendant. There is also gain and a form of response rate control (less pump usage). 

There are still some things not yet completed, and assorted minor software issues. Jack has Raymarine wind instruments that speak Seatalk. Rather than write a routine from scratch to parse Seatalk, I have a Raymarine Seatalk to NMEA converter lying around someplace that I'm going to send him. This will speed up development of this wind integration portion of the system.

When running a route, the vessel doesn't start the turn until you have arrived at the waypoint, and this can cause a overshoot on the next leg when turn angles are large. It corrects itself, but it would be better, if the turn started prior to waypoint arrival. There have also been some intermittent system freezes when a new route has been completed, and there are also some issues with the GPS's 1 second update speed. Some of this might be correctable with a faster 10Hz GPS. Have no doubts, that Jack is a persistent guy, and these warts will be found, and removed.

Jack has done an amazing job, and I think he is now one of the "Giants" others can stand on the shoulders of. The project continues on, and it proves it's feasible to do this with the same capabilities of mainstream commercial autopilots, at a fraction of the cost. Jack is also the only person I'm aware of who has gone this far in the development of a Ardunio based marine autopilot system. For those who are interested in pursing this type of activity, there is now a substantial library of software and hardware details  in his Dropbox site you can use to start with. I will provide the link below.

Jack is now so far along in his development his software, like all autopilot manufacturers he now has a disclaimer splash screen, and I think this speaks volumes about Jack's efforts.

"This software was developed as an experiment by the author to provide an auto pilot for his boat. It is made available to others who want to develop a Do It Yourself autopilot. The User accepts all responsibility for the safe operation of the boat recognizing that hardware and software errors can occur. The User also acknowledges that it is their responsibility to safely wire and install the autopilot components in accordance with appropriate codes and standards, and understand the system capabilities."

I now have an Ardunio Mega. I couldn't live without one after writing so much about them. It's huge fun to play with, for me at any rate. I think the first real project will be to make the "Digital Magic Eight Ball". This will give me some experience with writing to a display, and you can bet it will have some interesting prognostications. The second project is to make a sailboat wind instrument with a display for under $200 using the Peet Bros. anemometer. Robert Huiteme has written most of the code, and the balance I can figure out myself. It's good to have broad shoulders to stand on.

Jack Edwards Ardunio marine autopilot drop box link. You will also find his email link there.

The software requires Ardunio's IDE system to view. You can download it for free here. It is available for Windows, Mac OSx, and Linux 32/64 bit operating systems.

The wiring diagrams require Fritzing software to see, and it's free from here.

Product phot0s are from the Pololu and Sparkfun websites.

All other diagrams and photos are by Jack Edwards.

21 comments:

  1. I love the "tinkerer" impulse when translated to modern electronics and coding projects. While I don't personally feel I have the time or the drive to master the intricacies myself (even if they probably aren't as daunting as I might assume they are), I really like those sort of projects where you can dig down into how the thing actually works, and can thereby understand it completely.

    A very inspiring post, Bill.

    ReplyDelete
    Replies
    1. Rhys, in not a long period of time, someone like me will write a step by step set of instructions that will help someone implement this package. I'm follow said steps in doing the Magic Electronic Eight Ball project. Standing on the shoulders of giants so to speak.

      Delete
    2. Maybe I'll hold off on that W-H AP purchase, then, although with a dual-helm hydraulic setup (Marol, a Japanese commercial fishing boat hydraulic actuator type), I require "simple and robust".

      Good stuff, nonetheless. I really like reading about "homebrews that work".

      Delete
  2. Great article, Bill, and hats off to you and Jack Edwards for reminding us that we can build as well as consume. After all, we're not stupid. :-)

    ReplyDelete
  3. Thanks DB. It's a testimony to man's/woman's ingenuity. Toss out open source standardized hardware to thousands who all share their software efforts and adventures, and amazing things can happen.

    ReplyDelete
  4. great project but lots of unnecessary cost. you can get the same or better imu for 20$. a 10hz gps for 30-40$, and you only need one mega (heck you could probably do it on a leonardo) and that motor driver is ridiculously expensive.

    ReplyDelete
    Replies
    1. Jordan, thank you, and you have a nice blog. I do think you should shorten the entries by using a jump break, I cared. Jack was having some throughput issues due to the 1Hz GPS/NMEA, and the IMU 50Hz smoothing and processing time. This was solved by adding the second Ardunio. The motor driver is a bit of an overkill, but the thing that fails first in a marine autopilot are the FETS. I know this because I see it all the time. So overkill in a boat is never a bad thing. Jack has gone further than anyone else has in using Ardunios to build a fully functioning marine autopilot. I don't think it was ever really about the money, it was the challenge of doing it, and the learning that came with it. It's an Arduino thing.

      Delete
    2. yeah i think i know what you mean haha. you might be interested in the Energia project. They are working on an ARM compatible Arduino IDE so you essentially have 80MHz of processing power and yet the simplicity of arduino code. Although not everything quite works yet, but i think this project would be possible without too much hassle. It would depend on how many libraries it uses. But all that's irrelevant if it was just for the learning experience haha.

      Delete
  5. Hi Bill, thanks for highlighting this. Jack and Robert are my heros. I have been travelling this path with the vision of something like Jack's. I've built a GPS readout and now a talking compass, using an EMIC2 text to speech module. Regards,

    ReplyDelete
  6. Practical Pirate, thanks for the original link to Robert's Freeboard site which started me down this road. I'm behind the Ardunio curve, but working hard to catch up with my little board.

    ReplyDelete
  7. jim caravan@myway.comJanuary 11, 2014 at 8:07 AM

    The internet amazes me - again. I have been toiling with learning C language for my idea to build an auto pilot for my boat. Now I find I am re-inventing the wheel. I thank you gentlemen, now I can get on with the mechanics instead of trying to learn C and write a program for arduino.
    Instead of hydraulics i will use a 12V linear actuator, just $50 on Ebay. My Arduino stuff is also Ebay.
    My question is: Why not use the $GPAPB sentence from the GPS APB = Auto Pilot mode B. It seems to have all the info needed to drive an auto pilot already calculated.... But Then I am probably missing something. As far as accuracy, I only want A/P when fishing and at 1-2 MPH the correction rate and overshoot should be minimal.
    Also a Ham, a Pilot, and a Great grandpa. Still keeping my hand in the electronic cookie jar.
    73

    ReplyDelete
  8. This is a very interesting article and project.

    Re the quote regarding standing on the shoulders of giants, I think it is misattributed. I believe it was first expressed by Issac Newton.

    http://en.wikipedia.org/wiki/Standing_on_the_shoulders_of_giants

    ReplyDelete
  9. I just discovered the Arduino, and placed an order for one. My first impulse was to apply it to steer my sailboat.

    BUT my needs are very much different. I daysail a 22-foot O'day. My needs are minimal. I just need to push a button when I'm on course, then have the autopilot hold that course. Pretty much exactly what a low-end Raymarine tiller pilot would do. Sure, I could just buy one, but a little simple unit with no keypad, no display, and light-weight mechanical requirements should be a fraction of the cost... plus the added bonus of putting it out there online for other people to build.

    So far, I've only found people who say they want to do this, plus one person (Jack) who actually did it, but not nearly as simply as a trailerable boat would require. We need to get a group of small-boat sailors together on this.

    ReplyDelete
  10. An interesting article. One thing I would like to add to people building these, is not all compasses are alike. For us Mono-Hullers' you have to dig into the data sheet for the specific compass IC and double check the angle of operation. My first mistake was choosing a cost effective one to play with, & it had a 30 angle limit, which caused some harry situations in the field & a lot of headaches.

    ReplyDelete
  11. I have made on as well:
    https://youtu.be/bEQQ-wsNISU

    ReplyDelete
    Replies
    1. Hi Tobias. Any chance of seeing your code. I am working down the same track, looks like I even have the same linear actuator, but am still in the designing stage. I do have some software to use the compass and other outputs from a smart phone via arduino bluetooth module.
      Thanks

      Delete
  12. I wonder if you can replace the IMU with the new MinIMU-9 v5 Gyro, Accelerometer, and Compass (LSM6DS33 and LIS3MDL Carrier)? I could find the Arduino library here: https://github.com/pololu/lsm6-arduino

    ReplyDelete
  13. I have rewritten some of the NMEA sentence parsing code to make it insensitive to the number of decimals in Lat and Lon format. It will now prett well accept any format.
    In addition Ifixed the range error in the GPRMC sentence.

    How do I get those changes to Bill for updating.

    Rexlee

    ReplyDelete
  14. Thank you for sharing your great project and code!!

    Have you ever planned to move this project to GitHub?

    ReplyDelete
  15. Super!!! Say me pls why model pump and motor you is use?

    ReplyDelete

Note: Only a member of this blog may post a comment.