Go to Post "PWMed" - Sam N. [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 17-02-2007, 13:34
Dave K.'s Avatar
Dave K. Dave K. is offline
Engineer/Mentor
FRC #0930
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: WI
Posts: 91
Dave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to behold
Re: Timers and Such

Quote:
Originally Posted by Inverted View Post
I've forgotten most of the C that I learned a few years ago, and my mind has been clouded with the InteractiveC commands that we use in my robotics class (stupid LEGO RCX). I know about incrementing timers and doing, for example:

Code:
 timer1++;
if (timer1 < 200){
blah blah;
}
My question is does a C command exist that is the equivalent of InteractiveC's "sleep()" function? We want to have a dead reckoning backup and it would be a lot easier for me to train newbies if we could do the following instead of the former, since they already know how to write those type of programs.

Code:
pwm13 = pwm14 = 167;
pwm14 = pwm15 = 87;
sleep(2.0); //drive forward for 2 seconds
pwm07 = 205;
sleep(.5); //raise arm
blah blah
Is that possible or am I just out of luck with doing things the easy way?

You have full control over the code that gets installed in the user processor. The good news is that you can do pretty much whatever you want. The bad news is, you can do pretty much whatever you want.

It appears that you are probably wanting to do this for autonomous mode, but the same thing will work for both.

Structure your code so that it is state driven and always exits. Whether in autonomous or teleoperated, setup your statemachine code to run every SPIData receive event (~38Hz).

You can then setup timer's like this:

Code:
    if (TimerDrive) {  // if timer running
      if (!(--TimerDrive)) {  // decrement one tick, and when it hits zero
         // do whatever you need to do to advance to the next step in your state machine
     }

   }

   if (TimerSomethingElse) {  // if timer running
     if (!(TimerSomethingElse)) {  // decrement one tick, and when it hits zero
        // do something else
    }
  }

If you really do want to impliment a sleep function, and if this is for autonomous, keep in mind how the default autonomous mode software is structured, and make sure you'll exit at the proper time... in other words, you'll probably need to sprinkle tests at each step along the way.

That said, to impliment a sleep function, I'd suggest setting up one of the unused hardware timers to interrupt and reload at rate equal to whatever you need your timer resolution to be, say 100ms.

In the interrupt service routine, in addition to servicing the interrupt, do this:

Code:
   if (TimerSleep) {
     --TimerSleep;
   }

Then your sleep function can be setup like this:

Code:
volatile unsigned char TimerSleep;

void Sleep(unsigned char timer) {

   TimerSleep = timer;

   while (TimerSleep);

}

If you need more than 8 bits of dynamic range for your timer and move up to a 16 or 32 bit value, then you should disable interrupts, move the TimerSleep variable into a local temp, re-enable interrupts, test the local variable, and loop until it times out.

The protection is necessary because the interrupt routine would update one byte of the variable at a time, and it creates a critical region for your foreground test.
__________________
--Dave
 


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
Descriptions and such in image threads? Billfred CD Forum Support 5 06-06-2005 10:01
Inventor skins and such Pat Roche Inventor 0 18-05-2004 22:46
Careers related to Animation and such.. Ryan Dognaux Career 8 04-02-2003 21:44
Careers related to Animation and such.. Ryan Dognaux Computer Graphics 0 03-02-2003 15:54
Thank You's and such Chris Hibner Thanks and/or Congrats 0 01-05-2002 08:54


All times are GMT -5. The time now is 14:23.

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