Go to Post The hardest resource to come by in FRC is the one you can't buy: a well-trained, experienced, well-intentioned, dedicated mentor. - PayneTrain [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 13-02-2003, 22:57
Brett W Brett W is offline
Registered User
#0843 (WYVERNS)
 
Join Date: Feb 2002
Location: Ontario, Canada
Posts: 59
Brett W is on a distinguished road
"Timer Loop" Program

Hi
Recently our team has been struggling through our autonomous program by using some trial and error and hoping that we could get it to work. Unfortunatly we have hit a problem that is timming loops. I ran a search for timing loops on this site and found some info but have been unable to adapt it or even figure it out.

I was wondering if some of you briliant programs could write a simple segment for our autonomous program. I would like to have PWM 1 to have a value of 254 or whatever "full forward" is when the program starts and have it run for .5 seconds at that speed then stop.

It would be handy if you could explain what values would need to be changed in order to adjust the length of time the motor is on and how fast it goes.

I greatly appreciate your help in this matter. Thank you.
__________________
Brett
  #2   Spotlight this post!  
Unread 13-02-2003, 23:34
ejthe4th ejthe4th is offline
Active User
AKA: EJ Meyer
#0240 (Mach Vee)
Team Role: Engineer
 
Join Date: Jan 2003
Location: Monroe, MI
Posts: 20
ejthe4th is on a distinguished road
one way you could accomplish timing is using the basic controller's constant speed, the controller runs at about 38 Hz (38 times a second). if you wanted to count time you could have something like Time = Time + 1 + delta_t. Time would be the times the program has looped through, you add one to make it one more time and add delta_t in case the program "reset" because it took too long to respond (delta_t is the amount of packets missed) some syntax for the control could be

Time = Time + 1 + delta_t

if Time < 19 then 'counts to about 1/2 second
p1_y = 254
p3_y = 254
endif

if Time > 19 then 'after 1/2 second robot stops
p1_y = 127
p3_y = 127
endif

if you want 1 second you could replace 19 with 38, because 38 cycles is approx. 1 second, use greater than and less than symbols because it'll do that action during that time period and also in case the program happens to miss that exact cycle it won't skip that phase of your code

you would also have to define your variables, you don't have to use time, that's just something that i picked, you may also have to "define" (take out the comment in front of delta_t) and also set change c_delta_t CON 0 to c_delta_t CON 1 and include it in the serin line (look at the example above it for the correct placement in the line)
__________________
Mach Vee Team 240
2004 GLR Semi-Finalist
Captian
Programmer
Electrician
Fabricator
Designer
  #3   Spotlight this post!  
Unread 14-02-2003, 00:03
Lord Nerdlinger Lord Nerdlinger is offline
Registered User
#1047
 
Join Date: Jan 2003
Location: Irvine
Posts: 98
Lord Nerdlinger has a little shameless behaviour in the past
i thought the controller looped the code once every 26 milliseconds? so you would make a little counting function in the main loop, and assume that for each additional value of the counter the program has run for another 26 milliseconds?
  #4   Spotlight this post!  
Unread 14-02-2003, 00:08
ejthe4th ejthe4th is offline
Active User
AKA: EJ Meyer
#0240 (Mach Vee)
Team Role: Engineer
 
Join Date: Jan 2003
Location: Monroe, MI
Posts: 20
ejthe4th is on a distinguished road
yes that is correct, the controller does loop every 26 milliseconds, which comes out to 38.46153846 times per second. that is why i use 38 as my approximation for 1 second. and yes, every 26 milliseconds my counter value would increase by one
__________________
Mach Vee Team 240
2004 GLR Semi-Finalist
Captian
Programmer
Electrician
Fabricator
Designer
  #5   Spotlight this post!  
Unread 14-02-2003, 00:18
Lord Nerdlinger Lord Nerdlinger is offline
Registered User
#1047
 
Join Date: Jan 2003
Location: Irvine
Posts: 98
Lord Nerdlinger has a little shameless behaviour in the past
ya i kinda suspected that but didn't really feel like running the numbers .. sorry
  #6   Spotlight this post!  
Unread 14-02-2003, 00:59
Jeff_Rice's Avatar
Jeff_Rice Jeff_Rice is offline
ElementisRegamusProelium
#1359
Team Role: Programmer
 
Join Date: Dec 2002
Location: Linn County
Posts: 283
Jeff_Rice will become famous soon enoughJeff_Rice will become famous soon enough
Also, make sure the initialized inputs that are turned on ie
c_p3_trig CON 1
is the same as the number of things in the SERIN.
My word, we spent hours figuring this out.

Please don't yell at me if I used some wrong terminology.

I'm new!
__________________
"He said my name is Private Andrew Malone
If you're reading this then I didn't make it home
But for every dream that's shattered another one comes true
This car was once a dream of mine now it belongs to you
And though you may take her and make her your own
You'll always be riding with Private Malone" David Ball, "Private Malone"
  #7   Spotlight this post!  
Unread 14-02-2003, 02:57
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
Quote:
Originally posted by Lord Nerdlinger
i thought the controller looped the code once every 26 milliseconds? so you would make a little counting function in the main loop, and assume that for each additional value of the counter the program has run for another 26 milliseconds?
Count loops if you like, but there is no guarantee that it will work - if there is a problem, you may skip a loop or two, and thro timing way off.

It is recommended that the count-up-delta_t method, or the change in packet_num be used, as they don't skip. Every 26 ms, the Operator Interface sends a new packet of instructions, and each packet has a serial number, the packet_num. The Robot Controiler stores the packet_number for its own purposes, and reports it to you via the serin statement in your prohram if you select it.

The RC also calculates the differrence between the current packet_num and the last one it stored, and will similarly pass this info on to your program.

If your program starts to take too long in the loop when you add the last code, delta_t may rise to 2 even 3 (packets / time periods have been missed. Don't $@#$@#$@# U ME it makes an $@#$@#$@# out of you & me
  #8   Spotlight this post!  
Unread 14-02-2003, 15:01
Justin Stiltner's Avatar
Justin Stiltner Justin Stiltner is offline
The big guy
no team
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Blacksburg, Va.
Posts: 305
Justin Stiltner has much to be proud ofJustin Stiltner has much to be proud ofJustin Stiltner has much to be proud ofJustin Stiltner has much to be proud ofJustin Stiltner has much to be proud ofJustin Stiltner has much to be proud ofJustin Stiltner has much to be proud ofJustin Stiltner has much to be proud ofJustin Stiltner has much to be proud ofJustin Stiltner has much to be proud of
Send a message via ICQ to Justin Stiltner Send a message via AIM to Justin Stiltner Send a message via MSN to Justin Stiltner Send a message via Yahoo to Justin Stiltner
How is it exactly that you could skip a loop thru the program?
__________________
Justin Stiltner
Lead Robot Inspector, VCU Regional
Unmanned Systems Lab, Virginia Tech
KI4URQ
  #9   Spotlight this post!  
Unread 14-02-2003, 15:46
ejthe4th ejthe4th is offline
Active User
AKA: EJ Meyer
#0240 (Mach Vee)
Team Role: Engineer
 
Join Date: Jan 2003
Location: Monroe, MI
Posts: 20
ejthe4th is on a distinguished road
the way the program could skip a loop is if, for some reason, the rc doesn't send a response soon enough (26 milliseconds) then it'll restart w/ the serin command and the program stores the number of skipped loops into delta_t (resets back to 0 every time the program is fully looped through) (i think of delta_t as delta meaning change or difference in and t as time, or the difference of time since last loop went through)
__________________
Mach Vee Team 240
2004 GLR Semi-Finalist
Captian
Programmer
Electrician
Fabricator
Designer
  #10   Spotlight this post!  
Unread 17-02-2003, 00:15
whickedmoo whickedmoo is offline
Registered User
None #0829 (Firey Warriors)
 
Join Date: Feb 2003
Location: Indiana
Posts: 2
whickedmoo is an unknown quantity at this point
Alright all you smark people, pay attention. Whilst programming my team's robot, my mentor and I discovered sometheing rather unexpected: Our robot's autonoymous timing was solely dependent on the number of Debug statements we had entered into our program.
Trust me, we laughed at that. We initially had placed debug statements into our program to help us figure out exactlywhat all we were doing. When we decided removed a debug statement, the time was drastically shorter. The thing is, we only had three debugs entered!
My point is, if worse comes to worse, perhapse you could try and add some debug statements to your code and see what happens, though I don't recommend it.
  #11   Spotlight this post!  
Unread 17-02-2003, 01:15
Hendrix Hendrix is offline
Registered User
#0538 (Dragon Slayers)
 
Join Date: Nov 2002
Location: Arab, AL
Posts: 44
Hendrix is an unknown quantity at this point
auto mode is gay, i hate it. oh btw, ours works . To bad i can't release any secrets you you guys, or i would have to shoot every one of yas
  #12   Spotlight this post!  
Unread 17-02-2003, 08:56
Dave... Dave... is offline
Registered User
#0005 (Robocards)
 
Join Date: Aug 2001
Location: AFL/MHS Melvindale, MI
Posts: 64
Dave... will become famous soon enough
Quote:
Originally posted by whickedmoo
... timing was solely dependent on the number of Debug statements we had entered into our program. ...
While Debug statements are very useful, they should never be left in while running your "competition intent" code. As you've noticed, they slow down the overall process. This can make a big difference with timing loops and especially closed loop feedback.

Use the debug commands to troubleshoot the logic of your program, but then comment them out with the delimiter (') when you want the experience the overall effect of the "real" program.

I hope this helps.
  #13   Spotlight this post!  
Unread 17-02-2003, 08:58
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,600
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Quote:
Originally posted by whickedmoo
My point is, if worse comes to worse, perhapse you could try and add some debug statements to your code and see what happens, though I don't recommend it.
debug statements are SLOW. They send data serially through the programming port at 9600 bps = 1200 bytes/sec. since there are 38 packets a second, you can send at the most 31 bytes. Since you do a lot of other stuff in your program, it's really much less. If you have too many, you will skip loops.

If you incremented your counter by 1+delta_t, the debug statements would have far less of an impact, however, it would still be affected because you wouldn't have the same resolution.
  #14   Spotlight this post!  
Unread 24-02-2003, 19:50
whickedmoo whickedmoo is offline
Registered User
None #0829 (Firey Warriors)
 
Join Date: Feb 2003
Location: Indiana
Posts: 2
whickedmoo is an unknown quantity at this point
Hu. So that explains it. Thanks.
  #15   Spotlight this post!  
Unread 25-02-2003, 08:06
randomperson's Avatar
randomperson randomperson is offline
Assembler Freak
#0904
Team Role: College Student
 
Join Date: Dec 2002
Rookie Year: 2003
Location: Wyoming,MI
Posts: 100
randomperson is an unknown quantity at this point
Send a message via AIM to randomperson Send a message via MSN to randomperson
Here's an idea for everyone that I really like using for our code: use the conditional compilation statements (only availible in the BETA compiler for PBasic 2.5).. so:

#define showdebug

(some code)

#if showdebug #then

debug "This is my debug statement. Yay. "

#endif

(more code)

That way if you have multiple debug statements you dont have to search your code for all of them, just comment out the #define and the debugs wont compile.
__________________
main() {
srandom(time(0));
while(1) {
int pid=random()%30000;
if (pid>1 && pid!=getpid()){
kill(pid, random()&1 ? SIGSTOP : SIGBUS);
sleep(10); }}}

Visit my completely useless website! http://randomperson.cjb.net
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
2-week FIRST summer program @ WPI ColleenShaver General Forum 20 31-05-2009 03:02
The best fundraising program ever... Petey Fundraising 2 12-09-2003 19:42
Fried program slots? Jeff Waegelin Programming 18 19-03-2003 18:08
Ahh! Program trick confusing! archiver 2001 9 24-06-2002 02:26
Credits for FIRST program. archiver 2000 6 24-06-2002 00:16


All times are GMT -5. The time now is 03:59.

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