pseudo code for guidance on 14m

tater1337

Member
i've been searching the posts and am cobbling up a program that probably has been done already. please note that I dont have all the hardware ready yet, so I havent tested to see if it'll work.

I just want to see if I am on the right track here. my plan is for this program to control a parafoil type parachute to direct it towards a specific landing area. I dont have the GPS yet, so I stole some code from the forums and tried to suss it out correctly. then I saw the limitations on variables, so I used POKEs and PEEKs.

still need to work out a compass section of the code, but the rest should work if I understand it correctly. on the other hand, i might have my directions reversed

Code:
#picaxe 14m

poke 80,4,4,1,8,1,2,7,2  				'set target lat= 44°18'12.72"N
poke 90,9,0,4,2,5,8,9,3  				'set target long= 90°42'58.93"W

serin 1,t9600_8,("N"),b0,b1,b2,b3,b4,b5,b6  	'read latitude from gps
poke 100,b0,b1,b2,b3,b4,b5,b6 			'store latitude

serin 1,t9600_8,("W"),b0,b1,b2,b3,b4,b5,b6  	'read longitude from gps
poke 110,b0,b1,b2,b3,b4,b5,b6  			'store longitude

b12=80
do 								'test loop for latitude
 b12=b13+20
 peek b13,b0						'get next target character
 peek b12,b1						'set next position character
  if b0>b1 then						'compare target to position, if south
   sertxd("go north")					'set to go north
   exit							'exit loop
  elseif b0<b1 then					'compare target to position, if north
   sertxd("go south")					'go south
   exit							'exit loop
  endif							'everything matched!
 b13=b13+1
loop until b13=88						'go on to nest significant character

b12=90
do 								'test loop for longitude
 b12=b13+20
 peek b13,b0						'get next target character
 peek b12,b1						'set next position character
  if b0>b1 then						'compare target to position, if south
   sertxd("go east")					'set to go north
   exit							'exit loop
  elseif b0<b1 then					'compare target to position, if north
   sertxd("go west")					'go south
   exit							'exit loop
  endif							'everything matched!
 b13=b13+1
loop until b13=88						'go on to nest significant character

'heading use compass to reallize which way is forward
#error "code not finished"
'output servos to steer

servo 1, 225						'turn left
wait 2							'pause NOTE turn less than 90 degrees
servo 1, 75							'straighten out



servo 1, 225						'turn right
wait 2							'pause NOTE turn less than 90 degrees
servo 1, 75							'straighten out
 

hippy

Ex-Staff (retired)
You can use the Programming Editor to compile the code as you develop and also use the Simulator to test it.

It seems you have three bytes of program memory left so may need to start optimising, scaling back ambitions or moving to a different PICAXE.
 

tater1337

Member
You can use the Programming Editor to compile the code as you develop and also use the Simulator to test it.

It seems you have three bytes of program memory left so may need to start optimising, scaling back ambitions or moving to a different PICAXE.
yeah, i just wanted to make sure i was on the right track.

I still have more code to add, so I'll have to cut it down. might be able to take the long/lat loops and make them one loop. same with servo steering.

i would have done so to begin with, but my brain wouldnt ba able to follow it to begin with, but now I see places i can eliminate duplication.
 

hippy

Ex-Staff (retired)
i just wanted to make sure i was on the right track

Hard to say without knowing what you intend to do in total. Presumably you'll need to take N and W position, compare with a reference, and see if you need to turn left or right. That's going to likely involve some trigonometry.

You can probably save some code with a loss of accuracy using ...

SerIn 1, T9600_8, ("N"), #w0
SerIn 1, T9600_8, ("W"), #w1

And I'm not sure what "the limitations on variables" are, but I would recommend not going to Peek or Poke unless you have to.
 

MartinM57

Moderator
b13 usage is weird - but if you were to use a suitable SYMBOL for it, you (and us) might be able to understand. Are you really relying on it being 0 at startup or have you missed an initialisation?

Why a 14M when you are already close to too much code? Suggets you spend another GBP2.50 or so and get yourself an X2 variant...b0 to ~b55 etc etc
 

vttom

Senior Member
Your "do" loops can be optimized if you make them "for ... next" loops.

I don't think "exit" will work inside a "for" loop. If not, you can use a goto instead.

Also, there is an error. You're referencing b13 before you set it.

One more thing... Your "go north", "go south" etc. strings take up quite a bit of storage. If they're just there for debug, shorten them to 1-2 characters.
 

tater1337

Member
You can use the Programming Editor to compile the code as you develop and also use the Simulator to test it.

It seems you have three bytes of program memory left so may need to start optimising, scaling back ambitions or moving to a different PICAXE.
ok, question. most posts about reading GPS's assume you already have one. I am still shopping for one. could you(or anyone) tell me what I should be putting in for the serin when the simulator asks for input?

hippy said:
Presumably you'll need to take N and W position, compare with a reference, and see if you need to turn left or right. That's going to likely involve some trigonometry.
ok, you got the idea. no trig needed as it'll turn an unknown ammount, but the next loop will correct if turned too far (and constantly over correct when close)

hippy said:
You can probably save some code with a loss of accuracy using ...

SerIn 1, T9600_8, ("N"), #w0
SerIn 1, T9600_8, ("W"), #w1
can this work? lots of posts on geting info from GPS's but little code posted that makes sense to someone new at it. how much accuracy do I lose? in other words, how big a landing site do i need? big is ok, but i'd like to know how big (preferably under a mile)
also, the method I use could concieveably be used anywhere on the hemisphere, I probably dont need that.....yet.
hippy said:
And I'm not sure what "the limitations on variables" are, but I would recommend not going to Peek or Poke unless you have to.
14m only has b0 to b14, right? or did i understand the documentation wrong
after reading the gps, how many variables woud I have left? if someone has posted code that does it better than this, please point me to it, I'll gladly use it.
martinm57 said:
b13 usage is weird - but if you were to use a suitable SYMBOL for it, you (and us) might be able to understand. Are you really relying on it being 0 at startup or have you missed an initialisation?
first, thanks for finding the bug. second I hope the remarks would tell what was going on. new gode now has symbols, doubt it helps
vttom said:
Your "do" loops can be optimized if you make them "for ... next" loops.

I don't think "exit" will work inside a "for" loop. If not, you can use a goto instead.

Also, there is an error. You're referencing b13 before you set it.

One more thing... Your "go north", "go south" etc. strings take up quite a bit of storage. If they're just there for debug, shorten them to 1-2 characters.
yep fixed the B13 glitch, changed the strings to course variables and hopefully implemented them correctly.

also, manual 2 says that exits will work in for next loops.

so far got a spare 16 bytes free, ordered a 18x kit that may or may not get used, depending if I can shoehorn it all in.

oh, here's the new code

Code:
#picaxe 14m
'recovery guidance
symbol targetdatstart=b11
symbol targetdat=b12
symbol positiondat=b13
symbol goaldirection=b3
symbol compassheading=b2
symbol turnhere=b4
symbol characterloop=b5

'load target data
poke 80,4,4,1,8,1,2,7,2  				'set target lat= 44°18'12.72"N
poke 90,9,0,4,2,5,8,9,3  				'set target long= 90°42'58.93"W
'wait for start swithch(maybe just power on?)

main:
serin 1,t9600_8,("N"),b0,b1,b2,b3,b4,b5,b6  	'read latitude from gps
poke 100,b0,b1,b2,b3,b4,b5,b6 			'store latitude

serin 1,t9600_8,("W"),b0,b1,b2,b3,b4,b5,b6  	'read longitude from gps
poke 110,b0,b1,b2,b3,b4,b5,b6  			'store longitude

targetdatstart=80							'test loop for latitude
gosub comparetotarget
targetdatstart=90
gosub comparetotarget
'heading use compass to reallize which way is forward

compassheading=36						'assume facing north - stub code, replace with serin from compass
turnhere=36+compassheading-goaldirection		'funky math to avoid negative result
if turnhere>36 then 					
servo 1, 225						'turn right
wait 2							'pause NOTE turn less than 90 degrees
servo 1, 75							'straighten out
elseif turnhere<36 then
servo 1, 225						'turn left
wait 2							'pause NOTE turn less than 90 degrees
servo 1, 75							'straighten out
endif
goto main

comparetotarget:
for characterloop=0 to 7 							
 targetdat=targetdatstart+characterloop
 positiondat=targetdat+20
 peek targetdat,b0					'get next target character
 peek positiondat,b1					'set next position character
  if b0>b1 AND positiondat<90 then			'compare target to position, if south
   goaldirection=36					'set to go north
   exit							'exit loop
  elseif b0<b1 and positiondat<90 then		'compare target to position, if north
   goaldirection=18					'go south
   exit							'exit loop
  elseif b0>b1 and positiondat>=90 then		'compare target to position, if west
   goaldirection=09					'set to go east
   exit							'exit loop
  elseif b0<b1 and positiondat>=90 then		'compare target to position, if east
   goaldirection=27					'go west
   exit							'exit loop
  endif							'everything matched!
next								'go on to next significant character
return
you do realize there is more in brackets on this post than content? wow
 

tater1337

Member
i just wanted to make sure i was on the right track

You can probably save some code with a loss of accuracy using ...

SerIn 1, T9600_8, ("N"), #w0
SerIn 1, T9600_8, ("W"), #w1
Hippy, I am stealing this, but it is still a tad big for a target area, can I do this?

Code:
serin 1,t9600_8,("GPGLL,"),w2,w4,w4  	'read latitude from gps
serin 1,t9600_8,("N,"),w3,w5,w5  	'read longitude from gps
and use w4 and w5 for fine tuning?

also, i used w4 &w5 twice to skip the ".". did i do this right? or should I use a scrap bx instead?
 

hippy

Ex-Staff (retired)
Hippy, I am stealing this ... can I do this?
No idea I'm afraid as I haven't done any GPS. It looks right, so in that sense, yes you can. Variables used twice will be overwritten when they are used again later so it's a good trick to throwing away unwanted data.
 

eclectic

Moderator
@tater.

I think you need byte variables.
Please see Manual2, p. 169.
“- Variable(s) receive the result(s) (0-255). Optional #’s are for inputting ASCII
decimal numbers into variables, rather than raw characters.”

For some unknown reason, I can't receive the GPGLL values, so
I've just tried a simple GGA test, to read the current time.
(My receiver outputs at t4800)

Code:
#picaxe 14M
setfreq m8
; tested at ~ 19:02 BST  / 18.02 UTC
main:
;Using word variables
serin 1,t4800_8,("GPGGA,"),w0,w1,w2
sertxd (w0,w1,w2,cr,lf)

;Using byte variables
serin 1,t4800_8,("GPGGA,"),b0,b1,b2,b3,b4,b5
sertxd(b0,b1,b2,b3,b4,b5,cr,lf)

goto main
How long until you can get a GPS receiver,
so that you can do some real tests?

e
 

Attachments

Top