PICAXE handling GPS for robot boat

Robin Lovelock

Senior Member
Hi Folks. Yes, I'm afraid it's me again, after the BBC bottles in the sea on www.gpss.co.uk/bbcbot.htm (causing that rare earthquake), I'm back onto the robot boat stuff - checkout the "Snoopy Sails!" video on www.gpss.co.uk/autop.htm - and give yourself time to stop laughing :)

This thread is about using ONLY a PICAXE and GPS to control a robot boat to sail the Atlantic, from UK to America - north or south is OK.

The existing prototypes are all similar in principle, using an iPAQ to take data from the GPS, do all the navigation logic, and just using a PICAXE servo driver to drive the vane-rudder to steer the boat.

I'm thinking of a radically simpler solution: just a GPS-PICAXE-Servo to keep the boat sailing roughly west all the time.
Result would be a much smaller and lower cost boat, maybe only 1 foot to 2 foot long.

Key to it is the required logic to extract GPS heading from the NMEA $GPRMC sentence.
All the other fields of data, like latitude and longitude can be skipped.
I've pasted in the code below from the little program you guys helped me with a year or two back.

An example NMEA sentence from the GPS is:
$GPRMC,114801,A,5129.8944,N,00041.0771,W,3.53,358.23,280608,,*18

The program needs to look for the $GPRMC because there will be other sentences like $GPGGA etc.
The characters it needs are the heading in 358.23

It would be good if the logic could do something like look for the commas (,)
to cover different types of GPS, which may have different field sizes. e.g. 358 instead of 358.23

It does not need to work east of the Greenwich meridian, so we might look for ,W, after the $GPRMC

After extracting the characters, such as 358.23 I then need this as a value.
It does not need to be accurate - a simple integer 0 to 359 will be OK (degrees clockwise from north).
So I need the three bytes 3 5 and 9 to be converted into a number value 359.

I'll then do some simple logic to drive the steering servo.

It seems that example code below, that I did with your help, might get me started.
But - as always - you guys might save me a lot of time.

Let me guess what might work:
SERIN 3,N4800_8,("$GPRMC,") 'look for the $GPRMC
SERIN 3,N4800_8,(",W,") 'now look for ,W,
SERIN 3,N4800_8,(",") 'skip over the speed

Now I'm struggling :)

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

Code:
'SC2.BAS iPAQ switch for robot boat
'v1a 13 Sep 2009 (c) Robin Lovelock www.gpss.co.uk/autop.htm 
'Thanks to LBenson, Eclectic and Hippy on www.picaxeforum.co.uk
'input is serial RS232 GPS data - to see when GPS is ready
'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 switching of iPAQ power ON
'note that no need to use or hold servo until just before exit

 #Picaxe 08M
 SETFREQ M8 '8MHz for SERIN 

 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps: '
 SERIN 3,N4800_8,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b1 'Eclectic
 'SERIN 3,N4800_8,("$GPRMC,")
 'SERIN 3,N4800_8,(","),b1 'idea from lbenson on picaxe forum
 if b1 <> "A" then 'this idea from eclectic on picaxe forum
   goto waitgps
 endif
 
 SETFREQ M4 'standard 4MHz
 PAUSE 1000
 
 SERVO 1,91
 PAUSE 1000
 SERVOPOS 1,126 'toggle servo to switch on iPAQ power
 PAUSE 1000
 SERVOPOS 1,91
 PAUSE 3000 'give servo time to travel then exit
 

Graham O

Member
With the sample code you've posted, i.e. reading GPS data into b0, b1 etc, it gets a bit messy when the position of the value you want is changing because a previous value has gone from 1 to 3 digit for example. The method I'm using for a high altitude balloon is to identify the string you want, (in this case $GPMRC) and then count through the commas to get to the field you want. Extract the values and then process accordingly.
 

Jamster

Senior Member
http://www.picaxeforum.co.uk/showthread.php?7957-flying-uav-update-not-good
The idea looks like it never got off the drawing board due to the numerous problems: Choppy seas, waterproofing, power, laws, etc.

You will need to test the boat (the atlantic is roughly 106,400,000,000 times bigger than your boat) and may want to sail by the side of the boat to make sure it doesn't do anything stupid.

I will be very interested as to where this goes, I thought about designing an autonomous boat that could sail down a river at least.

Best of luck,
Jamster
 

hippy

Technical Support
Staff member
It seems to me that the following should work ...

SERIN 3, N4800_8, ( "$GPRMC," )
SERIN 3, N4800_8, ( "," ), b1
SERIN 3, N4800_8, ( ",W," )
SERIN 3, N4800_8, ( "," )
SERIN 3, N4800_8, #w2

You'll then have the "A" in 'b1' and your 0 to 359 reading in 'w2'.
 

MPep

Senior Member
Hippy,
I tried your idea a few years ago. But it didn't work.
Given the current range of PICAXE chips and their very fast operating clocks (EM32 etc), there should now be enough time to get to the next SERIN and wait for the next ",".

Robin,
Would love to read your progress on this project.
To aid navigation, may I also suggest using a fluxgate sensor (magnetic compass) to give direction information. A few have been discussed on the forum in the past.
Remember that a GPS only knows its direction when the vessel is underway.

MPep.
 

srnet

Senior Member
I would suggest an alternative approcah is needed.

Within the limits of the GPS refresh, the boat might appear to be moving West for instance, but could be creeping North or South, so how much of the East Coast of America can be searched for the boat ?

And the obvious point, the prevailing winds in the Atlantic are generally West to East, so to go the 'wrong' way you need to tack all the time. Even if you could keep the boat pointing West, its going to be going backwards most of the time.
 

hippy

Technical Support
Staff member
I tried your idea a few years ago. But it didn't work.
Given the current range of PICAXE chips and their very fast operating clocks (EM32 etc), there should now be enough time to get to the next SERIN and wait for the next ",".
I wasn't sure about it working but seeing the code example assumed it would - but looking more closely that similar code is commented out.

You're probably right about speed of execution, too slow to have read one qualifier and/or data to get back and be ready for the next. As you say 32MHz on the M2 and 64MHz on the X2 may overcome that.

On the X2 there's also the HSERIN background receive; grab a packet then disable receive until processed. A 28X2 may be preferable to a 20X2 for the larger buffer size. The advantage of that is that all the data is available and can use any of it to determine heading and there's probably plenty of time to do any complicated maths.

Added : Suggested code works okay on 08M2 at 32MHz.
 
Last edited:

srnet

Senior Member
What you probably need is a GPS that can can be pre-programed with a waypoint (NY for instance) and will output the $GPBWC - Bearing and distance to waypoint sentance.

In this way you stand a chance of being able to correct the 'direction' to allow for current drift, wind, temporary loss of GPS signal etc.

Other systems can do this sort of calculation within the Micros code, but it really needs floating point maths and trigonometry capability.
 

hippy

Technical Support
Staff member
Code:
#Picaxe 08M2

' Test data to send ... $GPRMC,,A,W,,123,

SetFreq M32
Pause 16000
SerOut 4, N4800_32, ( "Ready", CR, LF )
Do
  SerIn  3, N4800_32, ( "$GPRMC," )
  SerIn  3, N4800_32, ( "," ), b1
  SerIn  3, N4800_32, ( ",W," )
  SerIn  3, N4800_32, ( "," ), #w2
  SerOut 4, N4800_32, ( #b1, " ", #w2, CR, LF )
Loop
 

MPep

Senior Member
What you probably need is a GPS that can can be pre-programed with a waypoint (NY for instance) and will output the $GPBWC - Bearing and distance to waypoint sentance.

In this way you stand a chance of being able to correct the 'direction' to allow for current drift, wind, temporary loss of GPS signal etc.

Other systems can do this sort of calculation within the Micros code, but it really needs floating point maths and trigonometry capability.
If you purchase a ready-made GPS, then you can add Waypoints, and use Goto Waypoint to get there. Usually, the Autopilot sentences then become available in the NMEA data output port. I believe the simplest Garmin eTrex is capable.
Using only a GPS module, no 'smarts', then you need to be able to enter destination before launch.

SRNET's warning on the prevailing winds should also be noted of course. You'd need extended battery power in order to keep the boat controllable for as long as possible.


As an aside, anybody seen this: http://rucool.marine.rutgers.edu/atlantic/about_gliders.html ?
 

hobgoblin

New Member
as an aside it is very easy to combine 2 numbers into 1.
eg: A=3 B=7
C=B+(A*10)
.:C=7+30=37
simple!
easy to expand to more digits, just multiply each by 100,1000 etc
 

hippy

Technical Support
Staff member
Note that it's necessary to take the left-to-right precedence into account ...

N = ( A * 1000 ) + ( B * 100 ) + ( C * 10 ) + D

using PICAXE maths would be ...

Let N = A * 10 + B * 10 + C * 10 + D
 

Robin Lovelock

Senior Member
Many Thanks Folks. This shows the value of using this forum. I'm grateful for Hippy's quick direct answer, and after I've finished digging out the required bits from my garage, I'll be putting a test program in and trying GPS->PICAXE->servo to see the servo move as I walk around my drive.

But the really amazing surprise resulted from MPeP's posting - I just found the required NMEA sentence coming out of my very old Garmin etrex. I selected a local waypoint,
corresponding to my house (AC22 for 22 Armitage Court) and, with HyperTerminal - there was the needed bearing: $GPBOD,89.2,T,92.0,M,AC22,*4D. I was amazed, since, when I was first thinking of robot boats, over 3 years ago, and set up www.gpss.co.uk/autop.htm you will see near the bottem of the page, under "early thoughts" that I had been thinking of this more obvious but complex approach - but I had no idea I had it in my old etrex !

That old yellow etrex has some sentimental value, so may not go to sea - my wife June brought it back from New York after their shopping trip, just after 911, in 2001.

But you can see the simple possability: instead of a little GPS mouse going into the PICAXE, we could use something like an old etrex. The simple PICAXE program I'm about to try (thanks Hippy) might start by just using the actual heading from $GPRMC, and comparing this with a fixed 270, to steer west (or some other fixed direction). BUT, if it also took the required direction out of the $BOD sentence, it might guide the boat to a precise destination. Obviously with none of the "extras" already in our existing, iPAQ based auto-pilot - but a LOT simpler, cheaper, and maybe more reliable.

For those who posted but did not play the video on my autop.htm page above - yes, of course things like solar panels are an important part of the solution.

Many Thanks everyone. I hope to report progress soon.
Robin
www.gpss.co.uk
 

Robin Lovelock

Senior Member
That's right srnet - you will also find these guys on my page www.gpss.co.uk/tam.htm which was set up soon after these old American guys did that epic model aircraft flight. The chap who'd done their GPS guidance and satcomms tracking, contacted me several years earlier, in 1998, and later told me my GPS Software had "inspired him" - that was praise indeed - and I was highly honoured indeed. As it happens, I've contacted him again recently, since the stacomms tracking (or other means using radio HAMs) is the one essential part of this little project.

Now - I really must continue digging out a GPS from the junk in the garage - but I've just been interrupted by my local "last of the summer wine" friends - who are dragging me out to the pub for lunch. Oh well - someone has to do it :)

Robin
www.gpss.co.uk

Been done by a Model plane;

http://en.wikipedia.org/wiki/The_Spirit_of_Butts_Farm

Scarry really, a lump of self build balsa and plastic, no doubt invisible to radar, that you can launch from 3,000Km away and arrives at the target 38 hours later .........
 

Robin Lovelock

Senior Member
Hi Folks. Here is the test program AUTOP1.BAS that I've been experimenting with today.
This was after finding the bits needed in my garage, including a PICAXE project board and Polestar GPS mouse.

The comments in the code pretty well describe the situation: If I use the SERIN that Eclectic gave me a year or two back (the long robot boat thread), then I can read the $GPRMC sentence and extract the parameter of value "V" or "A" saying if the GPS is tracking. The program can also move the servo to a position 1 or 2 to indicate this. But the program loop also moves the servo to a third position - maybe a side effect of changing frequency to use SERIN again.

Now some history: that old, long robot boat thread was where you - particularly Hippy - helped me get the PICAXE SC1.BAS solution working which is still used - taking RS232 commands from an iPAQ and driving one or more servos. In that long process it became apparent that the normal SERVO/SERVOPOS commands could not be used with SERIN. However, Hippy showed me how to program around this restriction, by going down to the lower level generation of the pulse train to the servo.

As part of this process, Eclectic showed me how to read GPS NMEA data, starting with $GPRMC, and extract the byte, value "V" or "A" which says if the GPS is tracking. i.e. if the GPS is giving good data such as latitude and longitude. This was used in an SC2.BAS application - option to have a PICAXE-controlled switch, to switch on the iPAQ after the GPS is tracking. Eclectic's SERIN is used in the program below. Hippy's original statements don't seem to work, but there could be several reasons - including those discussed on this thread, where Hippy agreed and posted a loop of code - not yet tried. Best discuss this stuff first.

It's possible that you will conclude that my "third position" problem with the servo, is the same restriction of trying to mix SERIN and SERVO. However, if a simple solution, using these statements can be found, that will be good. Note that for this application we can allow hug delays with the servo in it's required position and perhaps
the occasional twitch.

I'm working on the basis of getting a simple test program working that uses the "tracking/not tracking" item in the $GPRMC sentence, and then move on to capturing the GPS heading information - for the steering function to be done by this program. If that works, and the program has not become to large or complex, we might exploit the speed value (heading is only reliable if speed > 0.5mph ballpark) and MAYBE even that $GPBOD from a Garmin etrex - that would be really good.

But one step at a time. Sorry in advance for any silly mistakes in the code below, or important information left out.
Testing is not too bad a process when it's dry and sunny like now: watching what happens on my patio table out back :)

Robin
www.gpss.co.uk/autop.htm - the most relevant page on my www.gpss.co.uk

p.s. I should have mentioned that we can afford to miss a lot of the GPS data. In fact, I'm hoping that the GPS data has NOT been buffered up, ready for the program to go back to read the GPS after doing something with the servo - and maybe deliberately waiting for a while, to allow the rudder to have a turning effect. This may be relevant to Hippy's "second thoughts" about the code I've used. If a lot of GPS data is waiting in a buffer, it may take a long time before the program gets round to seeing the latest data - all it needs to know.


Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 28 July 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:
'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 does do this, responding to if the GPS is tracking or not (silver paper over)
'but the the change of freq seems to reset servo to equiv of SERVOPOS, 1, 0
'polestar GPS red light flashes if not tracking, and solid if tracking.
' SERIN 3,N4800_8,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b1 'WORKS OK
' but the 5 alternative SERIN do not pick up the b1="A"

 'waggle servo on startup to show that working
 SETFREQ M4 'standard 4MHz
 PAUSE 1000 
 SERVO 1,91 'start servo control process
 PAUSE 1000
 SERVOPOS 1,91 'move servo to position 1
 PAUSE 3000
 SERVOPOS 1,126  'move servo to position 2
 PAUSE 5000 'wait 5 secs before main loop

 #Picaxe 08M

 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 SETFREQ M8 '8MHz for SERIN 
 PAUSE 1000
 SERIN 3,N4800_8,("$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
 'SERIN 3, N4800_8, ( "$GPRMC," ) 'thanks Hippy :-)
 'SERIN 3, N4800_8, ( "," ), b1 'A = GPS tracking or V = not yet tracking
 'SERIN 3, N4800_8, ( ",W," )
 'SERIN 3, N4800_8, ( "," )
 'SERIN 3, N4800_8, #w2 'the GPS heading the boat is travelling
 
 'b1 = "V" 'test position 1
 'b1 = "A" 'test position 2
  
 if b1 <> "A" then 'if GPS not yet tracking
   goto nottrk
 endif
 
 'GPS is tracking 
 SETFREQ M4 'standard 4MHz
 PAUSE 1000
 SERVO 1,126
 PAUSE 1000
 SERVOPOS 1,126 'move servo to position 2
 PAUSE 10000 
 goto waitgps

 'GPS is NOT tracking
nottrk: 
 SETFREQ M4 'standard 4MHz
 PAUSE 1000 
 SERVO 1,91
 PAUSE 1000
 SERVOPOS 1,91 'move servo to position 1
 PAUSE 10000
 goto waitgps
 
Last edited:

srnet

Senior Member
To aid navigation, may I also suggest using a fluxgate sensor (magnetic compass) to give direction information. A few have been discussed on the forum in the past.
Remember that a GPS only knows its direction when the vessel is underway
You can navigate accuratly with a magnetic compass of course, but to do that you need to know (more or less) where you actually are in the first place.
 

hippy

Technical Support
Staff member
One brilliant thing with the M2's ( particularly the 08M2 because it's small and cheap ) is that using HSERIN, although only limited buffering, they can be perfect as a 'smart peripheral'.

That means it could receive a byte of data from another PICAXE, set a servo position from that, and because it's not doing anything else, doesn't need to block to do input, it should give jitter-free servo operation. It's also possible to use a PULSOUT and timed loop so it could operate at any frequency without using any actual SERVO commands.

If happy to have just 128, 64 or 32, servo positions a single M2 could control 2, 4 or even 8 servos. It could even continue to run while the controlling PICAXE were powered-down.

Splitting a project across multiple PICAXE does add board space, slightly more cost, draws a bit more power, but it can considerably simplify the software and overcome coding conundrums and conflicts. The effort for two or more PICAXE can often be a lot less than for just a single PICAXE. A classic example is in using the AXE033 or FRM010 to handle serial to LCD interfacing, which then only requires SEROUT commands rather than having to handle all the LCD interfacing on top of what one wants to concentrate on doing in their program. Where the master PICAXE would like to do all manner of things but is constrained in having to do it to comply with requirements like not changing frequency to keep servos working as expected it can make a lot of sense to shunt that off to where it can't be affected by whatever the master does.

There are good and valid reasons to do everything on a single PICAXE but sometimes that can be false economy.
 

MPep

Senior Member
You can navigate accuratly with a magnetic compass of course, but to do that you need to know (more or less) where you actually are in the first place.
Of course. The point of the post was to allow an extra sensor input. Say a wave caused the vessel to turn around. The Speed Over Ground would then have been -ve to where you wanted to go. A fluxgate sensor could then be read, and the PICAXE autopilot would then know that the vessel was pointing the wrong way, and take action as required.

@Robin,
I, of course, didn't know that you had an eTtrex. I was just thinking about the simplest ready-made GPS unit on the market. I realise its a few years old, but perfectly capable. Was really pointing out that 'simple' GPSs can be used.
Pleased my post helped point (no pun intended) in the right way.
 

papaof2

Senior Member
If you want to always have a compass heading (0-359), Sure has an I2C plus serial interface digital compass for less than $20US delivered (http://cgi.ebay.com/NEW-Dual-axis-Magnetic-Sensor-Module-Interface-improved-/160619379851). At this price, it's not compensated for pitch and roll, but that ability is found in I2C interface compasses that start around $150US (http://www.sparkfun.com/products/8656) and go up from there - search for compass at SparkFun to see what else is currently available.

I've interfaced the $150 compass to a PICAXE 28X2/40X2 and the I2C is easy. I have a Sure serial compass that I've yet to test - only so many productive hours in a day...

John
 

srnet

Senior Member
Of course. The point of the post was to allow an extra sensor input. Say a wave caused the vessel to turn around. The Speed Over Ground would then have been -ve to where you wanted to go. A fluxgate sensor could then be read, and the PICAXE autopilot would then know that the vessel was pointing the wrong way, and take action as required.
I see the point you are making, whilst you cannot 'navigate' with the compass you get an immediate indication of where the boat is facing, something a GPS cannot do.
 

manuka

Senior Member
Robin: The short journey time of small planes allows launching during favourable weather conditions. In contrast the many weeks a sea going vessel may take means all kinds of rough weather may arise. FWIW hence perhaps initially concern yourself MUCH more with the vessel rather than the GPS. A similar quest some years ago to auto-navigate NZ-Australia (across seas akin to the Atlantic),saw the much hyped unmanned rugged solar powered "boat" ($$,$$$) totally swamped just a few miles offshore...

Ah-what-is-your-budget? Perhaps check the $$,$$$,$$$ solar boat quest underway at present!
 
Last edited:

Robin Lovelock

Senior Member
Hi Folks. First something very different: click on the little World map at bottom of www.gpss.co.uk and you will see the laast few people visiting the page - or at least the town and country they are in - or near. I think I saw Manuka visit at 0810 UK time when I looked today. Spooky eh ? :)

The code below probably is all wrong, but is what I'm playing with now. Trouble is that we now have drizzle, so it's not pleasant going outside to get a good GPS signal :-( Guess I'll now have to add an umbrella to my test equipment !

If anyone sees any errors, or has relevant ideas, I'll be gratefull.

Yes, I'm familiar with spending lots of money - in the defence industry where I worked since the 1960s :)

This little PICAXE project is just to see if I can make a really cheap but reliable "throw away" solution. I doubt if I will risk my iPAQ based boats just yet - not without a lot more testing. Of course, the really essential part is the GPS-Satcomms tracking, such as SPOT, and this is not the Forum to discuss that.

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

Code:
 'waggle servo on startup to show that working
 SETFREQ M4 'standard 4MHz
 PAUSE 1000 
 SERVO 1,91 'start servo control process
 PAUSE 1000
 SERVOPOS 1,122 'move servo to position 1
 PAUSE 2000
 SERVOPOS 1,167  'move servo to position 2
 PAUSE 2000
 SERVOPOS 1,146  'move servo to middle position
 PAUSE 5000 'wait 5 secs before main loop
 
 #Picaxe 08M
 
  
'this is based on code from Hippy - August 2009 - in SC1.BAAS
 Low 1 : Low 2 : Low 4 'switch off SERVO background
 
 w1 = 320 ' 160 @ 4MHz
 w2 = 320 ' 160 @ 4MHz
 w3 = 320 '1h 160 @ 4MHz

 w0 = 4000 - w1 - w2 / 100

 SetInt %01000, %01000

 Do
   Pause      w0
   Pulsout 1, w1 
   Pulsout 2, w2
   Pulsout 4, w3 
 Loop

Interrupt:
  SERIN 3,N4800_8,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b12 'thanks Eclectic :-)
  w1 = 200 'Position 1 = NOT tracking
  if b12 = "A" then 'if GPS is tracking
     w1 = 400 'Position 2 = IS tracking
  endif  
  w0 = 4000 - w1 - w2 - w3 / 100 
  Pause w0
  SetInt %01000, %01000
  Return
 
Last edited:

MPep

Senior Member
Of course, the really essential part is the GPS-Satcomms tracking, such as SPOT, and this is not the Forum to discuss that.
Hi again Robin,

For satcomms, I suspect that you are not going to need a large data payload, so may I recommend you look into an Iridium 9602 Short-Burst-Data modem. SBD can transfer about 140 bytes per message, which is of course more than enough to get a position report. I have some experience in these machines. Use plain ASCII serial comms, in a satellite modem. Check it out here. PM me for more info. In a project I did a few years ago, I managed to use 40bytes to send a complete position report, including time, date, SOG, COG, etc, to an email address.

Trouble is that we now have drizzle, so it's not pleasant going outside to get a good GPS signal :-( Guess I'll now have to add an umbrella to my test equipment !
Another way is to use an active GPS antenna outside. Supply it with power, in a DC injection box, and then use a passive antenna as a re-radiator. The active antenna will provide enough signal through to the eTrex!
OR move the GPS closer to a window as you should see enough satellites.

Regards,
MPep.
 
Last edited:

Robin Lovelock

Senior Member
Thanks MPEP. Yes, some of the robot boat guys are using Iridium, and I've recently emailed my old contact in Boeing Aerospace, who took over the system from Motorola. That must have been the best part of 10 years ago when Boeing used my software in their Iridium remote tracking demonstrator. Feedback on satcomms tracking is best sent direct to me on my gpss@compuserve.com address. I'd like this thread to focus on this particular PICAXE task. But many thanks - don't let that disuade you :)
 

manuka

Senior Member
Yes, I'm familiar with spending lots of money - in the defence industry where I worked since the 1960s :)
That was other peoples money- Autonomous Surface Craft (ASC) receive significant naval interest of course,but at budgets well beyond that of small change PICAXE projects...

Excuse my ongoing slant Robin, but I tend to be holistic about technical quests as I get older (yeah- voice of experience). Although I'm often a fanatic about small aspects, it's important to keep things in perspective,AND remain alert for "fish hooks". Stan.
 

Robin Lovelock

Senior Member
Yes Stan - my sentiments exactly :) Of course, as expected, I found a silly bug - not switching frequency to 8MHz before main loop, using SERIN, but the following code is getting closer to working. What it does do is in the comments. Thought I'd better post it here to reduce wasted effort by others. The sun is coming out - so no need for the brolly :) I'm sure there are other bugs, due to my lack of understanding of driving servos with PULSOUT, or other things - but maybe someone will help me find them.

When moving the servo between two positions, according to the "A"/"V" parameter, I can then try Hippy's code again to try and pick up, then use, the GPS heading.

I'm not using an etrex (yet) - just a little Polestar GPS mouse.

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

Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 29 July 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:
'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 does do this, responding to if the GPS is tracking or not (silver paper over)
'but moves to these positions in several steps, taking a few seconds.
'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
' but the 5 alternative SERIN do not pick up the b1="A"

 'waggle servo on startup to show that working
 SETFREQ M4 'standard 4MHz
 PAUSE 1000 
 SERVO 1,146 'start servo control process - middle
 PAUSE 2000
 SERVOPOS 1,122 'move servo to position 1
 PAUSE 2000
 SERVOPOS 1,167  'move servo to position 2
 PAUSE 2000
 SERVOPOS 1,146  'move servo to middle position
 PAUSE 4000 'wait 4 secs before main loop
 
 #Picaxe 08M
 
  
'this is based on code from Hippy - August 2009 - in SC1.BAAS
 Low 1 : Low 2 : Low 4 'switch off SERVO background
 PAUSE 1000
 
 SETFREQ M8 '8 MHz so SERIN will work
 
 w1 = 320 ' 160 @ 4MHz
 w2 = 320 ' 160 @ 4MHz
 w3 = 320 ' 160 @ 4MHz

 w0 = 4000 - w1 - w2 - w3 / 100
 w5 = 0

 SetInt %01000, %01000

 Do
   Pause      w0
   Pulsout 1, w1 
   Pulsout 2, w2
   Pulsout 4, w3 
 Loop

Interrupt:
  if w5 > 0 then 'if interrupts still disabled
    Return
  end if
  SERIN 3,N4800_8,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b12 'thanks Eclectic :-)
  if b12 = "A" then 'if GPS is tracking
     w1 = 400 'Position 2 = IS tracking
  else
     w1 = 200 'Position 1 = NOT tracking
  endif  
  w0 = 4000 - w1 - w2 - w3 / 100 
  w5 = 1 'disable interrupts
  Pause w0
  w5 = 0
  SetInt %01000, %01000
  Return
 

Robin Lovelock

Senior Member
Success ! I've now got the program to do what it should - without glitches in servo position, AND with the simple use of SERVO/SERVOPOS at 4MHz, switching to 8MHz for use of SERIN to read the GPS serial data. The key was simply to add a LOW 1 to switch off the SERVO pulses before SERIN. The code below includes the unused alternative method with PULSOUT - I may need to go back to it :)

Now I've got servo control and use of the "A"/"V" in the GPS data, I'll try Hippy's code to read the GPS heading with SERIN.

Robin

Code:
'AUTOP1.BAS simple auto pilot for robot boat
'v1a 29 July 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:
'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
' but the 5 alternative SERIN do not pick up the b1="A"

 #Picaxe 08M

 'waggle servo on startup to show that working
 SETFREQ M4 'standard 4MHz
 PAUSE 1000 
 SERVO 1,150 'start servo control process - middle
 PAUSE 2000
 SERVOPOS 1,75 'move servo to position 1
 PAUSE 2000
 SERVOPOS 1,225  'move servo to position 2
 PAUSE 2000
 SERVOPOS 1,150  'move servo to middle position
 PAUSE 4000 'wait 4 secs before main loop
 
 
 'wait until GPS ready $GPRMC,114801,A,5129.8944,N, etc,etc
waitgps:
 Low 1 'switch off SERVO
 SETFREQ M8 '8MHz for SERIN 
 PAUSE 1000
 SERIN 3,N4800_8,("$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
 'SERIN 3, N4800_8, ( "$GPRMC," ) 'thanks Hippy :-)
 'SERIN 3, N4800_8, ( "," ), b1 'A = GPS tracking or V = not yet tracking
 'SERIN 3, N4800_8, ( ",W," )
 'SERIN 3, N4800_8, ( "," )
 'SERIN 3, N4800_8, #w2 'the GPS heading the boat is travelling

 if b1 <> "A" then 'if GPS not yet tracking
   goto nottrk
 endif
 
 'GPS is tracking 
 SETFREQ M4 'standard 4MHz
 SERVO 1,225 'start servo pulses
 SERVOPOS 1,225 'move servo to position 2
 PAUSE 3000 'at least 3 secs here
 goto waitgps

 'GPS is NOT tracking
nottrk: 
 SETFREQ M4 'standard 4MHz
 SERVO 1,75
 SERVOPOS 1,75 'move servo to position 1
 PAUSE 3000 'at least 3 secs here
 goto waitgps
 
 
 
 
 
'THIS CODE NOT CURRENTLY USED - ALERNATIVE BASED ON PULSOUT  
'this is based on code from Hippy - August 2009 - in SC1.BAAS
 Low 1 ': Low 2 : Low 4 'switch off SERVO background
 PAUSE 1000
 
 SETFREQ M8 '8 MHz so SERIN will work 
 w1 = 320 ' 160 @ 4MHz
 w0 = 4000 - w1  / 100
 w5 = 0

 SetInt %01000, %01000

 Do
   Pause      w0
   Pulsout 1, w1 
 Loop

Interrupt:
  if w5 > 0 then 'if interrupts still disabled
    Return
  end if
  SERIN 3,N4800_8,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b12 'thanks Eclectic :-)
  if b12 = "A" then 'if GPS is tracking
     w1 = 450 'Position 2 = IS tracking 225 @ 4MHz
  else
     w1 = 150 'Position 1 = NOT tracking 75 @ 4MHz
  endif  
  w0 = 4000 - w1  / 100
  w5 = 1 'disable interrupts
  Pause w0
  w5 = 0
  SetInt %01000, %01000
  Return
 

Robin Lovelock

Senior Member
Ok - guess we are getting to that crunch point, and Hippy's doubts, prompted by one of you, that my little PICAXE servo drivers will not be fast enough. That seems to be the case, when I tried Hippy's code, posted quickly on this thread. the relevant section is below.

Code:
SERIN 3,N4800_8,("$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_8, ( "$GPRMC," ) 'thanks Hippy :-)
 'SERIN 3, N4800_8, ( "," ), b1 'A = GPS tracking or V = not yet tracking
 'SERIN 3, N4800_8, ( ",W," )
 'SERIN 3, N4800_8, ( "," )
 'SERIN 3, N4800_8, #w2 'the GPS heading the boat is travelling
That single line from Ecletic (a year or two back) works fine - but would only work on the first of the two example GPS $GPRMC sentences.
i.e. we do need something that will count the commas, or do something similar, to extract the required field(s). Right now, I'm simply trying to extract that same "A"/"V" field, but in a way that we might use to extract other data like GPS heading. Would also be good if the code did not depend on the precise sentence coming out of the GPS. i.e. it would still work, whatever NMEA GPS we plugged in.

I'm hoping one of you can see a solution for reading that GPS data.

I won't change my old SC1.BAS program now (used for the iPAQ driven PICAXE servo driver), but it does seem that this is a simpler approach of mixing SERIN and SERVO.

Many Thanks in advance.
Robin
www.gpss.co.uk/autop.htm
 

eclectic

Moderator
A "don't know" at the moment, but a question.

Which Picaxe are you using for the tests?

Would a modern (and cheap) 08M2 at 32 MHZ be better?

e
 

Robin Lovelock

Senior Member
With the sample code you've posted, i.e. reading GPS data into b0, b1 etc, it gets a bit messy when the position of the value you want is changing because a previous value has gone from 1 to 3 digit for example. The method I'm using for a high altitude balloon is to identify the string you want, (in this case $GPMRC) and then count through the commas to get to the field you want. Extract the values and then process accordingly.
Hi Graham - thanks for that early posting. Now that I've got the servo control to work with SERIN, I'm ready to try what's needed to read that GPS data.

What sort of SERIN statement(s) were you using ? Maybe something to read enough bytes with SERIN into a byte array ?
If I can get that far, I can see it should not be too difficult to scan the array, counting commas, to extract the fields required.

Robin
 

Robin Lovelock

Senior Member
Thanks Eclectic: the old, slow 08M Project board, with a view to putting the same thing on the 08M servo controllers.
I prefer to find out the (undocumented) limitations of a product before trying yet another of the same brand :)
Robin

p.s. I guess switching to the faster version is not just plugging in another chip ?
That would be good, but I assume another board would have to be assembled ?
But, as I say, I would not be surprised if there is a software solution. e.g. that byte array.

A "don't know" at the moment, but a question.

Which Picaxe are you using for the tests?

Would a modern (and cheap) 08M2 at 32 MHZ be better?

e
 
Last edited:

papaof2

Senior Member
A PICAXE with HSERIN capability would make it easier to parse the NMEA sentence. It's also faster/easier to process the NMEA sentences if you can configure the GPS to only send the sentences of interest (RMC, whatever) instead of the default multiple sentences (RMC, GGA, GGV, etc).

Below is a portion of the code from some testing I did with a 28X2. The test protoboard could be powered from a vehicle (how else do you test a GPS' ability to track at speed?) and the output was formatted for a 20x4 LCD.

Code:
#picaxe 28x2

'LCD is on B.7

setfreq m16	

hsersetup B4800_8, 0

main:

hserin [1100, hfail], 0, 64, ("$")		'get GPS message into scratchpad
'goes to hfail when no message in 1.1 seconds

ptr = 2				'point to 3rd character received (0,1,2)
b3 = @ptr			'put character in b3
if b3 <> "R" then		'not an RMC message
	goto main					'back to top
endif

ptr = 17			'18th character
b3 = @ptr
if b3 <> "A" then		'"A" is a valid fix
	serout B.7, t9600, (" No Fix  ")
	goto main
endif

ptr = 55					'check for spacing
Dirspace = @ptr
if Dirspace = "," then	'nnn.nn direction
	ptr = 56
else
  ptr = 55				'nn.nn direction
endif
serout B.7, t9600, (@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc)

serout B.7, t9600, ("  Lat:")
ptr = 19
serout B.7, t9600, (@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc)
ptr = 29
serout B.7, t9600, (@ptr)

serout B.7, t9600, ("      Lon:")
ptr = 31
serout B.7, t9600, (@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc)
ptr = 42
serout B.7, t9600, (@ptr)

serout B.7, t9600, ("     Spd:")
ptr = 44
serout B.7, t9600, (@ptrinc,@ptrinc,@ptrinc,@ptrinc)

serout B.7, t9600, (" Dir:")
ptr = 49
serout B.7, t9600, (@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc)
if Dirspace = "," then
	serout B.7, t9600, (@ptrinc)
end if

goto main


hfail:
ptr = 2
b3 = @ptr
if b3 = "R" then		'have RMC but an error
	serout B.7, t9600, (".")
endif

goto main
The above code was copied, pasted, and edited twice to trim out the extraneous bits and then get it to the forum. Hopefully I didn't lose any useful bits or introduce any typos along the way.

John
 

papaof2

Senior Member
The 08M2 doesn't have the scratchpad of the bigger chips; it only has a two byte buffer. You need an X2 chip to use the code I posted - the 20X2 is the smallest of those.

See the HSERIN pages of Manual 2.

John
 

Robin Lovelock

Senior Member
Hi Folks. Could what I need be as simple as this:

instead of SERIN 3,N4800_8,("$GPRMC,"),b0,b0,b0,b0,b0,b0,b0,b1 'thanks Eclectic :)

I use something like this (not tried yet):
SERIN 3,N4800_8,("$GPRMC,"),1,2,3,4,5,6,7,8
b1 = peek 8

So I just use a SERIN with enough memory locations for the who $GPRMC sentence,
then do a loop, using peek, to count commas and then extract what I need.

Maybe, if I want to use b1,b2,b3 etc I'd start higher up in memory. e.g. 31,32,33,etc.

Could it really be as simple as that ?
Robin
www.gpss.co.uk/autop.htm
 

eclectic

Moderator
@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
 

Robin Lovelock

Senior Member
Brilliant Eclectic ! :) I've just ordered and payed for a 5-pack of 08M2. 60 off seemed a bit over the top :)
Your magic words were "drop-in" and I really appreciate your time spent in checking out Hippy's code - and yours too.
Hopefully, if Tech-Supplies are as fast as they normally are, I'll have those faster chips next Tuesday or Wednesday.
I can pick-up on this little job then. It definitely looks promising, what might be done very simply.
I've even been thinking - not TOO seriously - of putting an auto-pilot into one of those bottles :)
Robin
www.gpss.co.uk/autop.htm - robot boat, www.gpss.co.uk/bbcbot.htm - bottles, and www.gpss.co.uk/tam.htm - All the daft hobby projects :)
 
Top