Ok. Thanks for the help guys.
I can see what you are getting at; but this is a little more advanced for me, so maybe by giving you the full code in which the ‘drive’, ‘ldrive’ and ‘rdrive’ variables are manipulated, you can better see what the prpose of what I am trying to do is. Then maybe you can explain it a little further for me so I can replicate the PBASIC code into Arduino code…? Here’s the PBASIC code I’m trying to code into Arduino syntax:
avdo:
LOOKUP i,[rr, rl, drive],tmp
drive = tmp
i = 0 'clear history
avdone:
RETURN
wander: ' randomly wander around
IF wDur > 0 THEN wDone1
RANDOM seed ' random direction
i = seed & %111 ' mask off for 0-7 only
LOOKUP i,[fd,tl,fd,fd,fd,fd,tr,fd],wDir 'chose direction
seed = seed + i
wDur = (seed & %111111) + 20 ' mask for 64 choices of duration
wDone1:
wDur = wDur - 1 'decrement wander counter
drive = wDir 'get direction
RETURN 'completed
act: ' moves servo motors
IF aDur > 0 THEN aDec ' already doing one, got here
aDur = SACT ' times through this one
PULSOUT LEFT,ldrive * 10
PULSOUT RIGHT,rdrive * 10
aDec: ' decrement stuff
aDur = aDur - 1
aDone:
RETURN
I took that code from Justin R. Ratliff’s site, so credit for the design goes to him. I thought it looked like an excellent way to randomize my robot’s movements, so I decided to use it (under appropriate copyright terms, of course). I do understand this code to some extent; if you all do feel free to explain it to me because I am eventually going to need to ‘translate’ it into Arduino code. What I CAN see (among other things, of course; I understand enough of this code to see what it does) is that ‘ldrive’ and ‘rdrive’ are simply two separate parts of ‘drive’ (‘drive’ stores information on pulse width durations for the left and right servos).
Here’s the variable declarations and constants at the beginning of the program used for this code:
' **Servo Routines**
SACT CON 5 ' times through act routine
drive VAR Word ' wheel command combo
ldrive VAR drive.BYTE1 ' left wheel command
rdrive VAR drive.BYTE0 ' right wheel command
aDur VAR Byte ' duration of pulse left
' **Servo Drive Commands**
fd CON $6432 ' forward (left = 100 ((16*6)+4), right = 50 ((16*3)+2))
rv CON $3264 ' reverse (left = 50 ((16*3)+2), right = 100 ((16*6)+4))
st CON $4b4b ' STOP (left = 75 ((16*4)+11), right = 75 ((16*4)+11))
tr CON $644b ' turn right (left = 100 ((16*6)+4), right = 75 ((16*4)+11))
tl CON $4b32 ' turn left (left = 75 ((16*4)+11), right = 50 ((16*3)+2))
rr CON $6464 ' rotate right (left = 100 ((16*6)+4), right = 100 ((16*6)+4))
rl CON $3232 ' rotate left (left = 50 ((16*3)+2), right = 50 ((16*3)+2))
I wrote in all that crazy math to help myself understand how the values work. When all is said and done, I want to be able to understand how this works-inside and out-so I can manipulate it to my liking. Let’s just address the var.BYTE1, var.BYTE2, etc. topic for now. Thanks for the help so far.