Autopilot Prototype

33
 Autopilot Prototype HENRIK FLORIN Examensarbete Stockholm, Sverige 2010 

Transcript of Autopilot Prototype

Page 1: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 1/33

 

Autopilot Prototype

H E N R I K F L O R I N

ExamensarbeteStockholm, Sverige 2010 

Page 2: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 2/33

 

Autopilot Prototype

H E N R I K F L O R I N  

Bachelor’s Thesis in Computer Science (15 ECTS credits)

at the School of Computer Science and Engineering

Royal Institute of Technology year 2010 

Supervisor at CSC was Patric JenfeltExaminer was Stefan Arnborg

TRITA-CSC-E 2010:181 

ISRN-KTH/CSC/E--10 /181--SE

ISSN-1653-5715 

Royal Institute of Technology

School of Computer Science and Communication

KTH CSC

SE-100 44 Stockholm, Sweden

URL: www.kth.se/csc

Page 3: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 3/33

 

Abstract

Autopilot prototype

The main goal of this project is to get a better understanding of how an autopilot for a recreational boat is createdand how it could be developed further. More specifically the project aims at answering two questions,

1.  Can a basic autopilot be created with a standard eight-bit microcontroller?2.  How can the autopilot that is created during the project be further developed?

The autopilot was created by using an Arduino Mega board together with a H-bridge, a rudder feedback unit anda solid-state digital compass. The software was created using C++.

The design of the software was centred around two controllers, one taking in the current and desired heading andoutputting the desired rudder position while the other handled the actual rudder positioning. The first controller was created using a P-controller while the other used a simpler approach. The software also included means of altering the overall sensitivity of the autopilot and a user interface containing an LCD display and four buttons.

The project concluded that a basic autopilot could be created using the specified hardware and methodsdescribed in detail in this document. An important fact that led to the chosen design was that it made the

autopilot robust and independent of the design and behaviour of the boat.

Further development of the autopilot can be done by for example using a larger full colour display, addingsupport for GPS signals, removing the need for the rudder feedback unit and adding auto-tuning capabilities.

Prototyp av autopilot

Det huvudsakliga målet med detta projekt är att få en bättre förståelse för hur en autopilot för en fritidsbåtägare

skapas och hur den kan utvecklas vidare. Mer specifikt ämnar projektet till att besvara två frågor,

1.  Kan en grundläggande autopilot skapas med en standard åtta bitars processor? 2.  Hur kan autopiloten som skapas under projektet utvecklas ytterligare? 

Autopiloten skapades med hjälp av ett Arduino Mega kort tillsammans med en H-brygga, en rodergivare samt en

solid-state digitalkompass. Programvaran skapades i C++.

Utformningen av programvaran var centrerad kring två regulatorer, en tog in den aktuella och önskade kursenoch gav ifrån sig en önskad roderposition medan den andra skötte själva roderpositioneringen. Den förstaregulatorn skapades med hjälp av en P-regulator medan den andra används enklare metoder. Programvaran

inkluderade även funktionalitet för att förändra den totala känsligheten av autopilot och ett användargränssnittinnehållandes en LCD-display och fyra knappar.

Projektet kom fram till att en grundläggande autopilot skulle kunna skapas med den angivna hårdvaran ochmetoder som beskrivs i detalj i detta dokument. Ett viktigt faktum som ledde till den valda konstruktionen var attdet gjorde autopiloten mer robust och oberoende av design och beteende av båten.

Vidareutveckling av autopilot kan göras genom att t.ex. använda en större färgskärm, lägga till stöd för GPS-

signaler, ta bort behovet av roder givaren samt att ge autopiloten möjlighet att ställa in sina parametrar automatiskt.

Page 4: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 4/33

 

Page 5: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 5/33

 

Tableofcontents

1Introduction...................................................................................................................................1 1.1Background................................................................................................................................................................1 1.1.1FlotecMarinAB................................................................................................................................................1

1.2.Purposeandscope.................................................................................................................................................1 1.3Delimitations.............................................................................................................................................................2 1.4Definitions,acronymsandabbreviations ......................................................... ............................................ 31.5Literatureoverview................................................................................................................................................3 1.6Overviewofthedocument ........................................................ ............................................................. .............4

2Method.............................................................................................................................................5 2.1Planning.......................................................................................................................................................................5 2.2Production..................................................................................................................................................................5 2.3EvaluationphaseandPresentation.................................................................................................................5

3Theory..............................................................................................................................................6 3.1Automaticcontrolengineering..........................................................................................................................6 3.1.1PIDcontroller....................................................................................................................................................7

3.2Motorcontrol .................................................... ............................................................. ........................................... 83.3TheNMEA0183protocol .......................................................... ............................................................. .............9

4Design............................................................................................................................................ 104.1Autopilotfunctionality ...................................................... ............................................................. .................... 104.2Software............. ............................................................ ............................................................. .............................. 11

5Implementation.........................................................................................................................125.1Hardware ............................................................ ............................................................ ......................................... 125.1.1Wireconnection........................................................... ............................................................. .................... 13

5.2Software............. ............................................................ ............................................................. .............................. 145.2.1Headingcontroller ...................................................... ............................................................. .................... 145.2.2Ruddercontrollers.... ............................................................. ............................................................ .......... 165.2.3Headingdata........................................................ ............................................................. .............................. 175.2.4Userinterface...................................................... ............................................................. .............................. 18

5.3Tuning ........................................................ ............................................................ ................................................... 19

6Conclusionanddiscussion..................................................................................................... 21

Sourcereference...........................................................................................................................23

 AppendixA-Timeplan .............................................................................................................. 24 AppendixB–Completeclassdiagram................................................................................... 26 

Page 6: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 6/33

 

Page 7: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 7/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

1

1 Introduction

1.1Background

The use of autonomous systems has constantly been growing both in industries and in the every day life. This

type of technology is today used in everything between a children’s toy to the industrial robot that creates them.The main goal of an autonomous system is to relieve the need of constant human intervention, meaning that the

system should be able to manage its task on its own without constant human interaction. When it comes to achild’s toy this could be the task of moving around a room without hitting the walls while an industrial robotmay have to assemble a certain product without doing any errors or hitting other equipment situated nearby. In

general autonomous systems exists in many shapes and forms but their use have become a must in the society.

Within the marine industry autonomous systems are used both to produce equipment and to monitor them. Oneexample is to produce and monitor steering equipment for boats. There is a distinct difference betweenmechanization and automation. A steering system for a boat will help the user to steer the boat by relieving some

of the muscular requirements of steering the boat (mechanization). On the other hand an autonomous system,like an autopilot, would steer the boat in a predetermined direction or even to a predetermined location.

When it comes to autopilots created for use in the marine business then the bare minimum of what it should beable to do is to steer the boat in question in a predetermined direction. This is often done be using sensors likecompasses, GPS-units and rudder feedback units. If an autopilot can accomplish this task then technically it

could be sold and used in a smaller boat. Most autopilots today provide the user with more functionality than juststeering towards a predetermined direction. A small list can be seen below.

•  The user can manually steer the rudder / motor of the boat using the autopilots interface.•  The user can connect a GPS and steer towards a specific position.•  The user can connect a plotter providing the user with a graphical representation of the sea chart and

steer through a list of predetermined points on that map.

Today’s autopilots have the capability of performing the above-mentioned tasks but lack the reliability of doingso. An autopilot could fail at some point and when it comes to risking human life then most would agree thatsome monitoring of the system would be best. In other words, today’s autopilots can perform the task of steering

a boat but can in general not be left solely responsible for this task. It is therefore mostly used as an aid to thecaptain of the boat and not to replace him or her completely.

Autopilots are also in constant development and new features are created. One of the most resent developmentsis that many autopilots are considering taking away the rudder feedback unit for smaller boats. This is a featurethat can be seen in newer autopilots. Other functionality that is sometimes included in the autopilot is

information of wind in order to construct specific functionality for sailboats.

1.1.1FlotecMarinAB

Flotec Marin is small Swedish company that specializes in hydraulic steering systems and autopilots for both

 private smaller boats as well as bigger commercial ships. The company is the main distributer of several brandsof hydraulic steering and autopilot in the Nordic region and is constantly striving towards improving their 

 products in collaboration with manufacturers. As the main distributor of their product the company has a vital

 part in the further development of their products.

Their customers today consists mainly of private people and companies working with recreational boats. Thestore is located at Södermalm in Stockholm and the company has three employees.

1.2.Purposeandscope

The main goal of this project is to get a better understanding of how an autopilot for a recreational boat is createdand how it could be developed further.

More specifically a prototype of an autopilot with at least the minimum requirement mentioned in section 1.3will be created during the project. The system will be tested both in a lab environment and in real life, if 

 possible, and ideas for further development will be discussed.

Page 8: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 8/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

2

There are two main questions that should be answered during the project:

1.  Can a basic autopilot be created with a standard eight-bit microcontroller?

2.  How can the autopilot that is created during the project be further developed?

1.3Delimitations

The limits of the project will mainly be centred on the hardware that will be available and the time limits of the project. A more detailed description of the projects goal can be found here.

1.  Creating a functional prototype of an autopilot for recreational boats.•  The autopilot should be able to take in information from a NMEA compass and parse out

information of the current heading.•  The autopilot should be able to take in information from a rudder feedback unit regarding the

 position of the motor / rudder and interpret it in a correct way.

•  The autopilot should be able to set the motor / rudder in a specific angle within some error margin.

•  The autopilot should be able to make the boat steer in a predetermined direction within some

error margin.•  The autopilot should have some sort of interface towards the end user letting the user control

the autopilot.2.  Testing of the autopilot.

•  Each item in part 1 must be tested separately in the lab as much as possible.•  The system will be tested as a whole in the lab.

•  If possible then the prototype will be tested in a real world environment, meaning a real boat.3.  Discussion of further development.

•  After the test phase of the project then further development of autopilots will be discussed.

This will lead to some conclusions regarding what would be the best course of action in further development.

Table 1 lists the main hardware that was chosen during the implementation of the system.

Table 1: Hardware that is used to construct the autopilot.

Name AmountApproximate

price (kr / item)Description

ArduinoMEGA

1 520

Arduino is an organisation that strives to make hardwareand software that makes it easier to construct an embeddedsystem. It has a large community of people that helps and

share their knowledge and achievements. The ArduinoMEGA is their largest microcontroller chip. Moreinformation can be found athttp://arduino.cc/en/Main/ArduinoBoardMega.

Simple H 1 590

H-bridge constructed by the American company Robot

Power. The product is designed to be able to withstand acurrent up to 20 A.

ECS1 1 1 550

An NMEA based compass constructed by ElpromaInstruments in Holland. The compass is said to send thedata sentences needed in the project at a adequate rate (fromonce every second to ten times per second depending on the

type).

LCD 4 *

201 150

An LCD that has 4 rows and 20 columns giving it a total of 

4 * 20 = 80 characters that can be displayed at ones.

R1396W

 button4 27 A push button with embedded white light.

ML-40+ 1 10 000 Hydraulic steering unit including hydraulic pump.

Remaininghardware 1 400

Includes all connections (wires and brackets), screws, leadetc.

Page 9: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 9/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

3

1.4Definitions,acronymsandabbreviations

Table 2 provides definitions, acronyms and abbreviations that are used in this report.

Table 2: Definitions, acronyms and abbreviation used in this report.

NMEA 0183

 NMEA stands for the National Marine Electronics Association, which is an

organisation that strives towards a standard for all marine electroniccommunication. The NMEA 0183 is one of its standards for serial

communication in a marine environment. This will be further described inchapter 4.

PIDA controller that strives to keep a measurement at a given value bymanipulating some output. Further discussed in chapter 4.

ASCIIA standardized way of encoding characters in binary form. For example thecharacter ‘a’ is ‘0110 0001’ in binary code.

RS-232 Is an electrical standard for a serial databus.

Baud rateThe rate at which signals are sent from a sender to a receiver. One baudrepresents that one signal element is sent per second.

Stop bit

In serial communication one byte is sent at a time. This means that 8 bits aresent after each other to form one byte (character). One can chose to add one or 

several stop bits after each byte that is sent in order to separate the bytes.

Parity

A character takes up 7 bits of an byte when sent through serialcommunication. The last bit can act as a parity bit adding a ‘1’ or a ‘0’ to the

 byte. This is done to ensure that the number of ones or zeros always is odd or even. This fact can later on be used to perform simple error detecting.

HandshakingCan be done before the communication of two devises. The rules at which thecommunication will be performed are then agreed upon.

1.5Literatureoverview

Most facts are either taken from organisations operating in this field or academic literature. For example thereferences to the PID controller are all taken from the academic world while when talking about motor controlmost facts are taken from organisations and resources that take a more practical approach in describing themethods.

Since the NMEA protocol is not open the author chose to take in several references to all data that was used andcomparing them to the actual behaviour of the NMEA compass that was used. This was mainly done in order to

save cost and time but also to construct the autopilot to foremost work with the NMEA compass that waschosen.

Page 10: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 10/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

4

Below is a short description of the literature that was used during this project.

Table 3: Short description of the reference used in the document.

Bennett Peter, 2008, “The NMEA

 FAQ Version 6.6” 

Gives information about the NMEA-0183 protocol and itssentences.

Barr Michael, 2001, "Pulse Width

 Modulation"  Article published by Netrino and other organisations aimedat spreading information about embedded systems. Thisarticle handles information about pulse width modulation.

Cooper Douglas J., 2008,“Practical Process Control, Proven

 Methods and Best Practices for 

 Automatic PID Control” 

Douglas J. Cooper is a Professor at the University of Connecticut. This is one of his books published on the

internet handling PID controllers. The book takes a more practical approach with more information on setting up aPID controller and tuning it.

Elproma, 2010a, “Electric

compass sensor ECS1” 

Elproma is a company selling solid-state digital compass

among other things. The information found here is mainlyused in order to understand how the compass sends out itssignals.

Elproma, 2010b, “Compass

inverter”  Information gained from direct contact with the company.Engineering Knowledge, 2007,“DC Motor Control and 

 Interfacing” 

An organisation aimed at spreading the knowledge of how to

work with embedded systems and more. This article handlesthe basics about how to handle DC motors with PWM.

Flotec Marin AB, 2010,“AP47/AP47R Autopilot” 

Information of how one of the autopilots sold by FlotecMarin AB (job initiator) works. Pictures from this reference

have been used in this report. The autopilot is manufactured by TMQ.

Glad Torkel, 2007, “Reglerteknik,

 grundläggande teori” 

Student literature teaching the basics of automated control.Much of the book handles PID controllers and takes a moretheoretical and mathematical approach.

National Marine Electronics

Association, 2008, “NMEA 0183

Standard” 

Organisations responsible for the maintenance of the NMEA

 protocols.

TMQ, 2009, “AP46Pulsing” 

TMQ is a manufacturer of autopilots situated in Australia.

This documentation gives information of their way to handlethe PWM pulsing to the motor controlling the rudder 

 position. The information is gained through direct contact

with the company.

Raymond Eric S., 2010, “NMEA

 Revealed” 

Gives information about the NMEA-0183 protocol and its

sentences.

1.6Overviewofthedocument

The document starts by describing the workflow that was used during the project. The document continues bydescribing the theory behind the autopilot (chapter 3 to 5) after which it starts describing the actual behaviour of the autopilot. Chapter 7 describes the methods at with the functionalities and behaviours of the autopilot wascreated ending with a description of the tuning of the system. The report ends with the conclusions drawn after the project.

Further information on the time-plan and a full class diagram can be found in Appendix A and B respectively.

Page 11: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 11/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

5

2 Method

The project contains several sub goals that need to be met in order to complete it. The handling of these sub

goals or phases of the project are illustrated and described in figure 1.

Figure 1: Graphical illustration of the workflow within the project.

2.1Planning

This phase contains all the work of gathering information and plan for the rest of the project. The informationgathered here would mainly be information of the hardware and software that will be used during the project andfocus will be put on getting all the information needed to start the next phases. The end result of this phase will

 be the project plan containing a detailed plan for the rest of the time.

2.2Production

The production phase contains four sub phases that are repeated until all the goals of the project are met. Duringthe time of the project the prototype can be seen as a working progress with constant need of upgrading andtesting. This is what the Production phase is for.

Table 4: The different phases in the project are explained.

Hardware phase

This phase contains all the mounting, soldering, wiring and ordering of hardware that is needed to complete the project. Technical information of 

the hardware used should also be gathered here.

Software phase

The software phase contains the creation of the software needed to controlthe hardware used for the prototype. Each part of the prototype will need acorresponding software library that controls it. These libraries together 

with some automatic control will in the end build up the actual autopilot.

Testing phase

Each part of the prototype will be tested individually and as a whole inorder to see how well they perform the tasks that they are created for.Testing data will both be used for fine-tuning each parameter in theautopilot and as a base for discussion in the next phase.

Theory phaseThe theoretical phase contains a more in depth exploration of the subject

focusing on finding literature and papers relevant to the project.

2.3EvaluationphaseandPresentation

During the previous phases and after the prototype has been built the analytical phase will start. This phase

contains an analysis of individual parts as well as the system as a whole and will support the conclusions drawnduring the project.

In the end of the project a presentation phase containing both oral and written presentation of the work done will be concluded.

Planning ReportingProductionHardware

Software

Testing

Theory

Page 12: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 12/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

6

3 Theory

This chapter describes the theory which the implementation is formed around. There are three main sections inthis chapter. The first talks about automatic control engineering and is focused on PID controllers. PID

controllers are commonly used within the industry to steer and control equipment. The naval industry is noexception. A PID controller will be implemented in order to steer the boat in the desired direction.

The second section goes into pulse width modulation. In order to steer the boat one needs some way of controlling the motor that pushes the rudder back and forth. One could either accomplish this by usingspecifically designed hardware for this task or one could use pulse width modulation and the digital ports already

found on the processor board. The later solution is both cheaper and easier.

The last section of the chapter describes the NMEA 0183 protocol, which is used by the compass used for theautopilot. NMEA is a standard within the naval industry that most, if not all, electrical devises uses for communication purposes. The section concentrates on describing the three sentences within the NMEA 0183

 protocol used by the particular compass used for the autopilot. The implementation of the autopilot needs to beable to parse out the current heading from these three sentences.

3.1Automaticcontrolengineering

Within the practice of automatic control engineering one often uses a controller in order to monitor and affect theoperational conditions of a dynamic system. A normal controller has at least an input value and an output value.

The input value can be seen as the information that the regulator gets at each step and the output can be seen asthe reaction that the regulator calculates after getting that input. Normally one separates controllers into one of two groups. The first group of controllers aim at following the input value by regulating the output. In this case

the input is constantly moving. The other group of controllers, and the type of controller that will be used in this project, aims at maintaining a desired value. The desired value (setpoint) is given to the controller together withthe current value (input) and the output is the calculated response.

A classic example of a system using a controller is a normal thermostat in a house that regulates the heating

system of the house in order to regulate the temperature. In this system the thermostat is the actual controller,which takes a temperature reading as an input and outputs the needed response from the houses heating system.The setpoint is then the desired temperature in the house. At each point in time the controller can come across

one of three scenarios,

•  The temperature in the house is to low. The controller signals the heating system of the house to warm

up the air in the house more. The actual increase in “power” that the heating system uses is calculated by the controller and depends on how far the actual temperature is from the wanted temperature.

•  The temperature of the house is too high. The controller signals the heating system of the house to

 produce less heat or to turn off depending of how the system works. The actual decrease in heat produced is calculated in the same way as when the house temperature was too low.

•  The temperature is at the right level and the controller gives the heating system the same command as

 before. This means that no change in the output of the heating system is needed.

This means that the rate at which the temperature in the house is changed is dependent on the difference betweenthe current and the wanted temperature in the house. If the difference is high then the controller will increase or 

decrease the temperature fast and vice verse.

Page 13: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 13/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

7

An illustration of the system can be seen below.

Figure 2: Illustration of the flow of information to and from a radiator controlling the temperature inside a house.

This is the basic concept of a controller that in theory does not seam to be that complicated. The challenge comes

when trying to fit a controller into a dynamic system. A dynamic system is a system that acts differentlydependent on its settings and the surrounding environment. The thermostat may need to order the heating systemto produce more heat if the surrounding air is moist then if it was dry to reach the same temperature for example.The heating system might also need more energy to heat the house one degree if the current temperature is at 25

instead of 20 degrees Celsius. This fact puts additional demands on how the controller performs its calculations.

The controlled system can either be closed or open looped. In a closed loop system the input depends on the

output signal. In the case of a thermostat the input depends on the output in the way that the temperature in thehouse is dependent on the output of the heating system. In this type of system one needs less understanding of the systems dynamic behaviour. In the meaning of the thermostat then one only needs to know that the housewill get hotter if we give a higher output to the heating system and colder if the output is lower. An open systemon the other hand is more dependent on the controller having a good understanding on dynamic behaviour.

Many different solutions exist to this problem but one of the far most commonly used in the industry today is thePID controller. (Cooper Douglas J., 2008)

3.1.1PIDcontroller

All reference to setpoint, input- and output-values will in this section refer back to the installation shown infigure 3. The PID controller calculates the error in each time step by taking the input value minus the setpointvalue. The error is then used in three separate sections that are then combined to form the actual output. Each

section takes different aspect of the systems behaviour into account. The output is a weighted sum of theindividual terms. In other words, the weights control how much the output is dependent on the specific

 behaviour that the respective terms take into account. The different terms are listed in table 5. (Glad Torkel,

2007)

Table 5: Description of the three parts of a PID controller (GladTorkel, 2007).

Section Name Description

P ProportionalThe proportional part takes the error and calculates a proportionaloutput. The growth in the output is both proportional and linear to theerror in the input.

I Integral

The integral part of the controller is proportional to the integral of the

error. The integral will be growing as long as the error is positive anddiminish when the error is negative.

D DerivativeThe derivative part takes the current direction of the error intoaccount. Its output depends on if the current error is growing or diminishing.

The mathematical formula that is used to calculate the output differs between implementation but the one thatwill be used in this project can be seen below.

Input

temperature  power to heatingsystem

Output

SetpointDesiredtem erature

Page 14: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 14/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

8

Output =K  p ⋅ e(t ) +K i ⋅ e(τ )d τ 

0

 ∫  +K d d 

dt e(t )

 

K  p, K i and K d is the constant mentioned earlier.

One can choose to reject one or two parts of the PID controller by setting their constants to zero. A commonapproach is to start with a simple P-controller and then gradually adding the two other parts if needed. Table 6describes the main pros and cons of some forms of the PID controller.

Table 6: Pros and cons of different PID constellations (Cooper Douglas J., 2008).

PID Pros Cons

PA simple controller to implement that

gives a direct response given an error.

May not be able to remove the error. This

is the case for example, in systems whereone needs a non-zero control signal to stayat the setpoint value. The system is said to

have an offset from the setpoint.

PI

The integral part of the controller can

eliminate the offset of the simple Pcontroller.

A high integral part tends to over shoot thesetpoint and oscillate.

PID

The derivative part of the PID controller can compensate for the oscillation of the

PI controller and thereby give a smother and faster convergence to the setpoint.

The more constants that need to be tuned,the harder tuning becomes. Tuning theconstants in a PID controller can be hard.

3.2Motorcontrol

A motor controller is a system that controls the speed or position of a motor. A common type of motor that is

 being controlled is a normal DC motor. This type of motor is controlled both by the voltage and the currentgiven to it. The voltage taken in by the DC motor is an analogue signal dictating how fast it should go while thecurrent controls the torque of the motor. A normal constellation is to connect the DC motor to a H-bridge that issteered by the system, for example an Arduino board. In that way the motor is draining power directly from the

 power supply and can be controlled by the output from the circuit board. The speed is then controlled by theoutput and the torque is limited by the maximum current out from the power supply. (Engineering Knowledge,2007)

The analogue input of voltage posses a problem when using a digital output on a circuit board to control the

motor. A digital output can only output either high (normally 5 V or 3.3 V) or low (0 V). One therefore needssome way to translate the digital output from a circuit board to an analogue signal to the motor. One way of solving this problem is to use pulse width modulation (PWM). This method sends out a digital signal to the DC

motor in the form of a squared wave, meaning that the signal is high for a short time and then low for a shorttime. One cycle is seen from the time that the signal is high to the time it is low. The cycle is repeated at acertain frequency. If the frequency is high enough then the motor will not have adequate time to react to thechanges in voltage and will see an analogue input having the average voltage of the signal. Controlling theamount of time that the signal is high respectively low, often called duty cycle, can then control the voltage seen

 by the motor. Figure 3 shows three different wave signals (pwm signals) that would give the motor three

different voltages.

Proportional Integral Derivative

Page 15: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 15/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

9

Figure 3: Three different PWM signals that would give the motor a

voltage of 10 %, 50 % and 90 % of the digital high voltage (Barr Michael, 2001).

If the high signal of the digital output were 5 V then the voltage seen by the motor when using the threeexamples above would be 0.5 V, 2.5 V and 4.5 V respectively. (Barr Michael, 2001 and EngineeringKnowledge, 2007)

3.3TheNMEA0183protocol

The National Marine Electronics Association is an organisation that is responsible for maintaining severalcommunication protocols that are used in marine environments. One of these protocols is the NMEA 0183

 protocol, which describes how one sender can communicate with one or several listeners through serialcommunication. The protocol contains many different sentences that are sent as printable ASCII characters

through a RS-232 electrical interface. The signals through the serial communication are sent with the followingsettings.

Table 7: Electrical interface used by the NMEA 0183 protocol(National Marine Electronics Association, 2008).

Baud rate 4800

Number of data bits 8

Stop bits 1

Parity  None

Handshake  None

An important aspect of the NMEA 0183 protocol is that it is a one-way communication. This means that if twounits are to communicate with each other, sending and receiving information, then the electrical interface usedfor the communication has to be doubled. Meaning that each unit has to have one electrical interface for 

receiving information and one for sending it. (National Marine Electronics Association, 2008)

The NMEA 0183 protocol is not an open source document, however much of its sentences has been reverse

engineered and can be found on the Internet. Below is a selection of the three sentences that will be used duringthis project. The sentences are taken from (Institute of Computer Science Poznan University of Technology,2001). In order to make sure that the sentences are correct they are cross-referenced with several other sources.

Two of these sources are (Bennett Peter, 2008) and (Raymond Eric S., 2010).

Page 16: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 16/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

10

Figure 4: Figure describing the three NEMA 0183 sentences that will beused in the project (Institute of Computer Science Poznan University of Technology, 2001).

As can be seen above, each sentence ends with two ASCII characters representing a checksum. This checksum iscalculated by doing a bit-by-bit XOR calculation of all the characters between ‘$’ and ‘*’. The checksum is used

in order to eliminate faults in the sentence due to communication errors or disturbances.

In addition to the characters for each sentence that can be seen in figure 2 all sentences all end with a clear 

character (<CR>) and a line-feed character (<LF>) in ASCII code.

4 Design

4.1Autopilotfunctionality

Most autopilots today have two main modes, manual and auto. The TMQ AP46 autopilot sold by Flotec MarinAB is an example of this and inspiration has been taken from this autopilot when designing the prototype. The

 prototype of the autopilot will therefore also be designed with these two main modes.

Each of the main modes has a specific set of functionalities attached to it. The user is able to toggle between thetwo modes by pushing the AUTO button. Regardless of which mode the autopilot is in the user always has

access to the settings by pressing the MODE button. The settings menu can therefore be seen as a submenu thatis easily accessed by pushing the MODE button. When the autopilot is first turned on it is entered in manual

mode and the autopilot does not correct the course in any way. The user is able to manually steer the rudder by pushing one of two arrow keys.

The second mode that the autopilot can enter is the auto mode. When first entered in this mode the autopilottakes the current heading as the wanted heading and starts correcting the course in order to maintain that course.The user can correct the course by pushing the arrow keys. Each push changes the wanted course by one degree.

The user can also change the rudder ratio and the overall sensitivity of the autopilot by pushing down on the

MODE button. A number between 1 and 10 represents the rudder ratio and a higher number gives a larger rudder angle for a given error in course. The overall sensitivity is a number between 0 and 20 which in turn representthe amount of degrees off course that is acceptable. The autopilot will not correct the course if the error in thecourse in under the set overall sensitivity. A rough diagram of the autopilots functionalities can be seen in figure

5.

Page 17: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 17/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

11

Figure 5: State machine diagram of the autopilot.

4.2Software

The software that was developed is centred on two cascaded controllers. The first controller takes in the desiredand current heading and outputs a response for the rudder. The second controller takes in the outputted response

from the first controller and the current position of the rudder from the rudder feedback unit and outputs anaction for the motor. The action could be to move or stop the rudder. The second controller also has to regulatethe speed of the moving rudder. See picture 6.

Figure 6: Illustration of the two cascading controllers that the autopilotis centred around.

Page 18: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 18/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

12

5 Implementation

5.1Hardware

The hardware used in the project was chosen to match the functional requirements of the autopilot. Below is a

list of the hardware and why they were chosen.

Table 8: Reason why the hardware used in the project was chosen.

Hardware Reason for choice

Arduino MEGA

The Arduino Mega was chosen for its serial, digital and analogue

input capabilities. It has the capability to send and receive serialdata through one of three serial ports. Each serial port has a buffer attached to it and the receiving of data is handled in hardware by

continually writing data to the buffer. The handling of receivingdata from the compass does not have to be handled in software.

The analogue port is used for input from the rudder feedback unit

and the digital outputs are used for handling buttons, lamps, LCDoutput and does also have the ability to output pwm signals to steer 

the H bridge. The Arduino Mega has extra digital ports in contrastto other Arduino boards which was needed in order to connect allother parts.

The Arduino itself was chosen for its easy to use libraries and itsrich online community.

Simple HThe H bridge has a maximum load of 20 A that can be raised to 25

A with a cooling fan. This is adequate for driving the ML-40+.

ECS1

The compass that was chosen has the ability to send out the heading

signal ten times per second, which is a common requirement for many other autopilots. The compass is a solid-state digital compass

containing rate gyros, which compensates the output for pitch androll. This means that the outputted heading is less prune to errorsfrom pitch and roll.

LCD 4 * 20

The display that was used was a compromise between using a realcoloured graphical display and simpler 7 segment led displays. The7 segment led displays was found to be able to show too littleinformation at a time and the fully graphical display was though totake up too much time during development. The 4 * 20 character 

LCD display was thought to have adequate room to show theinformation that the user needed in order to use the autopilot.

R1396W buttonThe buttons was chosen for their ease of mounting and integratedlight.

ML-40+

(drive unit)

The ML-40+ is one of the products that is sold by Flotec Marin ABand has the advantage of having both a hydraulic cylinder and

motor in one unit. This means that working with oils was notnecessary during the project.

Rudder feedback 

unit (RFU)

The rudder feedback unit is the piece of hardware that sendsinformation on the current rudder position to the system. The unit is

 physically connected to the ML-40+ and sends the informationthrow an analog signal (between 0 and 5 V).

All hardware except for the ML-40+ was mounted on a board made of acrylic glass. As much as possible of the

wires were mounted on the back and put through holes in the board to be attached to the hardware. The boardwas also given four legs in order to give it some height from the table. This minimized the risk of accidental

short- circuits in the system. Connections to the compass and the 12 V current from the power supply was alsomounted on the top of the board for convenience.

Page 19: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 19/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

13

Figure 7: Picture of the autopilot on the acrylic glass.

5.1.1Wireconnection

 

Figure 8: Wiring scheme for the autopilot.

The H-bridge (motor controller) that controls the rudder needs two separate pwm outputs in order to work, oneto drive the rudder to the right and one to the left. The pwm outputs may not send a driving signal to both wiresat the same time, meaning that if the motor drives the rudder to the left the wire controlling if the motor drives to

the right must be set to output 0 and vice verse.

Page 20: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 20/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

14

5.2Software

The software was developed in C++ which is an object oriented programming language. Each part of the system,for example the two controllers described in chapter 6, was therefore constructed as a class or library. A

complete class diagram of the system can be seen in figure 8. The PID and the Rudderhandler classes representthe heading controller and the rudder controller. All settings of the autopilot and information of current status arestored within the Settings class. A more detailed class diagram can be found in Appendix A.

Figure 9: Class diagram of the system.

All Arduino based programmes have a main loop that the Arduino board goes runs over and over until the power is turned off. Most libraries in the autopilot have an update function that is called once every time the Arduino

 board goes over this loop. This function makes the necessary updates and changes that the specific class is madefor.

5.2.1Headingcontroller

The heading controller is a PID controller described in section 4.1. The PID controller takes the current headingas the Input and the desired heading as the Setpoint. A desired rudder position is then calculated and outputted.Since the NMEA compass outputs a new heading ten times per second then the PID controller should also follow

this frequency in its calculations. A timer interrupt is used in order for the system to call the PID controller tocalculate a new value at 10 Hz. The timer interrupt that is used on the Arduino board is the TimerThree that can

 be found on the Arduino Playground at <http://www.arduino.cc/playground/Code/Timer1> (20 August 2010).This library has the functionality to set up a timer interrupt that takes affect at regular intervals. In practice thelibrary has a flaw that results in the user having to test his or her way through its parameters in order to reach the

desired frequency. This is due to the fact that the library itself does not take into account the time it takes to callthe interrupt function and return to the original position in the program. The library does also not take intoaccount the time taken by the function inside the interrupt. This means that the user has to calibrate the library’s

 parameters in order to reach the desired frequency but when this is done the interrupts will occur at adequate

regular intervals. The error at whish the interrupts were fired when using 100 ms intervals were found to have anerror of +/- 2.5 ms.

Page 21: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 21/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

15

The PID controller that is used is made by Brett Beauregard and can be found on the Arduino Playground at<http://www.arduino.cc/playground/Code/PIDLibrary> (20 August 2010). A front-end for the PID regulator showing the Input, Setpoint and the Output at each time step was also used for tuning the system.

The integral and derivative parts of the PID controller have to be approximated from the data that is collected(sampled). For the integral part, simply adding the current error value to the former ones does this. Hence, the

integral part is very dependent on the time at which the data is sampled and the errors are calculated. If the datais sampling at even time intervals then the error in the integral calculations will be small while if the sampling isdone at sporadic time intervals then the integral part will have a lot of error in it. The same goes for thederivative part of the PID controller. In other words the accuracy of the approximations to the integral andderivative parts of the PID controller are highly dependent on the time interval at which one samples the data.

This dependency for the integral part is illustrated in figure 10.

Figure 10: Illustrates why the integral part of the PID controller is

dependent on even time intervals. The black line illustrates the error of the Input. Blue triangles illustrate a system with even time intervalsand red dots illustrate a system with sporadic time intervals. Dotted

lines are the calculated integral parts for the two different systems.

The values in the graph are fictive and only intended for explanatory purposes.

The difference between the two systems in figure 10 is clear which means that the special care taken to ensureeven calls to the PID controller is defendable.

The error that is calculated by the PID controller represent how far the current heading is from the wanted

heading. The output from the PID controller can be seen as the action that the boat should take in order to getcloser to the wanted heading. Both the wanted heading and the current heading are represented by a value

 between 0 and 359.9 in degrees. Special attention needs to be taken when the closest way to the desired heading

is to go from the maximum to the minimum heading that is when going from 359.9 to 0 degrees. For example, if one has a wanted heading of 10 degrees and the current heading is 300 degrees then one wants the PID controller to calculate an error of 70 degrees and not of 290 degrees. Both error calculations would result in a correction of 

the boat that would eventually lead to a correct heading but the later result would result in the boat making aunnecessarily large turn possibly resulting in a side trip. This is not a desired action and special care is taken toensure that this does not happen.

Page 22: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 22/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

16

The PID controller that is being used is also dependent on the current setting of the overall sensitivity. If thesensitivity is set to something over 0 then all errors under the set sensitivity calculated by the heading controller will be set to zero. A good example is when the boat is travelling in wavy waters constantly going up and down.

The course of the boat will then constantly change around one value. Say that the boats course will increase 5degrees when going up on a wave and decrease with 5 degrees when going down. In a situation like this it is notdesirable to correct the course for an error that is less than 5 degrees since the error will correct itself. The

overall sensitivity of the autopilot can be seen as an excepted error in course and is illustrated in figure 11. In thefigure a larger distance from the centre means a larger heading error. One can think of this as if the boat isconstantly going further and further to the sides until the autopilot corrects its course. The correction will take

 place at the lines and until then the boat will have an increasing heading error.

Figure 11: Overall sensitivity. Higher sensitivity (lower value in the

settings) will give the behaviour at the top of the image making theautopilot correct the course of the boat for smaller errors and thereforemore frequently (Flotec Marin AB, 2010).

5.2.2Ruddercontrollers

Initially two PID controllers were used, one for the heading and one for the rudder. The problem with thisapproach is that the second PID controller would output a value corresponding to the direction and speed that the

rudder should be driven to. In an Arduino platform this speed is normally a number somewhere between 0 and255. At high speeds the motor controlling the rudder will work fine and drive the rudder in the direction decided

 by the second PID. However, the motor has a limit on how slow it can drive the rudder back and forth. Values or 

rather pwm frequencies below that limit will cause the motor to stand still. This means that if one only use a P-regulator then one would get an offset as described in section 4.1. This can be handled by using an integral and aderivative part in the PID. However the outcome of testing such a system has shown that it is hard to reach

adequate congregational speeds through tuning the PID controllers constant. Speculations has also existed thatsuch a system would be much more dependent on the physical aspects of the boat, meaning that the constants of the PID controller will depend much on for example the inertia of the rudder and the boats behaviour at sea.

Instead of using two PID controllers one PID controller was used for the heading data and a simpler rudder controller was used. The rudder controller is called ones every loop of the program. Each time it is called upon it

will decide what to do with the rudder. The rudder controller can come upon the following situations.

•  The rudder is at its desired position within a margin of error (deadband) and the movement of the

rudder is stopped.•  The rudder is far from the desired position and the rudder is moved towards the goal position at full

speed.•  The rudder is close to the desired position and the rudder is moved towards the goal position in half 

speed marked as pulsing drive in figure 8.

The rudder is also checked for the following situations at all times. These situations have higher priority then theones described above and if any conflicts between the two arise then the response described below will be in

affect.

•  If the rudder is at one of its physical limits then it will be stopped from moving any further.•  If the rudder movement is changed from one direction to the other then a brief stop is made before the

change. This is done in order to let the hydraulic motor in the ML-40+ to settle before changing in

direction.

All the situations described in this chapter are illustrated in figure 12.

$ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $ $

$$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $ $$ $ $ $ $ $ $ $ $ $ $ $ $

$ $

$ $

$

$ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $ $ $$ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $

/

$ $ $ $ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $

$ $ $ $ $ $ $ $ $ $

$ $ $ $ $

Page 23: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 23/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

17

Figure 12: Illustration of all the situations that the rudder controller 

can come upon (TMQ, 2009).

5.2.3Headingdata

The compass that is used to receive the heading data is an Elproma sensor ECS1. It is a solid-state electronic

compass containing rate gyros, meaning that it will be less prune to send heading errors due to pitch and roll(marked as tilt in user manuals). The compass updates the heading ten times per second and sends it out througha serial communication protocol, in this case NMEA 0183. A more specific list of properties can be seen in table

9.

Table 9: Property of the Elproma sensor ECS1 (Elproma, 2010a).

Serial protocol  NMEA 0183

Update rate 10 times / second

Resolution 0.1 °

Tilt

compensationUp to 35 °

Output error max 2 °

Output change

with tiltmax 2 °

Repeatability 1 °

HDT 10 Hz

HDG 1 HzSignals and

frequency

HDM 1 Hz

Page 24: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 24/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

18

In reality the compass has been found to send out the three different NMEA 0183 signals that were described inchapter 3. Each of the signals is sent with a specific frequency and all sentences contain the heading information.This means that while the compass only updates the heading 10 times per second it also sends out its current

heading 12 times per second in total. In order to save computational time the autopilot only parses the HDTmessage, which will give it a new heading ten times per second. The risk of taking in all sentences is that theadditional two sentences each second can be sending an old heading that is not updated just for them. The

information that one gets from parsing these sentences can therefore be of no additional use.

When using the compass from Elproma one needs to invert all signals coming from the compass before readingthem. This can be done in software but since the Arduino board puts all signals in a buffer that is then read thenit is simpler to invert the signals electronically. An electrical scheme of how this is done is provided in figure 13.

Figure 13: Connection scheme for the Elproma sensor ECS1.

Connections are made in order to invert all data and the Arduino boardis marked as uC. The blue cable (marked in the figure with “Blue”) isthe signal cable from the compass (Elproma, 2010b).

The NMEA parser is called upon once at each loop of the program at which time it is updated with the latestcharacters received by the Arduino board from the compass. The parsing and updating of current heading is thenonly performed when a complete sentence is found. All messages from the compass are also checked by

 processing the checksum at the end of the sentence.

5.2.4Userinterface

The software controlling the user interface constitutes of two parts, a button handler and a LCD handler. Thegoal of the button handler is to check if the user has pressed any buttons and then calls the right function in therest of the system to reflect the users wishes. The button handler manages this by having an update function thatis called upon ones ever loop of the program. The update function checks the state of all four buttons andcompares them to the previously found state. If the state of one button goes from being pressed to being up then

the button is marked as pressed by the user and the corresponding action is initiated. This procedure is used in

order for the system to only mark a button to be pressed once every time the user pushes a button. The arrow buttons are also checked if they are being pressed during a longer time. This is done in order to be able to

 perform the power steer action when in manual mode. Figure 14 illustrates how the four buttons are set up onthe prototype board.

Figure 14: Illustration of the button configuration on the prototype board.

Page 25: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 25/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

19

The LCD of the autopilot has two main views. The first view is the main view that is shown at start-up andduring normal conduct. This view shows the user information of current heading, current rudder angle, currentmode, and is the autopilot is set to auto mode a course to steer is also shown. The design of the user interface can

 be seen in the picture below.

Figure 15: Picture of the main view of the LCD on the autopilot.

As can be seen in figure 15 the main view constitutes of tree parts. The upper left corner contains information of the current mode and the course to steer (CTS). The upper right corner shows the current heading with doublesized numbers and the lower part of the LCD displays the current rudder angle by displaying bars that

correspond to the rudder position. If the rudder is at its centre position then two half-filled bars are shown.

The second view is the settings view. This view has only a heading that describes which setting that is being

viewed and a corresponding value for that setting. The settings are changed by using two of the buttons and areimmediately changed when the user steps through the values. There exists several settings view handling severaldifferent settings that can be stepped through by pushing the mode button.

All details on the screen are constantly checked for updates and only the parts of the screen that contains oldvalues will be updated. This was done to minimize flickering in the display. Flickering was seen to appear if everything was constantly updated at each loop of the program.

5.3Tuning

Although the tuning of the system was not one of the main goals of the project a basic tuning was done duringthe project in order to evaluate the autopilots overall capacity to perform its duties.

The specific setup of cascaded controllers means that the heading controller does not produce any offsetdiscussed in chapter 4.1. This means that a normal P-controller should be enough in theory. A simple heading

simulator was created in order to test this theory in the lab. The heading simulator changes the current headingthat is inputted in the heading controller by linearly augmenting or decreasing it in accordance with the currentrudder position. In order to get a more revealing result on how the autopilot reacts then the sensitivity was set to

zero during the tests. Below are the result for a couple of different values for the P constant of the controller.Some results with a full PID controller are also shown in figure 16.

Page 26: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 26/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

20

Figure 16: The first four figures plot the behaviour of the autopilotwhen using a P controller as the heading controller. The P coefficientis set to 6, 7, 8 and 15 respectively. The last figure plots the behaviour 

when using a PI controller with P = 6 and I = 1. The upper area of each of the figures indicates the Setpoint and the Input of the PIDcontroller over time.

As can be seen in figure 16 one can construct a fairly good autopilot using a simple P controller in the lab usingthe above mentioned heading simulator. It can also be seen that if the P controller is given a too high P

coefficient then the behaviour of the autopilot will tend to start oscillate around the desired heading. It istherefore clear that in order to get an optimal result one needs to put more effort into tuning the coefficient of the

Page 27: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 27/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

21

P controller. The last figure shows the behaviour of a PI controller, which in this case never reaches the desiredheading. It should however be said that no effort has been put into tuning a PI or PID controller.

Although the autopilot behaves in a satisfactory manner when testing in the lab the behaviour in reality could bedifferent. In reality were the heading does not act completely linearly according to the rudder position then theapproach with just a P controller might not be adequate. Further investigation into the mater has not been

 possible during this project and will be left for future projects.

6 Conclusion and discussion

This project set out to answer the two fundamental questions listed below.

Can a basic autopilot be created with a standard eight-bit microcontroller? 

When looking at the prototype that has been created during the project and comparing it with the functionalitiesthat was listed in chapter 1.3 one can clearly see that all functionalities have been realized. The Arduino Mega

 board both has adequate computational power and programming memory for running the basic autopilot. Onecan even say that the Arduino board leaves place for further development. An example of this is the fact that the

 programmable memory in the board was only used up to approximately 15 percent.

The approximate hardware cost of producing the prototype in this project can be calculated to approximately1800 sek. It is important to understand that this cost is for producing the prototype and not a complete product. If 

the product were to enter a real production then one would have to create a custom made PCB and spend time on producing a casing for the autopilot. If the custom made PCB were to be produced at high volumes then the costof that hardware would be significantly less then the cost during this project. The casing would have a high

initial cost due to development costs but the production of larger volumes would also be rather cheap. Thesecosts do not include costs for development of the software and testing of the system.

This project aimed at looking at the complexity of a basic autopilot by creating a prototype. During the projectmany different ideas were though up and discussed but in the end the approach that has been discussed in this

document was chosen for its robustness and easy implementation. One very important property of this approachis that it will be independent of the configuration of the boat. This means that one does not need to tune the core

of the autopilot to the boat on which it is used. The tuning of the system was also made easier due to the fact thata simple P controller could be used. However this fact has not been tested in reality and the complexity of tuningthe system could potentially be higher in real life. In the authors mind more time needs to be spent on tuning andtesting in order to optimize the system. However optimizing the system has not been one of the main goals of 

this project it clearly shows that a basic autopilot can be created using the hardware listed in section 1.2 by usingthe approach discussed above.

 How can the autopilot that is created during the project be further developed?

One thing that is included in many autopilots today and that needs to be included in the autopilot created duringthis project in order to go further towards production is the functionality of taking in signals from a GPS unit.This functionality includes the ability of steering through waypoints from a plotter and correcting course after 

cross-track-error from the GPS unit. It would not be hard to add this functionality to the current autopilot. One

approach is to let the cross-track-error add a small correction in course depending on its magnitude, hence lettingthe autopilot steer towards the right path. However handling cross-track-error through GPS units has been

something that is outside the scope of the project. Letting the autopilot steer through waypoints is a mater of updating the wanted course after getting the information from the plotter.

Instead of taking in the current rudder position one could simulate the rudder by mathematical calculations. Thiswould eliminate the use of a physical rudder feedback unit, lessening the burden when installing the system andtaking away the cost of the rudder feedback unit.

During this project a simple LCD was chosen for its simplicity and capacity to show all the necessary parts of the user interface to the user. However one could greatly benefit from using a larger graphical display either in

 black and white or in full colour. In doing so one could create a more intuitive and informing user interface thatwould greatly increase the workflow in handling the autopilot. The software part needed to support a fully

graphical display would be significant. All parts of the display must be constantly checked for updates as wasdone with the simple LCD used in this project. The difference when using a bigger graphical display would be

Page 28: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 28/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

22

that the information that needs to be constantly checked would be much bigger and that all different displayoptions needs to be created stored and handled by the PCB.

An optional future development of the autopilot is to incorporate some type of self-tuning ability. This meansthat the autopilot would be able to tune its parameters automatically after the boat that it steers. Hence, it wouldmake the autopilot fit the boat better given time. This option is rather new to the market of autopilots and would

demand some ingenuity.

The three first features for the further development of the autopilot should not be that difficult to implement in astandard eight-bit micro controller like the Arduino Mega. The Arduino Mega both has the memory and the

 processing power needed for these features. The last feature talks about auto tuning, which could mean a lot of 

different things. One could for example have three different sets of tuning parameters that can be interchanged by the autopilot. This approach should also be small enough to be implemented in an Arduino Mega board. If one, on the other hand, wants a full neural network to be tuning the system then the memory and processing

 power of the chosen board would probably not be enough.

Page 29: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 29/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

23

Source reference

Bennett Peter, 2008, “The NMEA FAQ Version 6.6”,

<http://vancouver-webpages.com/peter/nmeafaq.txt>, (9 August 2010)

Barr Michael, 2001, "Pulse Width Modulation", Embedded Systems Programming, September 2001

also at

Barr Michael, 2001, ”Introduction to Pulse Width Modulation (PWM)”,

<http://www.netrino.com/Embedded-Systems/How-To/PWM-Pulse-Width-Modulation>, (24

August 2010)

Cooper Douglas J., 2008, “Practical Process Control, Proven Methods and Best Practices for Automatic PID

Control”, < http://www.controlguru.com/pages/table.html>, (13 August 2010)

Elproma, 2010a, “Electric compass sensor ECS1”,

<http://www.elproma.com/compass/Media/ECS1_SENSOR.pdf>, (18 August 2010)

Elproma, 2010b, “Compass inverter”,

Figure received by direct contact with the company (25 June 2010)

Engineering Knowledge, 2007, “DC Motor Control and Interfacing”,

<http://engknowledge.com/dc_motor_control_interfacing.aspx>, (24 August 2010)

Flotec Marin AB, 2010, “AP47/AP47R Autopilot”,

<http://www.flotecmarin.se/pdf/AP47SS23manualSV2010Rev3.pdf>, (24 August 2010)

Glad Torkel, 2007, “Reglerteknik, grundläggande teori”,

Studentlitteratur, Lund, Sweden, ISBN: 978-91-44-02275-8

Institute of Computer Science Poznan University of Technology, 2001, “The NMEA 0183 Protocol”,

<http://www.cs.put.poznan.pl/wswitala/download/pdf/NMEAdescription.pdf>, (9 August 2010)

 National Marine Electronics Association, 2008, “NMEA 0183 Standard”,

<http://www.nmea.org/content/nmea_standards/nmea_083_v_400.asp>, (9 August 2010)

TMQ, 2009, “AP46Pulsing”,

Figure received by direct contact with the company (12 July 2009)

Raymond Eric S., 2010, “NMEA Revealed”,

<http://gpsd.berlios.de/NMEA.txt>, (9 August 2010)

Page 30: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 30/33

Page 31: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 31/33

Page 32: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 32/33

Autopilot prototype - Bachelor’s degree

Henrik Florin

26

Appendix B – Complete class diagram

Page 33: Autopilot Prototype

7/27/2019 Autopilot Prototype

http://slidepdf.com/reader/full/autopilot-prototype 33/33

TRITA-CSC-E 2010:181 

ISRN-KTH/CSC/E--10 /181-SE

ISSN-1653-5715 

www.kth.se