Go to Post overly agressive play, sudden torque gains, and signs of robot acne will cause immediate suspicion, and may be used as justification for a complete tear-down inspection - dlavery [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

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 28-03-2007, 22:42
pheadxdll pheadxdll is offline
Registered User
AKA: Alex
FRC #1225 (Amperage Robotics)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: North Carolina
Posts: 168
pheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud of
Re: Timer Question

Yes, that will work.

About 38 cycles = a second so you could do something like:

int delaySeconds = 38 * sec;
int counter = 0;
MOVE_FOWARD;

if(counter < delaySeconds) {
counter++;
}else{
STOP_MOVING;
}

Remember to declare the int's at the top of the routine and good luck!

Note: You could use software timers like the one posted above, but just for simplicity, fastness, and realiblity, it won't matter if you choice either one.
__________________
Amperage Robotics Team 1225
Site under-going revamp. :/

Last edited by pheadxdll : 28-03-2007 at 22:45.
  #2   Spotlight this post!  
Unread 28-03-2007, 22:58
lightning_blast lightning_blast is offline
Registered User
FRC #1814
 
Join Date: Feb 2006
Location: Canada
Posts: 15
lightning_blast is an unknown quantity at this point
Re: Timer Question

Quote:
Originally Posted by pheadxdll View Post
Yes, that will work.

About 38 cycles = a second so you could do something like:

int delaySeconds = 38 * sec;
int counter = 0;
MOVE_FOWARD;

if(counter < delaySeconds) {
counter++;
}else{
STOP_MOVING;
}

Remember to declare the int's at the top of the routine and good luck!

Note: You could use software timers like the one posted above, but just for simplicity, fastness, and realiblity, it won't matter if you choice either one.
thanks for the suggestion, the delaySecond assignment is definately useful.
  #3   Spotlight this post!  
Unread 28-03-2007, 23:11
yoyodyne yoyodyne is offline
Registered User
AKA: Greg Smith
FRC #0116 (Epsilon Delta)
Team Role: Engineer
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Reston, VA
Posts: 61
yoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to behold
Re: Timer Question

There is a global variable named "disabled_mode" that is set true for a while after autonomous_mode is set to true and your autonomous code will start. What will happen is you will turn on PWM output for the motors but nothing will happen because the robot is disabled. The 15 sec autonomous period does not start until disabled_mode is set to false.

Check out Mark's post on this thread.

http://www.chiefdelphi.com/forums/sh... onomous_mode

"
Re: _mode flag summary??

--------------------------------------------------------------------------------

Last year we reset our autonomous whenever the robot was disabled. The drivers didn't have to remember to reset for the second practice match.

Last year the actual sequence at the SBPLI Regional was:
Disable bit set before the match started
Both disable and autonomous bits set
Then disable was turned off to start the autonomous mode
Finally the autonomous bit went off as the user_mode came on
One team had their autonomous timer ticking off while the robot was disabled at the beginning of the match, so the robot always thought it was partway or completely through the 15 seconds, before they were enabled and allowed to move."
  #4   Spotlight this post!  
Unread 28-03-2007, 23:36
lightning_blast lightning_blast is offline
Registered User
FRC #1814
 
Join Date: Feb 2006
Location: Canada
Posts: 15
lightning_blast is an unknown quantity at this point
Re: Timer Question

Quote:
Originally Posted by yoyodyne View Post
There is a global variable named "disabled_mode" that is set true for a while after autonomous_mode is set to true and your autonomous code will start. What will happen is you will turn on PWM output for the motors but nothing will happen because the robot is disabled. The 15 sec autonomous period does not start until disabled_mode is set to false.

Check out Mark's post on this thread.

http://www.chiefdelphi.com/forums/sh... onomous_mode

"
Re: _mode flag summary??

--------------------------------------------------------------------------------

Last year we reset our autonomous whenever the robot was disabled. The drivers didn't have to remember to reset for the second practice match.

Last year the actual sequence at the SBPLI Regional was:
Disable bit set before the match started
Both disable and autonomous bits set
Then disable was turned off to start the autonomous mode
Finally the autonomous bit went off as the user_mode came on
One team had their autonomous timer ticking off while the robot was disabled at the beginning of the match, so the robot always thought it was partway or completely through the 15 seconds, before they were enabled and allowed to move."
ahh sorry im new to C, and so is everybody on my team. so by writing:

if (disabled_mode)
timer = 0;

is the same as:

if (disabled_mode == true)
timer = 0;

right? thanks again .

Last edited by lightning_blast : 28-03-2007 at 23:38.
  #5   Spotlight this post!  
Unread 28-03-2007, 23:43
yoyodyne yoyodyne is offline
Registered User
AKA: Greg Smith
FRC #0116 (Epsilon Delta)
Team Role: Engineer
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Reston, VA
Posts: 61
yoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to behold
Re: Timer Question

For practical purposes, yes,

if(disabled_mode) // not disable_mode - my bad

is really the same as if(disabled_mode != 0)

If you look at ifi_default.h you will see the following defines:

#define FALSE 0
#define TRUE !FALSE

It might make more sense if the way you coded it was simply in your logic to increment timer

if(!disabled_mode) // disabled_mode == FALSE
timer += 1;
  #6   Spotlight this post!  
Unread 28-03-2007, 23:44
Stvn's Avatar
Stvn Stvn is offline
FIRST Competition Competer
AKA: Steven Rhodes
FRC #0100 (WHS/CHS - WildHats)
Team Role: Leadership
 
Join Date: Feb 2007
Rookie Year: 2004
Location: Woodside, CA
Posts: 90
Stvn is an unknown quantity at this point
Send a message via AIM to Stvn
Re: Timer Question

Quote:
Originally Posted by lightning_blast View Post
ahh sorry im new to C, and so is everybody on my team. so by writing:

if (disabled_mode)
timer = 0;

is the same as:

if (disabled_mode == true)
timer = 0;

right? thanks again .
If true = 1, then yes.
__________________
  #7   Spotlight this post!  
Unread 28-03-2007, 23:46
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Timer Question

Quote:
Originally Posted by yoyodyne View Post
There is a global variable named "disabled_mode" that is set true for a while after autonomous_mode is set to true and your autonomous code will start...
Contrary to what Mark McLeod describes in his post two years ago, I have never seen both the disabled and autonomous flags simultaneously. When we close the "disable" switch on our competition port dongle, the robot controller goes into disabled/teleoperated mode, regardless of the state of the "enable autonomous" switch. The User_Autonomous() function does not get called until the robot is enabled with the "autonomous" pin active.
  #8   Spotlight this post!  
Unread 28-03-2007, 23:57
lightning_blast lightning_blast is offline
Registered User
FRC #1814
 
Join Date: Feb 2006
Location: Canada
Posts: 15
lightning_blast is an unknown quantity at this point
Re: Timer Question

thanks for all of your help guys . im going to.. try out an autonomous tomorrow (GTR regionals ). i doubt we'll do so well but FIRST isnt all about winning right?
  #9   Spotlight this post!  
Unread 28-03-2007, 23:58
yoyodyne yoyodyne is offline
Registered User
AKA: Greg Smith
FRC #0116 (Epsilon Delta)
Team Role: Engineer
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Reston, VA
Posts: 61
yoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to behold
Re: Timer Question

Alan,

I don't know for a fact what the competition port sequence is this year but User_Autonomous_Code() gets called from main() if autonomous_mode is set regardless of the independent disabled_mode flag. It seems to me that to insure that Process_Data_From_Master_uP() is never called until the end of autonomous mode then disabled_mode and autonomous_mode would have to be set true at the same time. Maybe not for long but autonomous_mode has to already be set before disabled_mode is turned off.

We aren't taking any chances so we wait until disabled_mode is turned off and autonomous_mode is turned on to start our autonomous play.

Do you know what the timing is for 2007?
  #10   Spotlight this post!  
Unread 29-03-2007, 06:53
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Timer Question

Quote:
Originally Posted by yoyodyne View Post
I don't know for a fact what the competition port sequence is this year but User_Autonomous_Code() gets called from main() if autonomous_mode is set regardless of the independent disabled_mode flag.
My testing two years ago shows that the flags are not independent. When the "disable" pin on the competition port is grounded, the disabled_mode flag goes active as expected, but the autonomous_mode flag remains inactive whether or not the "autonomous" pin is grounded. I can state with absolute certainty that User_Autonomous_Code does not get called until disabled_mode goes away, indicating that being disabled keeps autonomous_mode from being true.
Quote:
Do you know what the timing is for 2007?
The timing of the pins is not particularly important. The "autonomous" pin obviously activates some time before the "disable" pin is released, but your code will see the flags change state simultaneously at the beginning of the match (and at the end of the autonomous period).
  #11   Spotlight this post!  
Unread 29-03-2007, 07:20
yoyodyne yoyodyne is offline
Registered User
AKA: Greg Smith
FRC #0116 (Epsilon Delta)
Team Role: Engineer
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Reston, VA
Posts: 61
yoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to beholdyoyodyne is a splendid one to behold
Re: Timer Question

Quote:
Originally Posted by Alan Anderson View Post
My testing two years ago shows that the flags are not independent. When the "disable" pin on the competition port is grounded, the disabled_mode flag goes active as expected, but the autonomous_mode flag remains inactive whether or not the "autonomous" pin is grounded. I can state with absolute certainty that User_Autonomous_Code does not get called until disabled_mode goes away, indicating that being disabled keeps autonomous_mode from being true.
Thanks for that information. Given that the default user code does not support that behavior and Mark's post I assumed that the flags as the user processor saw them were a direct reflection of the OI competition port pins. We need to take another look at our logic to latch the OI autonomous play and initial position switches and the "hand pointed" camera pixel offsets for one or both targets.
  #12   Spotlight this post!  
Unread 30-03-2007, 07:12
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,801
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Timer Question

My post applied to earlier field control. I found it to have changed to what Alan saw 2005 and after.

(I'm waiting for my teenager to leave for our regional this morning. Did I ever take this long to get ready in the morning?)
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 30-03-2007 at 07:15.
  #13   Spotlight this post!  
Unread 28-03-2007, 23:14
ay2b's Avatar
ay2b ay2b is offline
Registered User
AKA: Andy
FRC #2928
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 1994
Location: Seattle, WA
Posts: 211
ay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant future
Re: Timer Question

That is an excellent idea. Here's how I've been implementing it for the last few years; first the code, then an explination:

First off, I have two macros, all defined in auto_next.h
("DEBUG" is a macro defined elsewhere which will either call printf, or do nothing)

Code:
#ifndef __AUTO_NEXT_H__
#define __AUTO_NEXT_H__

#define AUTO_NEXT_STEP(x,name)                                              \
    if (auto_counter >= x)                                                  \
    {                                                                       \
        DEBUG((name "\r\n"));                                               \
        DEBUG(("auto_counter(%d) >= %d    ", auto_counter, x));             \
        ++auto_step;                                                        \
        DEBUG(("advancing to state %d\r\n", auto_step));                    \
        auto_counter = 0;                                                   \
    }

#define AUTO_NEXT_STEP_COND(x,y,name)                                       \
    AUTO_NEXT_STEP(x,name)                                                  \
    else if (y)                                                             \
    {                                                                       \
        DEBUG((name "\r\n"));                                               \
        DEBUG((#y));                                                        \
        DEBUG((" (%d)  ", auto_counter));                                   \
        ++auto_step;                                                        \
        DEBUG(("advancing to state %d\r\n", auto_step));                    \
        auto_counter = 0;                                                   \
    }

#endif // __AUTO_NEXT_H__
Somewhere above your autonomous function, declare these variables:

Code:
// These are used for state in autonomous mode
static unsigned int auto_counter = 0;
static char auto_step = 0;

And finally, in your slow loop autonomous function, do something like this:

Code:
void User_Autonomous_Slow_Loop(void)
{
    auto_counter++;

    switch (auto_step)
    {
      case 0:
        robot_drive(127,192);
        AUTO_NEXT_STEP(120, "drive forward");
        break;

      case 1:
        {
            bool turn;
            turn = robot_turn_to_angle(90);
            AUTO_NEXT_STEP_COND(400, turn, "turn robot");
        }
        break;

      case 2:
        robot_all_stop();
        break;
    }
}
In your slow loop function, you basically have a simple state machine. First your robot does whatever it does while in state 0, then state 1, etc. In the pseudo-code above, in state 0 it will drive straight forward at half speed; in state 1 it will turn to 90 degrees; in state 2, it stops.

The two variables, auto_step and auto_counter keep track of the state. The macros help manipulate them. AUTO_NEXT_STEP two paramaters, a time, and a string which is the name of the current mode. Each time through the slow loop, the auto_counter gets incremented. If it reaches the time paramater of AUTO_NEXT_STEP, the counter gets reset to 0 and the auto_step gets incremented.

The advantage to doing it this way over something like a bunch of chained if statements
Code:
if (timer < 120)
{
    // drive forward
} else if (timer < 400)
{
    // turn
}
is that you can easily change the time spent in one step without having to change the time in any of the other steps. Suppose you decide that you only want to drive forward for 100 counts rather than 120 counts. With this two-variable macro approach, you simply change the argument to AUTO_NEXT_STEP to 100 instead of 120. With the chained ifs, you have to change every single value.

The AUTO_NEXT_STEP_COND macro is like AUTO_NEXT_STEP, except that it also takes a condition. If you have a function like "robot_turn(90)" which returns a boolean value of TRUE when it is completed and FALSE when it is not, then you can use AUTO_NEXT_STEP_COND to advance to the next state as soon as a condition is met, rather than waiting for a time. This is particularly useful if you have functions to drive a certain distance based on encoder counts, or move an arm to a certain position, etc.

Good luck!

--AJY
__________________

2011 - SD Quarterfinalists (980), LA Quarterfinalists (980)
2010 - LA (2404) Finalists (980), AZ Motorola Quality (980)
2009 - LA Semifinalists (980); Las Vegas Quarterfinalists (980); SD (2404); IRI #1 Seed, Finalist (980)
2008 - SD Quarterfinalists (980), LA Champions (980), LA Rookie Inspiration Award (2404); CalGames Finalists
2007 - So.Cal Finalists (980), SD Quarterfinalists (980); CalGames Finalists
2006 - So.Cal Regional Champion (4), Toronto Judge's Award Day 1 (4)
2005 - SVR Champions, Delphi "Driving Tomorrow's Technology" (980); AZ Xerox Creativity (980); So.Cal Finalists, RadioShack Innovation in Control (980); Championship Archimedes Division Semifinalists; IRI Finalists (980)
2004 - So.Cal Regional Champions, Leadership in Controls (980); AZ GM Industrial Design (980); Championship Galileo Division #2 Seed; IRI Champions
2003 - PNW Semi-finalists (488)
2002 - PNW Finalists (488)
2000 - X-bot / 488 - Mentor / Founder
1994 - Sunny Delight - Driver - champion
Closed Thread


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
Timer questions Rick TYler Programming 3 12-02-2006 19:24
Quick Timer Question et1337 Programming 3 02-02-2006 15:19
Accelerometer Timer Question psquared Programming 3 12-02-2005 01:34
timer omega Programming 3 30-03-2004 18:52
Timer Preview Nate Smith General Forum 2 05-03-2003 12:25


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