PICAXE handling GPS for robot boat

Robin Lovelock

Senior Member
Hi Folks. I'm about to be interrupted by a local friend, working with me on the robot boats.

But, as expected, the faster 08M chips arrived today and I started to try my program
- got error messages. But the most worrying one seemed to be it not liking SERVO and SERVOPOS.
Is it possible that the faster chips do not allow SERVO and SERVOPOS ?
Maybe because the servo software only works at 4MHz ?

I thought I'd post this to save some time. I hope to start work again on it in a few hours.
Making the robot boat "sea worthy" ? Gosh ! I never thought of that: I'll be sure to discuss that novel ideawith my friend.
I was thinking of using one of those little rubber ducks for the hull - they've managed a few thousand sea miles so far :)

Robin
www.gpss.co.uk/autop.htm

@Robin.

re 08M2, it is just "drop-in" and then
a little code shuffling.

I modified
1. A program from two years ago,
2. Then Hippy's code.

Although I'm only testing from a static window-cill,
they both appear to work fine.

Code:
#picaxe 08M2
setfreq M32
#terminal 38400
main:
serin c.2,t4800_32,("$GPRMC,"), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27
;time
sertxd (b0,b1,": ",b2,b3," m ",b4,b5," s  UTC ",b10,b11,b12,cr,lf,cr,lf)
;deg N
sertxd(b13,b14," ",b15,b16,b17,b18,b19,b20,b21,b22,b23, cr,lf)
serin c.2,t4800_32,("$GPRMC,"), b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27
;deg W
sertxd (b0,b1,b2,".",b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,cr,lf)
sertxd ("Speed   = ",b13,b14,b15,b16,"knots",cr,lf)
sertxd ("Heading = ",b18,b19,b20,b21,b22,b23," degs",cr,lf)
serin c.2,t4800_32,("$GPRMC,"), b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27

sertxd( "Day =",b20,b21,"  Mon = ",b22,b23,"  Yr = ",b24,b25, cr,lf,cr,lf)
wait 32
goto main
Code:
serin c.3,t4800_32,("$GPRMC,")
SERIN 3, t4800_32, ( "A" )  ;A = GPS tracking or V = not yet tracking
SERIN 3, t4800_32, ( ",W," )
SERIN 3, t4800_32, ( "," )
SERIN 3, t4800_32, w2 'the GPS heading the boat is travelling
sertxd ("Heading = ",W2," degs",cr,lf)
wait 10
goto main
I seriously suggest that you order
a couple of 08M2 chips.
They are seriously powerful little beasts.

e
 

knight

Member
So if you were to operate a WSPR beacon outside the territorial waters of the UK & USA, what licencing conditions apply, possible none ?
In international waters I would expect that the International Telecommunication Union Regulations would still apply. That means to transmit in the Amateur band, you need to be a licensed amateur.

I may be wrong, but that would be my expectation.
(I'm not a lawyer, I may be wrong)
 

morrismarine

New Member
Well said- my view as well! All up perhaps Robin should just bite the bullet & install a ~160MHz marine AIS Class B transponder.These typically cost £500, but will also alert other vessels to the nature & course of his darling. Satellite reading of these is now underway too.

As mentioned before,a few hundred quid is probably near trivial beside costs involved in the overall seaworthiness of an unmanned ocean going vessel. Back in 1999 our local Trans-Tasman unmanned venture had >£20,000 (in todays money) thrown at it,but even then the dinghy sized craft proved not up to the task... In the spirit of Trans-Tasman rivallry I even teasingly offer the 1995 plight of their "Australia One" during an Americas Cup race.

Old salts no doubt recall "A boat is a hole in the water, surrounded by wood, into which money is poured"
To install an AIS unit you would need both a marine operators liecence and one for the vessel, you would also be opening yourself up to major legal issues if it happend to stumble into a busy shipping lane and created an incident, also as its main purpose is local identification via VHF it really doesnt do what you need. And you really dont want to let anyone else at sea know that it is there.

A cheap out of the box solution is an inmarsat C terminal, but i dont think its anywhere near your level of cheapness.

As for legislation on ships, if the vessel is a britished registered vessel then in uk waters and in international waters your following the UK law, however once you get into another countries waters at about 24miles you have to be following their laws.
 

eclectic

Moderator
. But the most worrying one seemed to be it not liking SERVO and SERVOPOS.
Is it possible that the faster chips do not allow SERVO and SERVOPOS ?
Maybe because the servo software only works at 4MHz ?
See Manual 2, page 213 (Latest edition)

Part quote "
Effect of increased clock speed:​
The servo command will function correctly at 4 or 16MHz (M2/X1 parts)8 or 32Mhz (X2 parts)4MHz (all other)​
No other frequency will work correctly"


 

Robin Lovelock

Senior Member
Many Thanks Eclectic - exactly what I needed. Now I'm making some real progress :)

Some of my earlier problems were due to my having an old version of the Editor (v5.2.4) and so, when I downloaded v5.4.0 it then began to accept those statements.

My latest code is below, and now Hipp's alternative statements work OK.

What a pleasure for SERIN and SERVO to work together, without that nasty switching of frequency :)

I'm sure you will see some mistakes, or improvements I could make in the code below. As it says in the comments, it seems the PAUSEs after the SERVOs are needed, before going back to the SERIN lines. I believe no PAUSE at all and it doesn't work. Half the time and the servo twitches. But what we have is OK anyway.

So now, the next step is to make use of that heading information in some way - maybe drive the same servo - or a different one.

I guess that will give me some needed exercise - walking around to get a changing GPS heading ! :)

Many Thanks everyone, and don't let my occasional sarcastic comments deter you from "off topic" comments.

Robin
www.gpss.co.uk

Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 2 August 2011 (c) Robin Lovelock www.gpss.co.uk/autop.htm 
'Thanks to Hippy, Eclectic, and others on www.picaxeforum.co.uk
'input is serial RS232 GPS data 
'the GPS outputs text strings and includes ",A," after $GPRMC when ready
'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'output is servo controlling rudder to steer boat on a particular heading

'note on behaviour of this test version:
'This is for use with the faster 08M2 chip
'after the startup waggle of the servo, it should monitor the GPS
'and put servo in position 1 if not tracking, and position 2 if tracking
'it now does do this, responding to if the GPS is tracking or not (silver paper over)
'It needed the LOW 1 to switch off SERVO before SERIN
'It gives a quick response to the GPS tracking or not tracking.
'polestar GPS red light flashes if not tracking, and solid if tracking.
' earlier tests...
' SERIN 3,N4800_8,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b1 'WORKS OK
' Now the 5 alternative SERIN also work OK. Yet to test more than the "A"/"V" value.
'It seems the PAUSE after SERVOPOS are needed to make it work
 
 #picaxe 08M2  
 setfreq M16

 'waggle servo on startup to show that working
 'SETFREQ M4 'standard 4MHz
 PAUSE 4000 
 SERVO 1,150 'start servo control process - middle
 PAUSE 8000
 SERVOPOS 1,75 'move servo to position 1
 PAUSE 8000
 SERVOPOS 1,225  'move servo to position 2
 PAUSE 8000
 SERVOPOS 1,150  'move servo to middle position
 PAUSE 16000 'wait 4 secs before main loop
 
 
 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 Low 1 'switch off SERVO
 PAUSE 1000
 'SERIN 3,N4800_16,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b1 'thanks Eclectic :-)

 'alternative SERINs to pickup the A/V into b1 but also GPS heading into w2
 'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
 'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18

 SERIN 3, N4800_16, ( "$GPRMC," ) 'thanks Hippy :-)
 SERIN 3, N4800_16, ( "," ), b1 'A = GPS tracking or V = not yet tracking
 SERIN 3, N4800_16, ( ",W," )
 SERIN 3, N4800_16, ( "," )
 SERIN 3, N4800_16, #w2 'the GPS heading the boat is travelling

 if b1 <> "A" then 'if GPS not yet tracking
   goto nottrk
 endif
 
 'GPS is tracking 
 SERVO 1,225 'start servo pulses
 SERVOPOS 1,225 'move servo to position 2
 PAUSE 8000 'at least 2 secs here - it seems this delay is needed
 goto waitgps

 
nottrk: 'GPS is NOT tracking
 SERVO 1,75
 SERVOPOS 1,75 'move servo to position 1
 PAUSE 8000 'at least 2 secs here
 goto waitgps
See Manual 2, page 213 (Latest edition)

Part quote "
Effect of increased clock speed:​
The servo command will function correctly at 4 or 16MHz (M2/X1 parts)8 or 32Mhz (X2 parts)4MHz (all other)​
No other frequency will work correctly"


 

Robin Lovelock

Senior Member
More progress to report ... I now have two servos, and one moves according to direction that I walk :)
Many Thanks everyone. If you see any changes I should make, or have other ideas, please say.
Robin
www.gpss.co.uk

Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 2 August 2011 (c) Robin Lovelock www.gpss.co.uk/autop.htm 
'Thanks to Hippy, Eclectic, and others on www.picaxeforum.co.uk
'input is serial RS232 GPS data 
'the GPS outputs text strings and includes ",A," after $GPRMC when ready
'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'output is servo controlling rudder to steer boat on a particular heading

'note on behaviour of this test version - which seems to work as intended:
'This is for use with the faster 08M2 chip
'servo 1 is moved according to GPS heading. Servo 2 according to tracking/not tracking.
'after the startup waggle of the two servo, it should monitor the GPS
'and put servo 2 in position 1 if not tracking, and position 2 if tracking
'it now does do this, responding to if the GPS is tracking or not (silver paper over)
'If the GPS is tracking, then servo 1 is moved according to GPS heading.
'It needed the LOW 1 to switch off SERVO before SERIN
'It gives a quick response to the GPS tracking or not tracking.
'polestar GPS red light flashes if not tracking, and solid if tracking.
' earlier tests...
' SERIN 3,N4800_8,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b1 'WORKS OK
' Now the 5 alternative SERIN also work OK. Yet to test more than the "A"/"V" value.
'It seems the PAUSE after SERVOPOS are needed to make it work
 
 #picaxe 08M2  
 setfreq M16

 'waggle servo 1 on startup to show that working - shows GPS heading
 PAUSE 4000 
 SERVO 1,150 'start servo control process - middle
 PAUSE 8000
 SERVOPOS 1,75 'move servo to position 1
 PAUSE 8000
 SERVOPOS 1,225  'move servo to position 2
 PAUSE 8000
 SERVOPOS 1,150  'move servo to middle position
 
 PAUSE 4000 'same for servo 2 - shows tracking/not tracking
 SERVO 2,150 'start servo control process - middle
 PAUSE 8000
 SERVOPOS 2,75 'move servo to position 1
 PAUSE 8000
 SERVOPOS 2,225  'move servo to position 2
 PAUSE 8000
 SERVOPOS 2,150  'move servo to middle position
 
 PAUSE 16000 'wait 4 secs before main loop
 
 
 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 Low 1 'switch off SERVO 1
 Low 2 'switch off SERVO 2
 PAUSE 1000
 'SERIN 3,N4800_16,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b1 'thanks Eclectic :-)

 'alternative SERINs to pickup the A/V into b1 but also GPS heading into w2
 'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
 'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18

 SERIN 3, N4800_16, ( "$GPRMC," ) 'thanks Hippy :-)
 SERIN 3, N4800_16, ( "," ), b1 'A = GPS tracking or V = not yet tracking
 SERIN 3, N4800_16, ( ",W," )
 SERIN 3, N4800_16, ( "," )
 SERIN 3, N4800_16, #w2 'the GPS heading the boat is travelling
 

 if b1 <> "A" then 'if GPS not yet tracking
   goto nottrk
 endif
 
 'GPS is tracking 
 SERVO 2,225 'start servo pulses
 SERVOPOS 2,225 'move servo to position 2
 PAUSE 8000 'at least 2 secs here - it seems this delay is needed
 
  'move servo 1 based on GPS heading in w2, value 0 to 359
 w3 = 150 * w2 / 360 + 75
 SERVO 1,w3 'start servo pulses
 SERVOPOS 1,w3 'move servo 2 to position based on GPS heading
 PAUSE 8000 'at least 2 secs here - it seems this delay is needed

 goto waitgps

 
nottrk: 'GPS is NOT tracking
 SERVO 2,75
 SERVOPOS 2,75 'move servo to position 1
 PAUSE 8000 'at least 2 secs here
 goto waitgps
 
Last edited:

Robin Lovelock

Senior Member
Hi Folks ! I'll soon be pausing here, and this may be my last post of the day.

I'm now looking into extraction of latitude, and maybe longitude, from that $GPRMC message.
It seems a simple PICAXE based autopilot might steer the boat crudely, in a particular direction.
It would be nice if that direction were calculated from it's current GPS lat/lon and a destination lat/lon.
That's obviously what happens in my "proper", iPAQ based, solution - plus a few other things.

Just steering to a final fixed destination would be great - but if we can do that, we can consider through several waypoints. But one step at a time ....

First, how to extract the required latitude from the $GPRMC sentence:
$GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358. 23,280608,,*18
i.e. extract the 5129.8944 = 51 degress 29.8944 minutes North.

If this is going into a 16 bit PICAXE word variable, then we might simplify things by saying we will always be north of the equator and south of 60N.
So we might hold the latitude in 1/1000ths of a degree. i.e. 50000 = 50 degrees North. Precision of 0.001 is very roughly 100 yard ballpark - plenty good enough.
Obviously don't need all those fractional digits. If we see a solution for Latitude, the Longitude will be similar. e.g. can assume always west of Greenwich.

So, looking at those SERIN statements from Hippy:

SERIN 3, N4800_16, ( "$GPRMC," ) 'thanks Hippy :)
SERIN 3, N4800_16, ( "," ), b1 'A = GPS tracking or V = not yet tracking
SERIN 3, N4800_16, ( ",W," )
SERIN 3, N4800_16, ( "," )
SERIN 3, N4800_16, #w2 'the GPS heading the boat is travelling

Can we just insert some more SERINs ?
'$GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358. 23,280608,,*18

MMmmm - needs a bit more thought..... maybe something like this ????
SERIN 3, N4800_16, ( "$GPRMC," ) 'thanks Hippy :)
SERIN 3, N4800_16, ( "," ), b1 'A = GPS tracking or V = not yet tracking
'now we are near the latitude - start by reading 5129.89 into bytes ???
SERIN 3, N4800_16, ( "," ), b2,b3,b4,b5,b6,b6,b7 'first b6 is to skip the decimal point
w6 = b2*10 + b3 'degrees
w6 = w6 * 1000 'scale it to 1/1000ths of a degree
w7 = b4 *10 + b5 'minutes
w7 = w7 * 1000 / 60 'convert minutes to scaled degrees
w6 = w6 + w7 '5129 converted in scaled degrees
' this is already within 1 minute = about a mile. similar approach for decimal bits ?

Maybe one of you more experienced guys can see a much neater approach than this - but it looks doable.

Next stage is to calculate the diferences in latitude and longitude between GPS position and destination - not difficult.

To calculate the bearing - what we need for the steered heading - I think that needs ARCTAN.
Has anyone done that ? If so, maybe we are then almost there ! :)

Many Thanks in advance.
Robin
www.gpss.co.uk
 

Robin Lovelock

Senior Member
Thanks SRNET. That could be a useful approach, using ACOS, SIN and COS (approximations). I see my old code from many years ago has used an approximation based on COS and ARCTAN. We can use plenty of approximation here - to within 1 degree will be plenty good enough, because all the other direction errors are so much greater - and as you get within a mile or even yards of a waypoint, a small direction error becomes insignificant. Listen to the Snoopy Sails! video - within 4 yards and closing :)

Robin
www.gpss.co.uk/autop.htm
Where La1,Lo1 and La2,Lo2 are the two sets of Lat and Long in radians;

Direction=acos((sin(La2)-sin(La1)*cos(Dist))/(sin(Dist)*cos(La1)))
 

srnet

Senior Member
That the calculation I use, in Mikrobasic, which supports trig, floating point and the brackets. The libraries needed take about 16K of flash to run. Its accurate to a degree over short distances, 1Km or less.

I would be interested to see if it can be coded in PICAXE, either over short distances or hundreds of Km.
 

Robin Lovelock

Senior Member
Thanks SRNET. My next question (for anyone who can help) is hardware. It's clear that a simple PICAXE solution is possible: it's just a matter of how far we go with the software: steering on a fixed heading, based on the GPS heading, should be simple - after tweaking based on real water trials. Also, we could at least make use of the degrees of latitude and longitude, to program change of heading for a particular (approximate) route. That's good enough for me for now - although those outstanding software-related questions will also be of interest.

Now the hardware: what is the simplest and most practical modificaation of an AXE024 servo driver, to wire in the serial output of my GPS ? This is the http://www.rev-ed.co.uk/docs/axe024.pdf and I've looked at the document on serial interfacing. I've obviously also been looking at what I've used on a few other AXE024 and Project boards, to see how I interfaced the input from iPAQ serial output, or - as now - output from a GPS mouse. I think any GPS that I use will swing between 0v and 5v levels, rather than true RS232.

I'm obviously interested in the (one or two?) components needed, but also the neatest way of wiring on the AXE024 board. e.g. there are some pins made available for a colour sensor. My GPS mice will connect to the same common +5v and 0v that are powering the PICAXE. Looking at the interfaacing documentation (http://www.rev-ed.co.uk/docs/picaxe_manual3.pdf), it seems my GPS signal output would go to a 22K R through to Pin 0, and a 10K R down to 0v. Looking on the project board that works, it seems I'm using a 22K R and diode - but that was assembled some time ago.

I'm thinking of having several AXE024 Servo Driver boards, wired up to GPS and servos, and being used for a number of tests started soon, including 24/7 reliability and power testing, and some trials by one or more boats on the water. We can start this with little more than the test software we already have. I guess for the autopilot software, I will be using a PC driving simulated GPS data into the PICAXE, for the route we expect the boat to take, away from the UK launch point, then south-south-west to catch the trade winds, then west to the Caribean, then "homing in" on our target destination - yet to be decided.

Off topic chat is always of interest, but I hope some of you can save me some valuable time, as you have many times before.

Robin
www.gpss.co.uk
 

Robin Lovelock

Senior Member
Hi Folks. Good progress is being made, and I've just updated the "latest news" on www.gpss.co.uk/autop.htm with a couple of small pictures showing testing of the simple, PICAXE-based autopilot. One is being 24/7 power tested, and the other is driven by my software, simulating the GPS. This simulator is the main test harness for the AUTOP1.BAS software - the early code for which is in an earlier posting of mine. Ideas from you of better ways of handling the latitude/longitude now become very timely ;-)

I used the 22k and 10k resitor solution documented for the serial input, without diodes, and I've not seen any problems. The two servo driver boards are in the above pictures.

During the recent power testing, I was very pleasantly surprised to see that the GPS, PICAXE, and servo, still continued to function, even when the battery had dropped to 3.75v ! This is well below the nominal 4.8v for a 4-cell NiMHd pack, and has good implications: we need not have the added complexity (and less reliability) of our boat 5 power source - 8 cells (10v) going into a UBEC 5v regulator. This was because we wished to get as much power as possible from the batteries, under poor solar lighting. Our power tests were based on a deliberately inadequate system - only 2300mA battery (we plan to use 10,000mAH D-size cells) and only one solar panel - charging just 200mA into 5v in bright sunshine. Yesterday was lots of rain and little sunshine ! Has anyone tested a PICAXE to see how low a voltage it will run reliably ?

The GPS simulator uses my GPS Software (on www.gpss.co.uk) and it drives the PICAXE serial line with simulated $GPRMC GPS data. I can add a mix of maps, including the whole World (seen in the picture) and more detail wherever needed - including near the finish line, final destination, and test areas like Bray Lake. Script files can be made by clicking on the maps. These script files then drive the simulation.

I'm now re-visiting AUTOP1.BAS to start plugging in the guidance logic aand test it with the simulator. I also expect to begin testing of a ruggedised boat 4 very soon.

Many Thanks in advance for any feedback.
Robin
www.gpss.co.uk
 

srnet

Senior Member
Yesterday was lots of rain and little sunshine ! Has anyone tested a PICAXE to see how low a voltage it will run reliably ?
Depend on the PICAXE, the 28X2 I know for sure runs at 2.5v, it will run at a lower voltage, but my experience is that at lower voltages than that you can have problems with the serial interface, if your using the simple resistor interface.
 

Robin Lovelock

Senior Member
Thanks SRNET. Thats nice news about the PICAXE working at a low voltage. Now for the main stuff: better progress than I expected for my latest version of AUTOP1.BAS, the code for which is below - along with description of behaviour in the comments. I'm hoping some of you will see some silly mistakes, or simplifications I could make.

e.g. you will see one comment where I program around an aparent restriction in the language.
It does not like something like "IF w3 < -180 THEN" - I guess because only positive values are allowed ?
Maybe that means some of my arithmetic will be wrong, and needs changing.
It looks as if it is steering the boat OK, but maybe not as intended.
The thing that is certainly wrong relates to extraction and calculation of a scaled latitude.

There are obviously lots of changes from the thoughts about these inserted SERINs in the earlier postings.
e.g. use of higher bytes, like b21,b22, etc to avoid clashing with the word variables, w1,w2, etc.
Also, my use of the # in the SERIN - hopefully to get the integer value 5 from ascii "5" in the byte.

But of course, I may be doing it all wrong.
Many thanks in advance for any feedback.

Robin
www.gpss.co.uk/autop.htm

Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 5 August 2011 (c) Robin Lovelock www.gpss.co.uk/autop.htm 
'Thanks to Hippy, Eclectic, and others on www.picaxeforum.co.uk
'input is serial RS232 GPS data 
'the GPS outputs text strings and includes ",A," after $GPRMC when ready
'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'output is servo controlling rudder to steer boat on a particular heading

'note on behaviour of this test version - which seems to ALMOST work as intended:
'This is for use with the faster 08M2 chip
'servo 1 controls rudder, based on GPS heading to steer the boat. 
'Servo 2 is to aid testing. e.g. based on other data from GPS such as latitude.
'Servo 2 = CENTRE (not tracking), LEFT (Latitude>51N) RIGHT (Latitude<51N)
'after the startup waggle of the two servo, it should monitor the GPS
'and control the two servos. Testing can be with real GPS or the GPS Simulator.
'It now does do this, responding to if the GPS is tracking or not (silver paper over)
'If the GPS is tracking, then servo 1 is moved to steer boat according to GPS heading.
'It needed the LOW 1 to switch off SERVO before SERIN
'It gives a quick response to the GPS tracking or not tracking.
'polestar GPS red light flashes if not tracking, and solid if tracking.
'It seems the PAUSE after SERVOPOS are needed to make it work
'BUGS/ERRORS REMAINING: Latitude does not seem to work - servo 2 goes left and right.
'It should be left when latitude above 51N (value 51000) else right (when south)
'This is despite fact that the SERIN for GPS heading is after SERINs for latitude.
'Looks as if an error in arithmetic related to latitude ???
 
 #picaxe 08M2  
 setfreq M16
 
 Symbol CENTRE = 150 'Servo middle position
 Symbol THROW = 50
 symbol LEFT=CENTRE - THROW 'Servo left
 symbol RIGHT = CENTRE + THROW 'Servo right
 symbol FOR1SEC = 4000 'pause value at 16MHz for 1 sec
 symbol FOR2SEC = 8000 'pause value at 16MHz for 2 sec
 symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec
 

 'waggle servo 1 on startup to show that working - will control rudder
 PAUSE FOR1SEC 
 SERVO 1,CENTRE 'start servo control process - middle
 PAUSE FOR2SEC
 SERVOPOS 1,LEFT 'move servo to position 1
 PAUSE FOR2SEC
 SERVOPOS 1,RIGHT  'move servo to position 2
 PAUSE FOR2SEC
 SERVOPOS 1,CENTRE  'move servo to middle position
 
 PAUSE FOR1SEC  'same for servo 2 - shows other GPS data e.g.south of 51N
 SERVO 2,CENTRE 'start servo control process - middle
 PAUSE FOR2SEC
 SERVOPOS 2,LEFT 'move servo to position 1
 PAUSE FOR2SEC
 SERVOPOS 2,RIGHT  'move servo to position 2
 PAUSE FOR2SEC
 SERVOPOS 2,CENTRE  'move servo to middle position
 
 PAUSE FOR4SEC 'wait 4 secs before main loop
 
 w1 = 225 'target heading is south west (we will update this in a later version)
 
 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 Low 1 'switch off SERVO 1
 Low 2 'switch off SERVO 2
 PAUSE 1000

 'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
 'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18

 SERIN 3, N4800_16, ( "$GPRMC," ) 'thanks Hippy :-)
 SERIN 3, N4800_16, ( "," ), b21 'A = GPS tracking or V = not yet tracking
  
 'now we are near the latitude - start by reading 5129.89 into bytes ???
 SERIN 3, N4800_16, ( "," ), #b22,#b23,#b24,#b25,b26,#b26,#b27 'first b16 is to skip the decimal point
 w6 = b22 * 10 + b23 'degrees e.g 50
 w6 = w6 * 1000 'scale it to 1/1000ths of a degree
 w7 = b24 * 10 + b25 'minutes e.g. 30
 w7 = w7 * 1000 / 60 'convert minutes to scaled degrees
 w6 = w6 + w7 'Latitude 5130 converted in scaled degrees 51500
 ' this is already within 1 minute = about a mile. similar later for decimal bits ?
 
 SERIN 3, N4800_16, ( ",W," )
 SERIN 3, N4800_16, ( "," )
 SERIN 3, N4800_16, #w2 'the GPS heading the boat is travelling

 if b21 <> "A" then 'if GPS not yet tracking
   goto nottrk
 endif
 
 'GPS is tracking 
 PAUSE FOR2SEC 'at least 2 secs here - it seems this delay is needed
 
 w3 = w2 - w1 'error is GPSHdg - TgtHdg
 w4 = -180 'because IF w3 < -180 THEN not allowed. Why not ???
 IF w3 < w4 THEN 
   w3 = w3 + 360
 endif
 if w3 > 180 then 
   w3 = w3 - 360 'now -180 < w3 <+180
 endif
 w3 = w3 * THROW / 180 + CENTRE 'now rudder servo position
 
  'move servo 1 based on GPS heading in w2, value 0 to 359
 'w3 = 150 * w2 / 360 + 75
 SERVO 1,w3 'start servo 1 pulses
 SERVOPOS 1,w3 'move servo 1 to steer boat based on GPS heading
 if w6 > 51000 then
   SERVO 2,LEFT 'start servo 2 pulses
   SERVOPOS 2,LEFT 'move servo to show latitude > 50
 else
   SERVO 2,RIGHT 'start servo 2 pulses
   SERVOPOS 2,RIGHT 'move servo to show latitude < 50
 endif
 PAUSE FOR2SEC 'at least 2 secs here - it seems this delay is needed
 goto waitgps
 
nottrk: 'GPS is NOT tracking
 SERVO 2,CENTRE
 SERVOPOS 2,CENTRE 'move servo to position 1
 PAUSE FOR2SEC 'at least 2 secs here
 goto waitgps

Depend on the PICAXE, the 28X2 I know for sure runs at 2.5v, it will run at a lower voltage, but my experience is that at lower voltages than that you can have problems with the serial interface, if your using the simple resistor interface.
 

papaof2

Senior Member
"IF W3 < -180 THEN" doesn't work because PICAXE positive integer math "rolls over" to 65535 when you attempt to go below 0 with a 16 bit value (0 - 1 = 65535; also, in byte arithmetic 0 - 1 = 255).

You can compute the actual value (65535 - whatever) and define it as a constant. The line might be something like this:
IF W3 {relation} TestValue THEN

John
 

Technical

Technical Support
Staff member
As John points out, your

w4 = -180

will make w4 = 0 - 180 = 65536 - 180 = 65356, which is not what you intended!
 

Robin Lovelock

Senior Member
Thanks Guys - as I thought when I put up that last posting. I must admit that even the code below, that does the steering logic, seems difficult to convert so it does not rely on signed integers. I spent a good bit of time on a different version, but that's messy and doesn't work yet.

Code:
 w3 = w2 - w1 'error is GPSHdg - TgtHdg
 w4 = -180 'because IF w3 < -180 THEN not allowed. Why not ???
 IF w3 < w4 THEN 
   w3 = w3 + 360
 endif
 if w3 > 180 then 
   w3 = w3 - 360 'now -180 < w3 <+180
 endif
 w3 = w3 * THROW / 180 + CENTRE 'now rudder servo position
 

Robin Lovelock

Senior Member
Hi Folks. I think this version of the AUTOP1.BAS code programs around not having signed integers, and it looks as if the steering logic is OK. So we are back to what is wrong with my SERINs to extract latitude, based on Hippy's code - with my incorrect changes no doubt :)
Robin
www.gpss.co.uk/autop.htm

Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 6 August 2011 (c) Robin Lovelock www.gpss.co.uk/autop.htm 
'Thanks to Hippy, Eclectic, and others on www.picaxeforum.co.uk
'input is serial RS232 GPS data 
'the GPS outputs text strings and includes ",A," after $GPRMC when ready
'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'output is servo controlling rudder to steer boat on a particular heading

'note on behaviour of this test version - which seems to ALMOST work as intended:
'This is for use with the faster 08M2 chip
'servo 1 controls rudder, based on GPS heading to steer the boat. 
'Servo 2 is to aid testing. e.g. based on other data from GPS such as latitude.
'Servo 2 = CENTRE (not tracking), LEFT (Latitude>51N) RIGHT (Latitude<51N)
'after the startup waggle of the two servo, it should monitor the GPS
'and control the two servos. Testing can be with real GPS or the GPS Simulator.
'It now does do this, responding to if the GPS is tracking or not (silver paper over)
'If the GPS is tracking, then servo 1 is moved to steer boat according to GPS heading.
'It needed the LOW 1 to switch off SERVO before SERIN
'It gives a quick response to the GPS tracking or not tracking.
'polestar GPS red light flashes if not tracking, and solid if tracking.
'It seems the PAUSE after SERVOPOS are needed to make it work.
'BUGS/ERRORS REMAINING: Latitude does not seem to work - servo 2 goes left and right.
'It should be left when latitude above 51N (value 51000) else right (when south)
'This is despite fact that the SERIN for GPS heading is after SERINs for latitude.
'Looks as if an error in arithmetic related to latitude ???
 
 #picaxe 08M2  
 setfreq M16
 
 Symbol CENTRE = 150 'Servo middle position
 Symbol THROW = 50
 symbol LEFT=CENTRE - THROW 'Servo left
 symbol RIGHT = CENTRE + THROW 'Servo right
 symbol FOR1SEC = 4000 'pause value at 16MHz for 1 sec
 symbol FOR2SEC = 8000 'pause value at 16MHz for 2 sec
 symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec
 

 'waggle servo 1 on startup to show that working - will control rudder
 PAUSE FOR1SEC 
 SERVO 1,CENTRE 'start servo control process - middle
 PAUSE FOR2SEC
 SERVOPOS 1,LEFT 'move servo to position 1
 PAUSE FOR2SEC
 SERVOPOS 1,RIGHT  'move servo to position 2
 PAUSE FOR2SEC
 SERVOPOS 1,CENTRE  'move servo to middle position
 
 PAUSE FOR1SEC  'same for servo 2 - shows other GPS data e.g.south of 51N
 SERVO 2,CENTRE 'start servo control process - middle
 PAUSE FOR2SEC
 SERVOPOS 2,LEFT 'move servo to position 1
 PAUSE FOR2SEC
 SERVOPOS 2,RIGHT  'move servo to position 2
 PAUSE FOR2SEC
 SERVOPOS 2,CENTRE  'move servo to middle position
 
 PAUSE FOR4SEC 'wait 4 secs before main loop
 
 w1 = 225 'target heading is south west (we will update this in a later version)
 
 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 Low 1 'switch off SERVO 1
 Low 2 'switch off SERVO 2
 PAUSE 1000

 'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
 'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18

 SERIN 3, N4800_16, ( "$GPRMC," ) 'thanks Hippy :-)
 SERIN 3, N4800_16, ( "," ), b21 'A = GPS tracking or V = not yet tracking
  
 'now we are near the latitude - start by reading 5129.89 into bytes ???
 SERIN 3, N4800_16, ( "," ), #b22,#b23,#b24,#b25,b26,#b26,#b27 'first b16 is to skip the decimal point
 w6 = b22 * 10 + b23 'degrees e.g 50
 w6 = w6 * 1000 'scale it to 1/1000ths of a degree
 w7 = b24 * 10 + b25 'minutes e.g. 30
 w7 = w7 * 1000 / 60 'convert minutes to scaled degrees
 w6 = w6 + w7 'Latitude 5130 converted in scaled degrees 51500
 ' this is already within 1 minute = about a mile. similar later for decimal bits ?
 
 SERIN 3, N4800_16, ( ",W," )
 SERIN 3, N4800_16, ( "," )
 SERIN 3, N4800_16, #w2 'the GPS heading the boat is travelling

 if b21 <> "A" then 'if GPS not yet tracking
   goto nottrk
 endif
 
 'GPS is tracking 
 PAUSE FOR2SEC 'at least 2 secs here - it seems this delay is needed
 
 'Integers are unsigned, so cannot have any negative numbers.
 
 if w2 > w1 then 'GPSHdg > TgtHdg
   w3 = w2 - w1
   if w3 < 180 then 'turn left
     goto turnleft
   else 'turn right
     w3 = 360 - w3
     goto turnright
   endif
 else 
   w3 = w1 - w2
   if w3 < 180 then 'turn right
     goto turnright
   else 'turn left
     w3 = 360 - w3
     goto turnleft
   endif
 endif
 
turnleft:
 w3 = w3 * THROW / 180
 w3 = CENTRE - w3
 goto turn
 
turnright:
 w3 = w3 * THROW / 180
 w3 = CENTRE + w3
 
turn: 
 SERVO 1,w3 'start servo 1 pulses
 SERVOPOS 1,w3 'move servo 1 to steer boat based on GPS heading
 
 if w6 > 51000 then
   SERVO 2,LEFT 'start servo 2 pulses
   SERVOPOS 2,LEFT 'move servo to show latitude > 50
 else
   SERVO 2,RIGHT 'start servo 2 pulses
   SERVOPOS 2,RIGHT 'move servo to show latitude < 50
 endif
 PAUSE FOR2SEC 'at least 2 secs here - it seems this delay is needed
 goto waitgps
 
nottrk: 'GPS is NOT tracking
 SERVO 2,CENTRE
 SERVOPOS 2,CENTRE 'move servo to position 1
 PAUSE FOR2SEC 'at least 2 secs here
 goto waitgps
 

Robin Lovelock

Senior Member
Thanks Eclectic - is this suggesting that I become a radio ham ?
If so, I don't think I have sufficient hours to invest, or time until launch :)
But, to be serious, that's why I am seeking the help of existing radio hams.
If something like WSPR is to be used, it needs a ham to pursue it.

@Robin
As a slight aside, see Stan's second paragraph
here:
http://www.picaxeforum.co.uk/showthread.php?19053-Radio-power

e
I now have an AUTOP1.BAS that is closer to what is needed - see the code below.

I'll soon be tweaking the steering logic to match the turning characteristics of whatever boat we use.
i.e. by comparison with behaviour under radio control. e.g. hard right for two seconds.
We obviously need it to turn the boat onto the correct course, but without over-correction and oscilation.

The latitude extraction seems to work, now that I simply read the bytes, then subtract 48 to convert from ASCII.
Earlier I had tried to use the SERIN with # as Hippy did, to read a value.
I could not find this mechanism in the documentation. Where would I find it ?

I'm sure my existing logic can be tidied up, maybe using CASE statements instead of IF THEN,
but I guess my priority now is to continue work on latitude and longitude,
to see how precise I can make the guidance. Precise guidance will make it easier to test on Bray Lake.

Any ideas, on or off topic, will be greatfully received.
Robin
www.gpss.co.uk/autop.htm
Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 1230 6th August 2011 (c) Robin Lovelock www.gpss.co.uk/autop.htm 
'Thanks to Hippy, Eclectic, and others on www.picaxeforum.co.uk
'input is serial RS232 GPS data 
'the GPS outputs text strings and includes ",A," after $GPRMC when ready
'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'output is servo controlling rudder to steer boat on a particular heading

'note on behaviour of this test version - which seems to work as intended:
'This is for use with the faster 08M2 chip
'servo 1 controls rudder, based on GPS heading to steer the boat. 
'Servo 2 is to aid testing. e.g. based on other data from GPS such as latitude.
'Servo 2 = CENTRE (not tracking), LEFT (Latitude>51N) RIGHT (Latitude<51N)
'after the startup waggle of the two servo, it should monitor the GPS
'and control the two servos. Testing can be with real GPS or the GPS Simulator.
'It now does do this, responding to if the GPS is tracking or not (silver paper over)
'If the GPS is tracking, then servo 1 is moved to steer boat according to GPS heading.
'It needed the LOW 1 to switch off SERVO before SERIN
'It gives a quick response to the GPS tracking or not tracking.
'polestar GPS red light flashes if not tracking, and solid if tracking.
'Latitude seems to work, now SERIN numeric bytes read as ASCII, then -48 to a value.
 
 #picaxe 08M2  
 setfreq M16
 
 Symbol CENTRE = 150 'Servo middle position
 Symbol THROW = 50
 symbol LEFT=CENTRE - THROW 'Servo left
 symbol RIGHT = CENTRE + THROW 'Servo right
 symbol FOR1SEC = 4000 'pause value at 16MHz for 1 sec
 symbol FOR2SEC = 8000 'pause value at 16MHz for 2 sec
 symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec
 

 'waggle servo 1 on startup to show that working - will control rudder
 PAUSE FOR1SEC 
 SERVO 1,CENTRE 'start servo control process - middle
 PAUSE FOR2SEC
 SERVOPOS 1,LEFT 'move servo to position 1
 PAUSE FOR2SEC
 SERVOPOS 1,RIGHT  'move servo to position 2
 PAUSE FOR2SEC
 SERVOPOS 1,CENTRE  'move servo to middle position
 
 PAUSE FOR1SEC  'same for servo 2 - shows other GPS data e.g.south of 51N
 SERVO 2,CENTRE 'start servo control process - middle
 PAUSE FOR2SEC
 SERVOPOS 2,LEFT 'move servo to position 1
 PAUSE FOR2SEC
 SERVOPOS 2,RIGHT  'move servo to position 2
 PAUSE FOR2SEC
 SERVOPOS 2,CENTRE  'move servo to middle position
 
 PAUSE FOR4SEC 'wait 4 secs before main loop
 
 w1 = 225 'target heading is south west (we will update this in a later version)
 
 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 Low 1 'switch off SERVO 1
 Low 2 'switch off SERVO 2
 PAUSE 1000

 'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
 'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18

 SERIN 3, N4800_16, ( "$GPRMC," ) 'thanks Hippy :-)
 SERIN 3, N4800_16, ( "," ), b21 'A = GPS tracking or V = not yet tracking
  
 'now we are near the latitude - start by reading 5129.89 into bytes ???
 SERIN 3, N4800_16, ( "," ), b22,b23,b24,b25,b26,b26,b27 'first b16 is to skip the decimal point
 b22 = b22 - 48: b23 = b23 - 48: b25 = b25 - 48: b26 = b26 - 48: b27 = b27 - 48 'from ASCII 
 w6 = b22 * 10 + b23 'degrees e.g 50
 w6 = w6 * 1000 'scale it to 1/1000ths of a degree
 w7 = b24 * 10 + b25 'minutes e.g. 30
 w7 = w7 * 1000 / 60 'convert minutes to scaled degrees
 w6 = w6 + w7 'Latitude 5130 converted in scaled degrees 51500
 ' this is already within 1 minute = about a mile. similar later for decimal bits ?
 
 SERIN 3, N4800_16, ( ",W," )
 SERIN 3, N4800_16, ( "," )
 SERIN 3, N4800_16, #w2 'the GPS heading the boat is travelling

 if b21 <> "A" then 'if GPS not yet tracking
   goto nottrk
 endif
 
 'GPS is tracking 
 PAUSE FOR1SEC 'at least 1 secs here - it seems this delay is needed
 
 'Integers are unsigned, so cannot have any negative numbers.
 
 if w2 > w1 then 'GPSHdg > TgtHdg
   w3 = w2 - w1
   if w3 < 180 then 'turn left
     goto turnleft
   else 'turn right
     w3 = 360 - w3
     goto turnright
   endif
 else 
   w3 = w1 - w2
   if w3 < 180 then 'turn right
     goto turnright
   else 'turn left
     w3 = 360 - w3
     goto turnleft
   endif
 endif
 
turnleft:
 if w3 > 90 then 'more than 90
   w3 = 90 'turn hard left
 endif
 w3 = w3 * THROW / 90 'proportion to error
 w3 = CENTRE + w3
 goto turn
 
turnright:
 if w3 > 90 then 'more than 90
   w3 = 90 'turn hard right
 endif
 w3 = w3 * THROW / 90
 w3 = CENTRE - w3
 
turn: 
 SERVO 1,w3 'start servo 1 pulses
 SERVOPOS 1,w3 'move servo 1 to steer boat based on GPS heading
 PAUSE FOR2SEC 'hold rudder here for long enough to turn
 SERVOPOS 1,CENTRE 'return rudder to centre

 
 if w6 > 51000 then
   SERVO 2,LEFT 'start servo 2 pulses
   SERVOPOS 2,LEFT 'move servo to show latitude > 50
 else
   SERVO 2,RIGHT 'start servo 2 pulses
   SERVOPOS 2,RIGHT 'move servo to show latitude < 50
 endif
 PAUSE FOR1SEC 'at least 1 secs here - it seems this delay is needed
 goto waitgps
 
nottrk: 'GPS is NOT tracking
 SERVO 2,CENTRE
 SERVOPOS 2,CENTRE 'move servo to position 1
 PAUSE FOR2SEC 'at least 2 secs here
 goto waitgps
 

manuka

Senior Member
FWIW- a UK launch may catch the North Atlantic Subtropical Gyre & lead to a potential garbage patch fate. Hence perhaps ponder that the North Atlantic's prevailing winds (and beneficial Gulf Stream flow) may greatly favour a North American-UK (West-East) passage-you may want to consider launching from the USA.
 

Attachments

Last edited:

Robin Lovelock

Senior Member
My latest code for AUTOP1.BAS is below, for those friends working with me (not active on this forum). Good progress is being made, with trace output to Windows Terminal and input from a real GPS or my GPS simulator. I'm now getting close to trying to exploit the accurate lat/lon read from the GPS, to update the target heading. Meanwhile 24/7 power tests continue based on one PICAXE, GPS, battery and solar cells. We may be doing our first rudder guidance logic tests on water late this week.

Thanks Manuka: but I'd rather spend the money on other things than air tickets and hotels :) Follow the links from www.gpss.co.uk/autop.htm to the Microtransat site and the rules: from Longitude 7.5 degrees west to 60 degrees west. The Canadian and American teams might prefer to try it your way, of course. Today I updated my page www.gpss.co.uk/tam.htm - that even more demanding flight by a model aircraft years ago - from Canada to Ireland. As I think I've said before, if we do go for it, then it would be from coast to coast - actually launching off a beach. I understand the French may try this year - from Brest.


FWIW- a UK launch may catch the North Atlantic Subtropical Gyre & lead to a potential garbage patch fate. Hence perhaps ponder that the North Atlantic's prevailing winds (and beneficial Gulf Stream flow) may greatly favour a North American-UK (West-East) passage-you may want to consider launching from the USA.
Robin's code is below. Ref the PICAXE autopilot on www.gpss.co.uk/autop.htm
Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 9th August 2011 (c) Robin Lovelock www.gpss.co.uk/autop.htm 
'Thanks to Hippy, Eclectic, and others on www.picaxeforum.co.uk
'input is serial RS232 GPS data 
'the GPS outputs text strings and includes ",A," after $GPRMC when ready
'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'output is servo controlling rudder to steer boat on a particular heading

'note on behaviour of this test version - which seems to work as intended:
'This is for use with the faster 08M2 chip
'servo 1 controls rudder, based on GPS heading to steer the boat. 
'Servo 2 is to aid testing. e.g. based on other data from GPS such as latitude.
'Servo 2 = CENTRE (not tracking), LEFT (Latitude>51N) RIGHT (Latitude<51N)
'after the startup waggle of the two servo, it should monitor the GPS
'and control the two servos. Testing can be with real GPS or the GPS Simulator.
'It now does do this, responding to if the GPS is tracking or not (silver paper over)
'If the GPS is tracking, then servo 1 is moved to steer boat according to GPS heading.
'It needed the LOW 1 to switch off SERVO before SERIN
'It gives a quick response to the GPS tracking or not tracking.
'polestar GPS red light flashes if not tracking, and solid if tracking.
'Latitude seems to work, now SERIN numeric bytes read as ASCII, then -48 to a value
'Lat/Lon not yet used to update the heading, but held accurately to 1/1000ths of a minute
'b0 = latitude degrees North only i.e. 0 to 89N
'b1 = longitude degrees West only i.e, 0 to 120W ???
'w1 = target heading 0 to 359
'w2 = GPS heading
'w3 = servo position
'w4 = accurate minutes of latitude 0 to 59999 lsd = 0.001 minutes.
'w5 = accurate minutes of longitude 0 to 59999 lsd = 0.001 minutes.
 
 #picaxe 08M2  
 setfreq M16
 
 Symbol CENTRE = 150 'Servo middle position
 Symbol THROW = 50
 symbol LEFT=CENTRE - THROW 'Servo left
 symbol RIGHT = CENTRE + THROW 'Servo right
 symbol FOR1SEC = 4000 'pause value at 16MHz for 1 sec
 symbol FOR2SEC = 8000 'pause value at 16MHz for 2 sec
 symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec

 'sertxd(“The value of b1 is ”,#b1,13,10) 
 sertxd ( "AUTOP1 - testing two servos ...",10,13 ) 'test ouput back to PC

 'waggle servo 1 on startup to show that working - will control rudder
 PAUSE FOR1SEC 
 SERVO 1,CENTRE 'start servo control process - middle
 PAUSE FOR2SEC
 SERVOPOS 1,LEFT 'move servo to position 1
 PAUSE FOR1SEC
 SERVOPOS 1,RIGHT  'move servo to position 2
 PAUSE FOR1SEC
 SERVOPOS 1,CENTRE  'move servo to middle position
 
 PAUSE FOR1SEC  'same for servo 2 - shows other GPS data e.g.south of 51N
 SERVO 2,CENTRE 'start servo control process - middle
 PAUSE FOR1SEC
 SERVOPOS 2,LEFT 'move servo to position 1
 PAUSE FOR1SEC
 SERVOPOS 2,RIGHT  'move servo to position 2
 PAUSE FOR1SEC
 SERVOPOS 2,CENTRE  'move servo to middle position
 
 PAUSE FOR2SEC 'wait 2 secs before main loop
  
 sertxd ( "AUTOP1 - waiting for GPS data ...",10,13 ) 
 
 w1 = 225 'target heading is south west (we will update this in a later version)
 
 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 Low 1 'switch off SERVO 1
 Low 2 'switch off SERVO 2
 PAUSE 1000

 'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
 'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18

 SERIN 3, N4800_16, ( "$GPRMC," ) 'thanks Hippy :-)
 SERIN 3, N4800_16, ( "," ), b21 'A = GPS tracking or V = not yet tracking
  
 'now we are near the latitude - start by reading 5129.89 into bytes ???
 SERIN 3, N4800_16, ( "," ), b22,b23,b24,b25,b26,b27,b27 'first b16 is to skip the decimal point
 b22 = b22 - 48: b23 = b23 - 48: b24 = b24 - 48: b25 = b25 - 48: b26 = b26 - 48: b27 = b27 - 48 'from ASCII 
 b0 = b22 * 10 + b23 'degrees of latitude e.g 50
 w4 = b24 * 10 + b25 'minutes e.g. 30
 w4 = w4 * 1000 'convert minutes to 1/1000 ths minutes
 w6 = b26 * 100 'add 0.1 mins
 w4 = w4 + w6 'add 0.1 mins
 w6 = b27 * 10
 w4 = w4 + w6 'add 0.01 mins
 SERIN 3, N4800_16,  b22,b23 
 b22 = b22 - 48: b23 = b23 - 48
 w4 = w4 + b22 'add 0.001 mins - now minutes of latitude in 1/1000yhs mins
 'read longitude ,N,00041.0771,W,
 SERIN 3, N4800_16, ( ",N," ), b22,b23,b24,b25,b26,b27,b27 'first b16 is to skip the decimal point
 b22 = b22 - 48: b23 = b23 - 48: b24 = b24 - 48: b25 = b25 - 48: b26 = b26 - 48: b27 = b27 - 48 'from ASCII 
 b1 = b22 * 100 
 w6 = b23 * 10 + b24 
 b1 = w6 + b1 'longitude degrees e.g 001
 w5 = b25 * 10 + b26 'minutes e.g. 30
 w5 = w5 * 1000 'convert minutes to 1/1000 ths minutes
 w6 = b27 * 100 'add 0.1 mins
 w5 = w5 + w6 'add 0.1 mins
 SERIN 3, N4800_16,  b22,b23 
 b22 = b22 - 48: b23 = b23 - 48
 w6 = b22 * 10
 w5 = w5 + w6 'add 0.01 mins
 w5 = w5 + b23 'add 0.001 mins - is now scaled longitude 1/1000 minutes
 
 SERIN 3, N4800_16, ( ",W," )
 SERIN 3, N4800_16, ( "," )
 SERIN 3, N4800_16, #w2 'the GPS heading the boat is travelling
 
 sertxd ( 10,13,"AUTOP1 ",b21,", Lat=",#b0,"+",#w4,", Lon=",#b1,"+",#w5, ", Hdg=",#w2 ) 'trace output back to PC


 if b21 <> "A" then 'if GPS not yet tracking
   goto nottrk
 endif
 
 'GPS is tracking 
 PAUSE FOR1SEC 'at least 1 secs here - it seems this delay is needed
 
 'Integers are unsigned, so cannot have any negative numbers.
 
 if w2 > w1 then 'GPSHdg > TgtHdg
   w3 = w2 - w1
   if w3 < 180 then 'turn left
     goto turnleft
   else 'turn right
     w3 = 360 - w3
     goto turnright
   endif
 else 
   w3 = w1 - w2
   if w3 < 180 then 'turn right
     goto turnright
   else 'turn left
     w3 = 360 - w3
     goto turnleft
   endif
 endif
 
turnleft:
 if w3 > 90 then 'more than 90
   w3 = 90 'turn hard left
 endif
 sertxd ( " LEFT ",#w3 ) 'trace output back to PC
 w3 = w3 * THROW / 90 'proportion to error
 w3 = CENTRE + w3
  goto turn
 
turnright:
 if w3 > 90 then 'more than 90
   w3 = 90 'turn hard right
 endif
 sertxd ( " RIGHT ",#w3 ) 'trace output back to PC
 w3 = w3 * THROW / 90
 w3 = CENTRE - w3
 
turn: 
 SERVO 1,w3 'start servo 1 pulses
 SERVOPOS 1,w3 'move servo 1 to steer boat based on GPS heading
 PAUSE FOR2SEC 'hold rudder here for long enough to turn
 SERVOPOS 1,CENTRE 'return rudder to centre

 
 if w6 > 51000 then
   SERVO 2,LEFT 'start servo 2 pulses
   SERVOPOS 2,LEFT 'move servo to show latitude > 50
 else
   SERVO 2,RIGHT 'start servo 2 pulses
   SERVOPOS 2,RIGHT 'move servo to show latitude < 50
 endif
 PAUSE FOR1SEC 'at least 1 secs here - it seems this delay is needed
 goto waitgps
 
nottrk: 'GPS is NOT tracking
 SERVO 2,CENTRE
 SERVOPOS 2,CENTRE 'move servo to position 1
 PAUSE FOR2SEC 'at least 2 secs here
 goto waitgps
 
Last edited:

Robin Lovelock

Senior Member
Hi Folks. Progress has gone well on the simple PICAXE based autopilot and I have a question:

Is there any way of my program "remembering" at least one byte or word variable, if power is interrupted ?

The documentation is clear that all the variables in a 08M2 (servo driver) are lost if power is lost. The program is obviously not lost. I'm looking at changes to the program needed to cover temporary loss of power (e.g. too many cloudy days for the solar panels). If the program could remember things like the current destination waypoint, that might simplfy things a great deal.

Robin
www.gpss.co.uk/autop.htm
 

manuka

Senior Member
Are you up with PICAXE EEPROM ? Although simple enough (refer 2nd Manual P.261),you may however have a lot of variables to continually READ & WRITE.
 

srnet

Senior Member
Bear in mind with EEPROM there is a limit to the number of writes, they do fail eventually.

A 28X2 (18F25K22) has a minimum quoted endurance of 100K writes, which sounds a lot, but write to the EEPROM once a minute and you exceed the minimum spec in about 69days.
 

lbenson

Senior Member
Picaxe variables (b0, w0, etc.) are lost when power is lost, but eeprom values are not. For the 08M2, the eeprom documentation (Manual 2) says, "PICAXE- 08M2 / 18M2 --Program 1792 up to 2048 is EEPROM 255 to 0 So on 08M2/18M2 all bytes are available if program is shorter than 1792 bytes long."

If you are worried about exceeding 100,000 writes (deemed to be a conservative value), then write your data to a block (1 to 8 or 16 or any number of bytes), and after "x" number of writes, move up to another block. For instance, if you wanted to write 16 bytes, you could do that until a word counter (e.g., w13) overflowed to 0 (at a safe 65,000-odd times), then move to another 16-byte block. You have 16 16-byte blocks in 256 bytes of eeprom, so could write over a million times.
 

srnet

Senior Member
Picaxe variables (b0, w0, etc.) are lost when power is lost, but eeprom values are not. For the 08M2, the eeprom documentation (Manual 2) says, "PICAXE- 08M2 / 18M2 --Program 1792 up to 2048 is EEPROM 255 to 0 So on 08M2/18M2 all bytes are available if program is shorter than 1792 bytes long."

If you are worried about exceeding 100,000 writes (deemed to be a conservative value), then write your data to a block (1 to 8 or 16 or any number of bytes), and after "x" number of writes, move up to another block. For instance, if you wanted to write 16 bytes, you could do that until a word counter (e.g., w13) overflowed to 0 (at a safe 65,000-odd times), then move to another 16-byte block. You have 16 16-byte blocks in 256 bytes of eeprom, so could write over a million times.
Sure.

But how to keep track of which block is active, since the word variable is lost at power down. and it would be quite tricky to test it is actually working ?

Much easier to manage and test, so you have a high level of confidence it will work, would be a RTC with battery back up RAM. There are even RTCs that will time stamp the actual time of power failure which could be very useful info for testing and monitoring......
 

lbenson

Senior Member
>But how to keep track of which block is active, since the word variable is lost at power down.

When you write a block, also write the block # and block write count to eeprom. Robin seems to be looking for a minimalist hardware configuration. You could still have a mismatch when the power went off, so you might want to have a supercap to provide a few seconds of power, and detect failure and shut down gracefully.
 

lbenson

Senior Member
>But where in EEPROM do you write the block number and write count ?

For instance, at eeprom bytes 0-2, then just use the top 15 16-byte slots. When run in the simulator, the following program will illustrate writing 16 bytes to locations 32-47 in eeprom.

Code:
#PICAXE 08M2
#no_data

symbol eeprom_record_size=16 ' 16 bytes of data to be saved
symbol eeprom_write_count=0  ' location of write count (word)
symbol eeprom_data_slot=2    ' location of data slot number (byte)

symbol write_count=w13     ' number of times eeprom written
symbol data_slot=b25       ' current slot (1-15) for eeprom data
symbol eeprom_location=b24 ' where eeprom data is to be written

data_slot = 2   ' (implies eeprom bytes 32-47 for 16-bytes of data)
write_count = 12345 ' (for instance)

'set up data
b23 = "A"
bptr = 0
do while bptr < 16 ' set b0-b15 to values "A"-"P"
  @bptrinc = b23
  inc b23
loop

eeprom_location = eeprom_record_size*data_slot ' current starting address
write eeprom_location, b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15
write eeprom_write_count, WORD write_count, data_slot
inc write_count

bptr = 0
do while bptr < 16 ' set b0-b15 to 0
  @bptrinc = 0
loop

read eeprom_location, b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15
sertxd(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15)
 

MartinM57

Moderator
...or use some external FRAM - essentially unlimited writes (but not the preferred solution here as RL prefers solutions with no components :)D) ...and Ramtron FRAM seems to have disappeared off nearly all distributors inventories at the moment)

...or if you have the time (personal and code execution), code space and inclination, you can test an EEPROM value before writing to it and not writing to it if it already has the value you want. Tends to wear out different EEPROM locations at different rates (slowly changing locations last a lot longer), but can give some benefit (and also protects against an erroneous high speed looping program that always writes the same values every time and at high speed - after the initial write, the EEPROM will never be written to again)
 
Last edited:

lbenson

Senior Member
srnet's point about where you write the block and count data may have referred to the writing of that data in the same spot >100,000 times. That can be solved by writing the one-byte number only when it changes (once every 65,000+ times), and using different 2-byte areas to write the count. If you are monitoring power, and can determine that it is about to be shut off, you can only write to eeprom then.
 

papaof2

Senior Member
...or use some external FRAM - essentially unlimited writes (but not the preferred solution here as RL prefers solutions with no components :)D) ...and Ramtron FRAM seems to have disappeared off nearly all distributors inventories at the moment)
5 volt FRAM now seems to be rare. mouser.com has 3 volt FRAM.

John
 

Robin Lovelock

Senior Member
Thanks Folks. I just typed a long reply - but it didn't appear, so I'll make this much shorter :) Guess no surprise that I wont be adding that non-volatile memory. I'm very pleased with progress: only 1337 of 2048 bytes used - and all logic now in program - see below. Hope to add pictures and video of new boat 6 testing the autopilot soon.
Robin
www.gpss.co.uk/autop.htm

Code:
'NOTE MAJOR DELETIONS SO NOT TOO BIG FOR PICAXE FORUM
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 31st August 2011 (c) Robin Lovelock www.gpss.co.uk/autop.htm 
'This version is approaching being a usable version.
'Thanks to Hippy, Eclectic, SRNet and others on www.picaxeforum.co.uk
'input is serial RS232 GPS data 
'the GPS outputs text strings and includes ",A," after $GPRMC when ready
'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
'output is servo controlling rudder to steer boat on a particular heading

'note on behaviour of this test version - which seems to work as intended:
'This is for use with the faster 08M2 chip
'servo 1 controls rudder, based on GPS heading to steer the boat. 
'Servo 2 was used to aid testing. e.g. based on other data from GPS such as latitude.
'Servo 2 = CENTRE (not tracking), LEFT (Latitude>51N) RIGHT (Latitude<51N)
'after the startup waggle of the two servo, it should monitor the GPS
'and control the two servos. Testing can be with real GPS or the GPS Simulator.
'It now does do this, responding to if the GPS is tracking or not (silver paper over)
'If the GPS is tracking, then servo 1 is moved to steer boat according to GPS heading.
'It needed the LOW 1 to switch off SERVO before SERIN
'It gives a quick response to the GPS tracking or not tracking.
'polestar GPS red light flashes if not tracking, and solid if tracking.
'Latitude seems to work, now SERIN numeric bytes read as ASCII, then -48 to a value
'Lat/Lon not yet used to update the heading, but held accurately to 1/1000ths of a minute
'b0 = latitude degrees North only i.e. 0 to 89N
'b1 = longitude degrees West only i.e, 0 to 120W ???
'w1 = target heading 0 to 359
'w2 = GPS heading
'w3 = servo position
'w4 = GPS accurate minutes of latitude 0 to 59999 lsd = 0.001 minutes.
'w5 = GPS accurate minutes of longitude 0 to 59999 lsd = 0.001 minutes.
'w6 used as temp variable
'b14,b15 (w7) = destination lat, lon degrees.
'w8 = destination latitude minutes 0 to 59999 lsd = 0.001 minutes.
'w9 = destination longitude minutes 0 to 59999 lsd = 0.001 minutes.
'b21 = A or V = tracking or not tracking NOT USED NOW
'temporary variables b22 - b27 (W11,W12,W13)
'starting to add tests for reaching a waypoint to see effect on memory
'without:974 bytes out of 2048  with:1025 bytes out of 2048
'so each extra waypoint costs only 51 bytes of code
'trace output was used to Windows Terminal at 19200 baud during testing.
 
 #picaxe 08M2  
 setfreq M16
 
 Symbol CENTRE = 150 'Servo middle position
 Symbol THROW = 50
 symbol LEFT=CENTRE + THROW 'Servo left
 symbol RIGHT = CENTRE - THROW 'Servo right
 symbol FOR1SEC = 4000 'pause value at 16MHz for 1 sec
 symbol FOR2SEC = 8000 'pause value at 16MHz for 2 sec
 symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec
 symbol FORP5SEC = 2000 'pause value at 16MHz for 0.5 sec

 sertxd ( "AUTOP1 - testing two servos ...",10,13 ) 'test ouput back to PC at 19200

 'waggle servo 1 on startup to show that working - will control rudder
 PAUSE FOR1SEC 
 SERVO 1,CENTRE 'start servo control process - middle
 PAUSE FOR2SEC
 SERVOPOS 1,LEFT 'move servo to position 1
 PAUSE FOR1SEC
 SERVOPOS 1,RIGHT  'move servo to position 2
 PAUSE FOR1SEC
 SERVOPOS 1,CENTRE  'move servo to middle position
 
 PAUSE FOR1SEC  'same for servo 2 - shows other GPS data e.g.south of 51N
 SERVO 2,CENTRE 'start servo control process - middle
 PAUSE FOR1SEC
 SERVOPOS 2,LEFT 'move servo to position 1
 PAUSE FOR1SEC
 SERVOPOS 2,RIGHT  'move servo to position 2
 PAUSE FOR1SEC
 SERVOPOS 2,CENTRE  'move servo to middle position
 
 PAUSE FOR2SEC 'wait 2 secs before main loop
 
 b22 = 3: gosub waggle 'test waggle rudder servo 3 times 
  
 PAUSE FOR2SEC 'wait 2 secs before main loop
  
 sertxd ( "AUTOP1 - waiting for GPS data ...",10,13 ) 
 
 w1 = 225 'target heading is south west (we will update this in a later version)
 b14 = 51 'Destination degrees North
 b15 = 0  'Destination degrees West
 w8 = 30007 'Destination Latitude minutes for Bray Lake 51 30.007 N 000 41.411
 w9 = 41411 'Destination Longitude minutes
 'w8 = 23819 'Latitude minutes for AC22 51 23.819 N 000 39.591
 'w9 = 39591 'Longitude minutes
 
 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 Low 1 'switch off SERVO 1
 Low 2 'switch off SERVO 2
 PAUSE 1000

 'e.g. $GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18
 'e.g. $GPRMC,114801.123,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18

 SERIN 3, N4800_16, ( "$GPRMC," ) 'wait for $GPRMC sentence
 SERIN 3, N4800_16, ( ",A" ) 'wait until GPS is tracking 

  
 'now we are near the latitude - start by reading 5129.89 into bytes
 SERIN 3, N4800_16, ( "," ), b22,b23,b24,b25,b26,b26,b27,b21 'first b26 is to skip the decimal point

 'sertxd ( 10,13,"Raw data = ",b22,b23,b24,b25,b26,b27,b21 ) 'trace output back to PC
 
 b22 = b22 - 48: b23 = b23 - 48: b24 = b24 - 48: b25 = b25 - 48
 b26 = b26 - 48: b27 = b27 - 48: b21 = b21 - 48 'from ASCII
  
 b0 = b22 * 10 + b23 'degrees of latitude e.g 50
 w4 = b24 * 10 + b25 'minutes e.g. 30
 w4 = w4 * 1000 'convert minutes to 1/1000 ths minutes
 w6 = b26 * 100 'add 0.1 mins
 w4 = w4 + w6 'add 0.1 mins
 w6 = b27 * 10
 w4 = w4 + w6 'add 0.01 mins
 w4 = w4 + b21 'add 0.001 mins - now minutes of latitude in 1/1000yhs mins
 
 'read longitude ,N,00041.0771,W,
 SERIN 3, N4800_16, ( ",N," ), b22,b23,b24,b25,b26,b27,b27,b21 'first b16 is to skip the decimal point
 
 'sertxd ( 10,13,"Raw data = ",b22,b23,b24,b25,b26,b27,b21 ) 'trace output back to PC

 b22 = b22 - 48: b23 = b23 - 48: b24 = b24 - 48: b25 = b25 - 48
 b26 = b26 - 48: b27 = b27 - 48: b21 = b21 - 48  'from ASCII 
 
 b1 = b22 * 100 
 w6 = b23 * 10 + b24 
 b1 = w6 + b1 'longitude degrees e.g 001
 w5 = b25 * 10 + b26 'minutes e.g. 30
 w5 = w5 * 1000 'convert minutes to 1/1000 ths minutes
 w6 = b27 * 100 'add 0.1 mins
 w5 = w5 + w6 'add 0.1 mins
 w6 = b21 * 10 'add 0.01 mins
 w5 = w5 + w6 'add 0.01 mins
 SERIN 3, N4800_16,  b22
 'sertxd ( b22 ) 'trace output back to PC - the last digit of raw data

 b22 = b22 - 48
 w5 = w5 + b22 'add 0.001 mins - is now scaled longitude 1/1000 minutes
 
 SERIN 3, N4800_16, ( ",W," )
 SERIN 3, N4800_16, ( "," )
 SERIN 3, N4800_16, #w2 'the GPS heading the boat is travelling
 
 'sertxd ( 10,13,"AUTOP1 ",b21,", Lat=",#b0,"+",#w4,", Lon=",#b1,"+",#w5, ", Hdg=",#w2 ) 'trace output back to PC


 'if b21 <> "A" then 'if GPS not yet tracking
 '  goto nottrk
 'endif
 

 'The simple method, is to set target heading based on three boxes.
 'The centre box is a narrow lane to the target, either N-S or E-W
 'The target heading is set according to which box - to sail into the lane
 'and then follow the lane to the target

'MAJOR DELETIONS FOR PICAXE FORUM
 

srnet

Senior Member
Guess no surprise that I wont be adding that non-volatile memory
None at all.

I was looking at a similar issue myself recently, I was pondering whether it would be worthwhile to store the last know good GPS position in a power fail situation. EEPROM was the obvious choice, but I could not come up with a satisfactory method of controlling the writes to EEPROM over a long period, whilst at the same time being able to test that it would actually work. I may be a bit funny about this sort of thing, but I like to write code which I can prove by reasonable testing will work. The only way I could think of using EEPROM for data backup in this way was to test a PICAXE to destruction.

I did conclude that if I wanted this sort of battery backed up data facility, a RTC with RAM would be the way to go. Easier to verify its going to work, set up a rig that power cycled the PIC\RTC and see how often the data corrupted. RAM supports unlimited read\writes so no need to worry about cycling locations.
 

manuka

Senior Member
Robin: FYI-you may have heard of the meandering "Happy Feet" Emperor Penguin,which (back in June) turned up on a nearby NZ subtropical beach. His apparent swim to NZ from Emperors normal Antarctic home (~3000 km away) was almost akin to a polar bear being found in Gibraltar. Following local TLC he's just been returned to his southern ocean habitat, c/w a Kiwi designed tracker => http://www.sirtrack.com . It's possible technical insights for your own quest could be gained from this. Stan.
 

Robin Lovelock

Senior Member
Thanks Folks. It looks as if I can manage without non-volatile RAM - still plenty of space for program logic. Yes, wildlife tracking can sometimes be of interest - I looked into the cuckoo tracking - tiny solar panel - spends most of day charging up, ready for a short transmission: not unlike what we did on bottles. I've just updated the page with a bit more about our testing the PICAXE autopilot with a new boat 6. Have not updated the video yet. We've started testing the autopilot on Bray Lake and I've added some more test equipment including an onboard video camera. Hope to do more testing soon - maybe even today :)
Robin
www.gpss.co.uk/autop.htm
 

Robin Lovelock

Senior Member
Hi Folks. I've just had a bright idea. But first a reminder of where I am...

Things have gone well with the simple autopilot based on the AXE024 servo driver with the faster 08M2 chip. The simple GPS->PICAXE->rudder servo autopilot can steer the boat through a number of waypoints, and should work most of the time across the Atlantic, based on our knowledge of average wind directions. This solution does not "know" wind direction - unlike our iPAQ based solution. New pictures are on www.gpss.co.uk/autop.htm including of our new, small, 3 ft long boat 6, being used to test the new system.

Not knowing the wind direction means that, some of the time, the boat will be trying to sail directly into the wind, failing miserably. Ideally, if it knows the wind direction, it will attempt to tack, no closer than about 45 degrees to the wind.

My bright idea is a simple microswitch which detects when the main sail boom is pointing directly back - and for this to be wired into a spare input pin in the PICAXE. There are three servo positions on the AXE024 and I'm using two to drive servos: the rudder servo, and - possibly soon - a vane-rudder clutch. This is if we develop a suitably mechanically robust vane-rudder with clutch, to keep the boat steered if it losers power (accidentally or deliberately). A possible problem is that I think I'm using the third servo position input pin for my SERINs to read the GPS data. But maybe servos only use the output pin ?

Here are some extracts from my code, so you can see what pins are used for SERINs and SERVOPOS commands.
SERIN 3, N4800_16, ( "$GPRMC," ) 'wait for $GPRMC sentence
SERVOPOS 1,CENTRE 'move rudder servo to middle position
SERVOPOS 2,CENTRE 'move servo 2 to middle position

I'm guessing my microswitch should connect the appropriate spare pin to ov or +5v. Through a resistor ?
What instruction should I use to test the state of the pin ?

Many Thanks in advance.
Robin
www.gpss.co.uk
 

Jamster

Senior Member
See manual 3 about interfacing, the command would just be:

if pin1=1 then
'do whatever
endif

but change "pin1" to whatever pin you are using.
Jamster
 

Robin Lovelock

Senior Member
Thanks Jamster. Sorry - I should have phrased my main question more clearly:
what pin is spare in my particular solution - if any ?
Here are some extracts from my code, so you can see what pins are used for SERINs and SERVOPOS commands.
SERIN 3, N4800_16, ( "$GPRMC," ) 'wait for $GPRMC sentence
SERVOPOS 1,CENTRE 'move rudder servo to middle position
SERVOPOS 2,CENTRE 'move servo 2 to middle position
Robin
 
Top