Autopilot for boat (PART 2 – Programming)

Programming the microcontroller was the most interesting part for me. I learned a lot about good coding practice during my work on this project.

First thing here is to write parsers for GPS and electronic compass. Almost every GPS receiver returns the data which follows NMEA standards[1], and it wasn’t problem to implement parser on microcontroller. I used electronic compass which has very poor documentation, so I spent a lot of time on guessing some things until I finally managed to finish parser for it.

Another image of my boat
Another image of my boat

The next step was coding the complementary filter, which combines GPS position estimation and predictions based on heading and speed information. I mentioned earlier that I wrote simulation of this localization algorithm, so it was time to check the boat localization in real world. This part will be explained later.

My final goal was to make the boat track a straight line and to reach the given coordinates on the lake. After some consulting with mentors, I decided to use PID control[2] for motors based on the current heading. PID controller isn’t complicated to code, but it depends on three coefficients, whose setting requires a lot of testing on the lake.

I attached here my original source code in case that some of my explanations were not clear.