Go to Post So take it all with a grain of salt, form your own opinions, lead by example, act responsibly, be graciously professional, and everything will be ok. - LauraN [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

 
Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1   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
  #2   Spotlight this post!  
Unread 09-05-2011, 18:44
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: Wait(); function

ok thanks guys i finally got it!, I did a test where I ran the motor for 10 seconds while driving with the timer() class and it worked!
Reply With Quote
Reply


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 13:22.

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