Friday, January 28, 2011


A difficult decision to make when displaying measurement values is how much damping to apply. Too much damping and you will miss rapid changes in conditions. No damping and quickly changing digital displays become very difficult to interpret. One solution to this dilemma is to dampen all digital numbers, but to show both dampened and undampened values on analog displays. In this system, we use by default a running average over the last 4 seconds for damping. The running averages are recalculated each time a new value is received (10 times per second).
The following figures present around 19 seconds of data recorded during a beat (in an under-canvassed and badly trimmed boat, I must admit...). The dampened data is plotted in red over the real-time data.

Apparent wind angle (AWA)
True wind angle (TWA)

Speed through water (STW)
Velocity made good (VMG)

Apparent wind speed (AWS)
True wind speed (TWS)

Custom software (written in C++) has been developed for the notebook to build displays using the real-time data received through the USB port. The only limit here is imagination. The following clip shows how the data presented above look like in the chosen display (the background image can be changed to any one of your preferred vendor or your own). The analog display shows both dampened and umdampened apparent wind angle (AWA), with the dampened true wind speed (TWS) number in the center. In the right column, we find the following dampened numbers: speed through water (STW), VMG, wind direction and heel angle. Two analog sliders also repeat the STW and VMG values.


This other clip shows a debugging display receiving most of the same real-time data, undampened.


Wednesday, January 26, 2011

Gyro Compass Calibration








For the above points, the coefficients are found to be:

               A = 4.103844379
               B = -8.302380526
               C = 15.92628402
               D = 1.519510921
               E = 2.346228572

The fitted curve is drawn in red in the above figure.


Tuesday, January 25, 2011

Boat and wind speed calibration

A basic linear calibration is first programmed in the microcontroller. For boat speed, we can use the nominal specification of the Airmar transducer (4.8 Hz/knot). For the anemometer, a good starting point is 1.0 Hz/knot.

Then we go on a sea trial in which we make several slow turns by motoring at constant speed. We try to choose a calm sea with light winds and currents, but we cannot make the assumption of null current and wind, whatever we think or feel. In the general case, the boat drifts with the current as seen by the GPS. And the apparent wind speed depends both on the movement of the boat and any true wind speed over water.

During these tests, we record the following data: boat speed through water (STW), apparent wind speed (AWS), and speed over ground (SOG) from the GPS.

We will record a constant speed through water (STW) as we are motoring at constant speed. We will record a maximum SOG (SOGmax) as the boat goes in the same direction as the current, and a minimum SOG (SOGmin) as the boat is directly against the current. We will also record a maximum AWS (AWSmax) as the boat goes directly against the wind (AWS = boat speed + true wind speed) and a minimum AWS (AWSmin) when the boat goes with the wind (AWS = boat speed – true wind speed).

From these values, we can calculate the real speed through water:
               STW_corrected = (SOGmin + SOGmax) / 2
The correction factor to apply to the boat speed is:
               Boat_Speed_Correction_Factor = STW_corrected / STW

The correction to apply to the apparent wind speed is:
               Wind_Speed_Correction_Factor = STW_corrected x 2 / (AWSmax + AWSmin)

This test also provides the following information:

Speed of Current during test = (SOGmax – SOGmin) / 2
True Wind Speed during test = (AWSmax – AWSmin) * Wind_Correction_Factor / 2

We can repeat the process for 3 different speeds, for example:  hull speed, 2/3 hull speed and 1/3 hull speed. We can then construct a calibration curve covering the whole range of boat speeds.

Similarly we can construct a calibration curve for the lower range of wind speeds. Cup anemometers are known to have a very linear calibration curve, so that we can safely extrapolate our curve for higher wind speeds.

Here is an example from a preliminary trial test done with the system (STW in blue, SOG in brown, AWS in green).

In a calibrated installation, the STW line will cross the middle of both the SOG and AWS curves. The one that is correct is the SOG curve from the GPS. We see that STW line is too high (the reported boat speed is over-evaluated) and that the AWS curve is much too low (the reported wind speed is grossly under-evaluated).

We can now calculate the correction factors to apply to the reported values.

STW = 6.69 kts
SOGmin = 4.36 kts            SOGmax = 7.38 kts
AWSmin = 1.56 kts           AWSmax = 4.16 kts

STW_corrected = (4.36 + 7.38) / 2 = 5.87 kts
Boat_Speed_Correction_Factor = 5.87 / 6.69 = 0.878
Wind_Speed_Correction_Factor = 5.87 * 2 / (1.56 + 4.16) = 2.05

Speed of Current during test = (7.38 – 4.38) / 2 = 1.51 kts
True Wind Speed during test = (4.16 – 1.56) * 2.05 / 2 = 2.67 kts

Monday, January 24, 2011

Two microcontrollers for the task

1- BDMICRO MAVRIC-IIB Controller (ATmega128)  

This is the master controller.

Ten times per second (10 Hz rate), it goes through the following cycle:

- it measures both voltages from the wind vane and translates this into the measured apparent wind angle, correcting for the installed offset;
- it calculates the apparent wind speed from the time interval between the last two pulses from the anomometer, applying the appropriate calibration curve;
- it calculates the measured boat speed from the time interval between the last two pulses from the starboard transducer, applying the appropriate calibration curve;
- as an I2C master, it fetches the slave I2C Olimex microcontroller working in parallel for its current values of:
- heading
- heel angle
- pitch angle
- rate of rotation
- GPS position
- speed over ground (SOG);
- course over ground (COG);
- measured boat speed from the port transducer
- it corrects the measured apparent wind angle for the heel angle;
- it chooses the appropriate measured boat speed (port or starboard) depending on the heel angle;
- it calculates the leeway angle from the measured boat speed and heel angle, using the appropriate calibration curve;
- it calculates the boat speed through water (STW) corrected for leeway;
- it calculates the true wind speed (TWS) and true wind angle (TWA);
- it calculates the velocity made good (VMG);
- using the heading value, it calculates the wind direction;
- using the SOG and COG values, it calculates the speed and direction of the current;
- it updates a running average over the last four seconds of the following values : STW, VMG, TWS, AWA, speed of the current;
- it sends these running averages on the SeaTalk bus for the repeaters to show;
- it sends all measured and calculated values from this cycle (in binary form) on the USB port for the notebook to update the main displays at the 10 Hz rate;
- it waits(!) for a timer signal to initiate a new cycle.

The controller also accepts commands from a terminal program through the USB port. When it receives such a command, it pauses from its 10 Hz cycle to perform the required action and report back to the terminal program. Such commands are typically used to change calibration values stored in the controller EEPROM.

2- Olimex AVR-MT-128 Development Board (ATmega128)

This microcontroller manages the compass, the GPS and one of the boat speed transducer. The compass and the GPS require each their own serial port, and the 2 serial ports of the main controller are already taken by the USB converter and the SeaTalk bus.  Likewise, the second boat speed transducer requires its own input capture pin, and the 2 input capture pins of the main controller are already used for the anemometer and the other boat speed transducer. Furthermore, the parallel processing provided by this microcontroller helps to achieve the 10 Hz refresh rate of the system.
This microcontroller is interrupt-driven and continually :
- reads the characters from the compass ASCII stream, and when a NMEA sentence is complete, extracts the required fields and converts the numbers in floating-point binary form
- applies the deviation correction to the heading value 
- reads the characters from the GPS ASCII stream, and when a NMEA sentence is complete, extracts the required fields and converts the numbers in floating-point binary form
- at each new pulse of the speed transducer, calculates the time since the last pulse and converts it in speed value, using the appropriate calibration curve
- as an I2C client, at the request of the main controller, transmits its current values of : heading, heel angle, pitch angle, rate of rotation, GPS latitude and longitude, SOG,  COG and measured boat speed.

Friday, January 21, 2011

Wind vane calibration

Accurate wind vane calibration is critical, as any small variation will significantly penalize the accuracy of many other results : apparent and true wind angle, VMG, wind direction, etc. By using the procedure described in this post, it is possible to achieve a typical resolution of 1/4 to 1/3 of degree.

The following figure illustrates the interface between the Raymarine transducer and the microcontroller. With a regulated 8.0 V supply, the wind vane produces 2 analog signals (the green and blue wires) varying typically between  2.9 and 5.3 volts. The exact range is influenced by the length of the cable going to the top of the mast. This is why it is necessary to calibrate only after the installation is complete on the boat.

The analog signals can be fed directly to two ADC (analog-to-digital) pins of the microcontroller, as the input pins can tolerate up to 5.5 V. The microcontroller uses a 5 V volt reference to convert the signals to a number ranging from 0 to 1023. All voltages higher than 5 V are reported as 1023.


The sine waves suggest that the rotation of the vane is translated in a back-and-forth movement of two sweepers on straight-line potentiometers. The output signals do not vary linearly with the angle, as is the case with designs based on circular potentiometers.
What is not apparent in the above figure is that:
·        the voltage amplitudes of the 2 curves are slighthly different;
·        their mean values are slightly different;
·        the phase angle between the two is not exactly 90 degrees.

Rigorous calibration involves the precise mathematical reconstruction of these two curves from a set of measurements taken on the boat during a trial run. To illustrate the procedure, an example with a reduced set of data points is presented here. In this example,we have gathered the following simultaneous green/blue data points (converted voltages) from a trial run on the water:

570/642              530/758              531/812              541/861              558/902
581/940              609/971              643/997              678/1017            879/1021
914/1004            944/983              968/960              987/937              1002/914
1014/892            1022/870            1022/692            1008/660            989/630
965/603              936/576              899/553              856/535              804/526
776/525              747/527              715/535              683/546              651/562
620/585              592/613              569/645              550/679              539/710

We have discarded all data with a 1023 value, as they are outside the range of measurement. We can now graph these green/blue pairs as X,Y points in Excel.

This may look like a circle, but it is in fact a slightly eccentric ellipse, with its axis slightly tilted, and its center slightly off the main diagonal. The next step is to find the equation of the ellipse that best fits these points. For this step, we use the NLREG software which has a convenient example of fitting an ellipse to data points (
     Parameter        Final estimate
           Xcenter           783.408681     
           Ycenter           782.546036      
         TiltAngle      0.0326530049 radian
              Xdim           254.549343       
              Ydim           257.708809   

We can now define the parametric equation of the ellipse

Note that NLREG has defined the ellipse with the major axis on the Y-axis before rotation (Ydim > Xdim). The parametric equation defines an ellipse on the X-axis before rotation, so we have to use the following relations in order to use it with the NLREG parameters.
     Xc = Xcenter = 783.408681
     Yc = Ycenter = 782.546036
     a = Ydim = 257.708809
     b = Xdim = 254.549343
     ϕ = TiltAngle – π/2 = -1.53814332 radian

The parametric equation gives the position of any point on the ellipse as we sweep around its center from 0 to 360 degrees, beginning near the bottom and going counterclockwise.  This is exactly the correspondance that we are seeking between a vane angle and any pair of green*blue values.

X(t) = 783.408681 + 257.708809 cos(t) cos(-1.5381432) – 254.549343 sin(t) sin(-1.5381432)

Y(t) = 782.546036 + 257.708809 cos(t) sin(-1.5381432) + 254.549343 sin(t) cos(-1.5381432)

The equation reduces to

X(t) = 783.408681 + 8.413472 cos(t) + 254.4136524 sin(t)

Y(t) = 782.546036 - 257.5714342 cos(t) + 8.310324 sin(t)

We can now calculate and plot the fitted ellipse along the original points.

          t[deg]                X(t)                       Y(t)

0             791.8221527      524.9746018
1             796.2610018      525.1588663
2             800.6959359      525.4215335
3             805.1256041      525.7625232
4             809.5486572      526.1817317
5             813.9637478      526.6790313
6             818.369531         527.2542704
7             822.7646647      527.9072739
8             827.1478103      528.6378428
...           ...                          ...
...           ...                          ...
354        765.1825947      525.5169396
355        769.6165261      525.2304464
356        774.0546587      525.0223339
357        778.4956406      524.8926657
358        782.938119         524.8414812
359        787.3807408      524.868796
360        791.8221527      524.9746018

We can also now reconstruct the green and blue signals from the equation results.

We already know that the vane is pointing forward (AWA = 0) when the green signal is at or very near its maximum value. There is a (approximately) 90 degrees offset between the zero angle of the equations and the zero AWA. We will now apply a preliminary offset of 90 degrees to the results of the equation so that we can graph the curves with respect to this nominal AWA. Even if this offset is not exactly 90 degrees, the remaining small adjustment will be merged in the final offset adjustment that we will have to make to correct the alignment of the transducer with the centerline of the boat.

We use only the thick lines for calibration, where the values are between the intersection points of 964 and 602. When the green value is outside the red zone, we use the blue curve, otherwise we use the green curve. When we have determined the color of the curve to use, there are 2 possible angles for the same value, which we can separate by noting if the blue value is greater or lesser than the green value.

For efficiency, we precalculate the angle for each thick line value inside the red zone, so that the green (or blue) value defines an index in a lookup table. The lookup tables are stored in the flash memory of the microprocessor.


This is a lot of work but it has to be done only once and we are rewarded by a resolution varying from 0.23 to 0.32 of a degree, depending on the angle.

Future enhancement considered : add an external 12-bit ADC chip connected through SPI bus to achieve a resolution better than 0.1 degree.

UPDATE :  I am now using a simpler method to calibrate the wind vane. See also here for the related microcontroller code.