Go to Post I wonder if we sang songs to Bill Miller if that would get TIMS opened sooner, like the way it worked to wring game hints out of Dave Laverly. - rsisk [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
  #5   Spotlight this post!  
Unread 12-03-2010, 02:26
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: switching turning direction using arcade drive?

You probably dont want to have any kind of nested loops in your main program loop, unless you are certain it will execute fast enough. A for loop will block the execution of the code after it, and will fire the watch dog, or worse, cause your bot to "freeze" its output values while the loop is executing.

Instead, you could use a Timer object.
Code:
class MyRobot : public IterativeRobot
{
   // Declare the timer
   Timer * kickTimer;
 
   // Then down in the constructor...
   MyRobot(void){
      // ...
      kickTimer = new Timer();
   }

   void TeleopPeriodic(void){
      if( somethingHappened ){
         kickTimer->Start();
         mySolenoid->Set(true);
      }

      if( kickTimer->Get() >= 1.0){
         mySolenoid->Set(false);
         kickTimer->Stop();
         kickTimer->Reset();
      }
}
Or you could just increment a counter every time you loop around
Code:
static unsigned int solenoidCounts = 0;
static bool kickerFired = false;

if(somethingHappened){
   solenoid->Set(true);
   kickerFired = true;
   solenoidCounts = 0;
}

if(kickerFired){
   solenoidCounts++;
   if(solenoidCounts > 1 * 40){ // 40Hz(ish)
      solenoid->Set(false);
      kickerFired = false;
      solenoidCounts = 0; // just to be safe
   }
}
It's not the prettiest thing in the world, but it gets the job done and its pretty easy to understand/implement/change.
 


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
Semi-Omni-Arcade Drive byteit101 Programming 20 24-01-2010 08:21
Normalizing motor speeds using Arcade Drive in Labview rsisk NI LabVIEW 9 28-08-2009 20:56
Programming Arcade Drive kyungjin C/C++ 4 06-04-2009 11:28
Arcade/Tank Drive Malfunction piedmont Programming 2 19-01-2009 17:37
Arcade Drive Anfony VEX 4 08-11-2006 19:46


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

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