Go to Post "It is a guaranteed fact that at least one rookie team will name their robot 'Chuck Norris'." - Tim Arnold [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #7   Spotlight this post!  
Unread 09-05-2011, 17:39
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Wait(); function

Here's some simple timer code that you can apply to this situation as well.

Code:
Timer* t;
bool running = false;
bool driveState = false;
...
// In constructor
t = new Timer();
t->Reset();
...
// In periodic function
int motorSpeed = 0.0;
bool triggerPressed = Thirdstick.GetTrigger();

// When the trigger is pressed, the desired behavior is
// 1. Run the motor forward at half speed for 1 second.
// 2. After one second has passed, turn the motor off
// 3. When another second has passed, return to #1
if(triggerPressed == true)
{
    if(running == false)
    {
        // We aren't running yet.  Start the timer and set the flag
        t->Start();
        running = true;
        driveState = true;
    }

    if(t->HasPeriodPassed(1.0))
    {
        // The one second timer has passed.  Change the drive state
        driveState = !driveState;
        // Reset the timer
        t->Reset();
    }

    // Select a motor speed based on the drive state
    if(driveState == true)
    {
        motorSpeed = 0.5;    
    }
    else
    {
        motorSpeed = 0.0;
    }
}
else
{
    // The trigger is not pressed.  

    // Stop it and reset it
    t->Stop();
    t->Reset();

    // Clear the global variables so that they're ready to
    // go when the button is pressed again
    running = false;
    driveState = false;
}

// Set the motor output
motor->Set(motorSpeed);
Reply With Quote
 


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


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

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