Thread: Autonomous code
View Single Post
  #4   Spotlight this post!  
Unread 14-01-2003, 09:26
Brian_Lim's Avatar
Brian_Lim Brian_Lim is offline
Registered User
#0907 (EY Cybernetics)
 
Join Date: Jan 2002
Location: Toronto
Posts: 16
Brian_Lim is an unknown quantity at this point
Send a message via ICQ to Brian_Lim Send a message via Yahoo to Brian_Lim
GOING FORWARD THEN BACKWARD

Well lets see, how can you go forward and then backward

Well try to find these three lines of code

MainLoop :
'(there is code between here)

Serout USERCPU, OUTBAUD, [255,255,p1_y,relayA,p2_y,relayB,p3_y,p4_y,p1_x,p2_ x,p3_x,p4_x,p1_wheel,p2_wheel,p3_wheel,p4_wheel]

'(there is code between here)
Goto MainLoop :

Well the way it works is that every 26 miliseconds or so, the program goes through the loop and sends output through the serout command. You can't use a for loop -- it would stay inside the for loop and never get to the serout command. What you want is a counter variable to keep track of how long the robot goes forward and backwards.

For example :

'=== DECLARE VARIABLES (out of main loop)
state var byte
state = 0
counter var byte
counter = 0

'======
' PUT THIS AFTER MainLoop, before SEROUT command
if NOT (auton_mode = 1 and state = 0) then skip1
state = 1
counter = 0
p1_y = 254
skip1:

counter = counter + 1

if NOT (state = 1 and counter = 50) then skip2
state = 2
p1_y = 0
counter = 0
skip2:

if NOT (state = 2 and counter = 50) then skip3
state = 3
p1_y = 127
skip3:
' =========


You could easily alter this for tank-steering/other purposes

You notced I use the NOT and brackets, that's how I get into making the if statement a true if statement... it normally goes to the label, but if I put a NOT, it reverses, going to the label if the opposite is true... neat eh?

I'm going to be posting our team's autonomous code soon. The problem I heard from another post is that since the battery voltage changes, motor speed changes, so using an internal counter is not that reliable... but I'm not that convinced that can happen, how much voltage drop is going to happen in 2 minutes?

Hope this helps

907
Brian Lim
__________________
907 is back and we won't go quietly...
brianeyci@hotmail.com
brianeyci@yahoo.ca
ICQ #:147900708