Go to Post After talking with the students on these teams I could see the light in their eyes. These were their robots! Inspired? That would be a definate YES! - Steve W [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-02-2010, 17:40
davidalln's Avatar
davidalln davidalln is offline
World's Worst Coder
AKA: David Allen
FRC #2415 (The Westminster Wiredcats)
Team Role: Programmer
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Atlanta, GA
Posts: 108
davidalln is on a distinguished road
Send a message via AIM to davidalln
Running a Relay for a Set Time

I need to run a relay for a set amount of time while still being able to run the rest of the robot's functions. When I use the tried and true Wait() function from the Watchdog, it (as expected) halts the rest of robot operations. I have looked into separating out this function in a Task/Semaphore formation, but I'm not sure if it will solve this or exactly where to start with this (I have looked through this tutorial, but I'm still not sure where to start). What is the best way to run a function for a set amount of time while still running drive/other schmazz?
__________________
SANTOSH ANDREW DECKER RICK WYNNIE SEAN DEREK MATT
(alamo (semis), p'tree (CHAMPS!), nc (CHAMPS!), newton (quarters))


Best four years of my life. Thanks to everyone who made it happen.
Reply With Quote
  #2   Spotlight this post!  
Unread 22-02-2010, 00:02
mandrews281 mandrews281 is offline
Registered User
FRC #0281
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Greenville SC
Posts: 83
mandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to behold
Re: Running a Relay for a Set Time

One of our programmers got it with a separate task, but what I'd suggest is starting a Timer, polling it in your loop, and as soon as the timer exceeds some length of time, turn the relay off.
__________________
Michael Andrews
Team #281 Programming Mentor
Reply With Quote
  #3   Spotlight this post!  
Unread 22-02-2010, 08:48
SuperBK's Avatar
SuperBK SuperBK is offline
Registered User
AKA: BrianK
FRC #1225 (Amperage Robotics)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Henersonville, NC
Posts: 358
SuperBK is just really niceSuperBK is just really niceSuperBK is just really niceSuperBK is just really nice
Re: Running a Relay for a Set Time

This is a C++ example. Its a state machine that starts with a trigger on a joystick. It even includes the 2 second lockout before the kicker can be fired again.

Code:
enum Kicker_State {
Kicker_off, 
Kicker_going_out, 
Kicker_out, 
Kicker_coming_back, 
Kicker_reload};

Timer kicker_timer;
Kicker_State kicker_state = Kicker_off;

while (IsOperatorControl())
{
    GetWatchdog().Feed();
    myRobot.TankDrive(left_stick, right_stick);		// drive with two sticks
    Wait(0.005);				// wait for a motor update time
    
    // kicker out-in actuator
    switch (kicker_state)
    {
    case Kicker_off:
        // see if go button is pressed
        if (right_stick.GetRawButton(KICKER_BUTTON))
        {
            kicker->Set(Relay::kForward);	// turn on
            kicker_timer.Reset();
            kicker_timer.Start();
            kicker_state = Kicker_going_out;
        }
        break;
    case Kicker_going_out:
        // see if enough time elasped
        if (kicker_timer.Get() >= .25)
        {
            kicker->Set(Relay::kOff);
            kicker_timer.Reset();
            kicker_state = Kicker_out;
        }
        break;
    case Kicker_out:
        // see if enough time elasped
        if (kicker_timer.Get() >= .5)
        {
            kicker->Set(Relay::kReverse);
            kicker_timer.Reset();
            kicker_state = Kicker_coming_back;
        }
        break;
    case Kicker_coming_back:
        // see if enough time elasped
        if (kicker_timer.Get() >= .25)
        {
            kicker->Set(Relay::kOff);
            kicker_timer.Reset();
            kicker_state = Kicker_reload;
        }
        break;
    case Kicker_reload:
        // see if enough time elasped
        if (kicker_timer.Get() >= 2.0)
        {
            kicker_state = Kicker_off;
            kicker_timer.Stop();
        }
        break;
    }
    
}	// end operator control loop
__________________
Brian K
Team 1225 Robotics Mentor
Reply With Quote
  #4   Spotlight this post!  
Unread 22-02-2010, 09:51
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Running a Relay for a Set Time

I'd recommend using the Notifier class. It automatically calls a callback function after a given amount of time, and works on an interrupt level so it doens't block other code until it runs.
__________________
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP!!!EMERGENCY!!!RUNNING OUT OF TIME!!! furiousgeorge Programming 7 12-02-2009 14:05
2791 Bot running around for the first time yodameister General Forum 5 08-02-2009 04:30
Set Up Time At Regionals fatjoe3833 Regional Competitions 13 25-03-2006 00:04
Running a motor for a set time in auton Morgoth Programming 5 11-03-2003 13:59
Time is running out... archiver 2001 0 24-06-2002 00:04


All times are GMT -5. The time now is 03: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