Tag Archives: boat

Autopilot for boat (PART 3 – Testing)

Testing is very important part of every project, so here I will explain how I tested important features of my autopilot.

After implementing localization system on microcontroller with GPS and compass, I needed to test it somehow. There are many ways for checking localization, and my way was to send data from microcontroller via XBee[1] to my computer. I wrote application for my computer which visualizes the data received from boat in real time, and have ability to send some commands back (reset, change coefficient, restart compass/GPS, etc…). After doing all this, I was able to test localization accuracy very easy. At first look writing this additional software seems to be useless, but after some additional coding, it became my main control panel.

Here is the sample screenshot of control panel application
Here is the sample screenshot of ‘cockpit’ application

Although the PID tuning is very time-consuming, there is way to make this process easier. Visualizing data is always good idea, so I added visualization of PID to my “control panel”. Values of P, I and D are shown independently, and it is very useful for tuning. One more useful tweak is allowing PID coefficients to be changed while boat is running. This saved me a lot of time.

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.


Autopilot for boat (PART 1 – Assembling the electronics)

Two years ago I started working on a very interesting project at Petnica Science Center[1]. The goal of the project was to hack an RC boat toy and implement an autopilot on it. Here I’ll tell you more about my experience on this project. First of all I needed to decide how to do localization of the boat. Autopilot systems on large scale boats use GPS to localize because it can give position estimate within 15m accuracy. In my case this error is big compared to the size of the lake where I planned to test the system. One good thing is that GPS systems have very accurate speed estimation which can be combined with some information about direction of moving in order to calculate current position. So, I decided to use a GPS module and an electronic compass in a combination with a microcontroller. Just to be sure in my decision, I made a simulation of localization algorithm in MATLAB and added GPS and compass errors from datasheets, and the output results were suitable for the project. My choice of equipment was a GPS module and a PIC32 microcontroller from Mikroelektronika[2], and an electronic compass from Mikrokopter[3]. This electronic compass has a built-in IMU which is very important because it compensates the error of heading measurements when the boat is shaking. Here comes the interesting part: choosing an appropriate RC toy. The most important thing here is to choose a toy which has enough free space for additional electronics. The second important feature is the power of motors because of the increase in the toy weight. I bought some used toy and I was ready to start working on the project!

This is the original toy which I used for the project
This is the original toy which I used for the project

It is very important to put all electronics and mechanics together at the very beginning. Ignoring this will cost you a lot of time in your later work. Although the best way for assembling electronics is printing a circuit board and soldering wires, I decided to use a breadboard and a lot of jumpers. The battery which came with boat wasn’t capable for working more than 15 minutes, so I needed to buy another one. Batteries are also very important for boat balancing, because they are the heaviest part in the whole boat. Another interesting problem is placing electronic compass such that other devices don’t affect its behavior. I had to rearrange all inner parts of boat several times until I managed to have the compass far from other components with strong magnetic field.

Here is how the boat looked like in some moment of assembling
Here is how the boat looked like in some moment of assembling