Start
Mecahnical Assembly
GPS - Digital
Compass
Proportional Servo
Circuit Description
Software
Test Modes
Crossing the Atlantic
Sources
Test
modes
Test
modes are controlled by SW3, SW4, and SW5. When SW5
is closed, data from the GPS is disabled, thus the
Roboat sails under control of the digital compass
only. Pushing SW3 stores the direction the Roboat
is presently heading to as the reference course so
the Roboat will sail straight along a fixed direction.
This is how the compass is tested.
When
SW4 is closed, the compass is disabled, which allows
the rudder to be controlled by only the potentiometer
(R8) and thus it can be adjusted for the Roboat to
sail straight.
Because
the Roboat software was written directly in assembler,
all the needed mathematics deals with integers only.
Latitude and longitude data need four-byte integers
to be wholly represented. A few basic operations were
developed to deal with such long numbers, in the form
of the subroutines: COMPAB, SWAPAB, ADDAB, SUBAB,
MULAB, and DIVAB. These subroutines are a development
of the basic assembler commands (cmp, mov, add, sub,
mul, div) and refer to the four byte registers REGA,
REGB, REGC and REGD.
The
subroutine DIST compares the distance to the next
waypoint (located at the coordinates DX,DY) with a
reference distance (RANGE), to define if the waypoint
is close enough to be considered reached.
The
formula for distances is:

But,
to avoid dealing with square roots, and because we
only want to compare distances, DX2 + DY2 is computed
without the square root and RANGE is squared instead.
The formula used in DIST then becomes (DX × DX) +
(DY × DY) compared to (RANGE × RANGE).
More
discussion is in order for ATAN operation, which computes
the ArcTangent of the ratio DX/DY.
First
of all, azimuths are represented with a one-byte value,
that indicates: North=$00, East=$40, South=$80, West=$C0,
as shown in Figure 7a.
In
order to work with integers only, the curves of the
tangent and cotangent functions are approximated to
a sequence of straight segments that describe the
functions quite closely in the range 1, 0, and
+1 (see the solid red line in Figure
7b).
The
program works on the coordinates of two points (X0,Y0)
and (X1,Y1), and starts determining the sector that
contains the direction (X0,Y0) -> (X1,Y1), by setting
the following flags:
if
(X0>=X1) then (flag2=0) else
(flag2=1)
if
(Y0>=Y1) then (flag1=0) else
(flag1=1)
if
(DX>=DY) then (flag0=0)
else (flag0=1)
The
value of flag2, 1, or 0 is entered in Table
2, the corresponding keyword is found and the
appropriate formula is selected to finally compute
the value of ArcTangent.
Another
operation that deals with simplified trigonometry
is the computation of adjustments for the rudder (see
Figure 8). The program compares
two azimuths (the GPS course in the direction of the
next waypoint to be reached and the compass course
in the direction where the Roboat is actually heading)
and then computes the new position for the rudder
inorder to steer from the present heading towards
the next waypoint.
The
position of the rudder is controlled by the length
of the pulse that controls the proportional servo.
This value is computed starting from a reference value
(rudder_trim) that is given by the rudder trimmer
(R8). The reference value can be adjusted to set the
rudder in the central position and it can vary between
$0500 and $1100 (±45° rotation of the servo wheel).
Then
(course_diff) is computed as the absolute value of
(GPS_course compass_course). This difference
sets the amount of rudder steering left or right.
Until the difference between the two azimuths is small,
as in:

the
rudder steering is controlled proportionally. At the
difference value of $20 or +$20, the rudder
reaches its full right or left position and cant
turn any further so the software constrains the difference
value. When the difference value increases outside
the range of:

the
software simply cuts it to one edge of the range of
+/$20.
The
final formula depends on the comparison between the
GPS course and the compass course:
if
(GPS_course > compass_course) then: pulse_length
= rudder_trim - (course_diff × $28)
if
(GPS_course < compass_course) then: pulse_length
= rudder_trim + (course_diff × $28)
For
example, consider Figure 8 where:
compass_course
= $F0
GPS_course
= $30
course_diff
= | GPS_course compass_course | = $40 and
is finally cut to $20
Consider
rudder_trim set at the middle value = $0C00, then
the formula becomes:
pulse_length
= $0C00 + ($20 × $28)
=
$1100
This
pulse value turns the rudder completely to the right,
so the Roboat also starts steering right, thus heading
towards the next waypoint.