Go to Post We did the best job we could out there, and unfortunatly we have human limits.. The refs don't catch every penalty, inspectors don't catch every issue, and this year the score keepers won't catch every single ball. - nobrakes8 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-01-2003, 03:41
PBoss PBoss is offline
Registered User
#1212
 
Join Date: Jan 2003
Location: Nowhere
Posts: 9
PBoss is an unknown quantity at this point
Autonomous code

Hi,
I was just trying to make my robot controller run forward for some time, and then backward. I have tried so hard but the thing acts so wierd.
I started with the following code, before the serout statement:
count VAR byte
FOR count=1 TO 100
p1_y=150
debug ? count
NEXT
I can see the counter going from 1 to 100 and repeating infinitely in the debug screen, but the p1_y doesn't go to 150, and the operator interface says BASIC ERROR

I'm a newbie, so please tell me what is wrong with this code, and help me write code for making the robot just move forward for some time, and then backwards for some time
THANKS
  #2   Spotlight this post!  
Unread 14-01-2003, 08:01
Lloyd Burns Lloyd Burns is offline
Registered User
FRC #1246 (Agincourt Robotics)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Toronto
Posts: 292
Lloyd Burns is an unknown quantity at this point
The RC program must loop through the "Do ... Loop" about once every 40 ms. It may be looosing sync with the OI with the time you are wasting, because, for each packet-loop, you're counting to 150, and for each count value you're sending a debug message and re-setting p1_y to a value without leaving your "count-loop". For each packet-loop. you're also doing the processing of the "Do ... Loop".

Now, the OI sends a new buch of values to the Serin line every few ms. each with a (no pun inteded) serial number, called a packet number which the default program ignores.

If you allow the RC to read packet_num (uncomment the declaration of packet_num near the end of declarations, near the start of the program, set c_packet_num CON 1 (changed from 0), and put packet_num in the correct place in the serin line) then you can store the packet number in a variable like "start_packet_num", and set p1_y to your value until you have gone 150 loops.

if auton_mode = 0 then fugeddabahtit

if packet_num = 0 then pack_count_zero = pack_count_zero + 1
'you have to declare the variables like pack_count_zero and temp (seen below)

if packet_num < start_packet_no then it_overflowed
temp = packet_num - start_packet_num
goto to checked_p_num

it_overflowed:
temp = (((2000 + packet_num + 256) - start_packet_num) - 2000)
'if the start_packet_num is more than 105, then in 150 loops it will roll over to a numer smaller than that. this cures the problem for loop counts of less than 256

checked_p_num:
if temp < 151 then p1_y = (your value)

fugeddabahtit:

BTW, 150 counts is only a few seconds in the above. I'm sure someone will call me a doddering old fool or worse for not remembering whether you get an update 25 or 40 times per second. A quick perusal of the 2003 OI manual yields no info.
  #3   Spotlight this post!  
Unread 14-01-2003, 08:09
Jeremy_Mc's Avatar
Jeremy_Mc Jeremy_Mc is offline
GitHubber
no team
Team Role: Mentor
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Orlando, FL
Posts: 496
Jeremy_Mc will become famous soon enoughJeremy_Mc will become famous soon enough
don't you need a serout?

*jeremy
__________________
GitHub - Collaborate on code, documentation, etc. - http://github.com
  #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
  #5   Spotlight this post!  
Unread 14-01-2003, 09:50
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
replace this part if you want it so it starts when you press a joystick button.

if NOT (p1_sw_top = 1 and state = 0) then skip1
state = 1
counter = 0
p1_y = 254
skip1:
__________________
907 is back and we won't go quietly...
brianeyci@hotmail.com
brianeyci@yahoo.ca
ICQ #:147900708
  #6   Spotlight this post!  
Unread 14-01-2003, 14:06
frumious frumious is offline
Registered User
#0847
 
Join Date: Jan 2003
Location: Philomath, Oregon
Posts: 10
frumious is an unknown quantity at this point
Send a message via ICQ to frumious Send a message via AIM to frumious Send a message via Yahoo to frumious
or, if you want something simpler, using the 2.5 code:

counter VAR WORD
counter = 0

inside the do...loop:

if counter++ > 500 then 'arbitrary time value
p1_x = 254
else
p1_x = 0
endif

should go forward for 13000 milliseconds, then go backwards.
change the 500 value up/down to have longer/shorter, it should incriment once every 26 ms (based on speeds of the default code)

Tyson
  #7   Spotlight this post!  
Unread 14-01-2003, 14:50
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Quote:
Originally posted by frumious

if counter++ > 500 then 'arbitrary time value
p1_x = 254
else
p1_x = 0
endif
Yeah, that will work as long as you ditch the ++ part. Doing a little C recently?


Anyway, dead-reckoning with the 2.5 syntax begs you to use the SELECT:
Code:
counter var word
counter=0

do
serin ....

IF auton_mode = 1 then
  SELECT counter
    CASE 0 to 100
      PWM1=254
      PWM2=254
      counter=counter+1
    CASE 101 to 200
      PWM1=254 
      PWM2=0
      counter=counter+1
    CASE else
      PWM1=127
      PWM2=127
   ENDSELECT
ELSE 
   'regular code goes here
ENDIF

serout...
LOOP
This code will go forward for approx. 2.6 seconds, then turn for another 2.6. To add new steps, just add another CASE. After it's done, it just stops and no longer incremements the counter. If you put the counter incrementer outside the SELECT, it will loop back to 0 after approx. 28 minutes. This may be OK, it may not.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #8   Spotlight this post!  
Unread 14-01-2003, 15:29
frumious frumious is offline
Registered User
#0847
 
Join Date: Jan 2003
Location: Philomath, Oregon
Posts: 10
frumious is an unknown quantity at this point
Send a message via ICQ to frumious Send a message via AIM to frumious Send a message via Yahoo to frumious
erp, yeah, i didn't notice i put the ++ in there way too much c/c++ for me (:

Tyson
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
autonomous mode problem on field Chris_C Programming 17 26-03-2003 19:11
Autonomous Code From Experience EbonySeraphim Programming 7 14-03-2003 21:56
Autonomous code tutorial miketwalker Programming 2 23-02-2003 12:28
Overcomplicated Autonomous Code EbonySeraphim Programming 33 20-02-2003 21:53
Autonomous Code Adrian Wong Robotics Education and Curriculum 1 18-11-2002 22:34


All times are GMT -5. The time now is 13:05.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi