Go to Post You know what they call the graduate with the lowest GPA in med school? Doctor. You know what they call the fourth robot in the alliance that wins Einstein? Champion. - Billfred [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 25-02-2006, 21:06
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
EasyC autonomous modes

It's after ship date now, but when we get to the regional, we want to program EasyC to select between various autonomous programs, depending on our starting position. We already wrote the various modes prior to ship, but didn't figure out how to select the proper one in EasyC. The old way, with MPLab and "default code" was to select your program after the robot is turned on and disabled, prior to Autonomous by setting a global variable to the appropriate value. From previous posts, it appears as if when the robot is powered up disabled, Initialize() is called then EasyC goes into a while loop until enabled. Am I getting this right? So neither OperatorControl() nor Autonomous() is called? I hope I am interpreting this incorrectly, because I am unsure where to put code that would read input from the OI while the robot is disabled awaiting Autonomous mode....
  #2   Spotlight this post!  
Unread 25-02-2006, 22:18
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: EasyC autonomous modes

I've been thinking about it.....

Could we put a while loop in Initialize() like this:

while (!IsEnabled())
{
// capture OI input for auto program
}

So when the robot is turned on and disabled, it will stay in the loop, listening to the OI. When enabled, the Autonomous will be called with the correct program hopefully.
  #3   Spotlight this post!  
Unread 26-02-2006, 00:59
Dillon Compton Dillon Compton is offline
Jack-Of-All-Trades
FRC #1391 (Metal Moose)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Malvern, PA
Posts: 186
Dillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud of
Send a message via AIM to Dillon Compton
Re: EasyC autonomous modes

Shouldent you be able to just call the OperatorControl() function in initialize? Unless I am mistaken, you should be able to stick that in the initialize function and access the OI input that way.
__________________
www.metalmoose.com
  #4   Spotlight this post!  
Unread 26-02-2006, 13:27
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: EasyC autonomous modes

Quote:
Originally Posted by Dillon Compton
Shouldent you be able to just call the OperatorControl() function in initialize? Unless I am mistaken, you should be able to stick that in the initialize function and access the OI input that way.

Hmmm that might work, too. I guess we will have to try it at competition. Another less desireable alternative is to just set the Autonomous program we want in the code and compile and upload. This will only work if we have time to consult with our alliance partners before we leave the pits pre-match, though. Baaahh, I wish we figured this out before we shipped, but all of our effort was focused on finishing the robot.
  #5   Spotlight this post!  
Unread 26-02-2006, 16:51
intelitek_Chris intelitek_Chris is offline
Registered User
no team
 
Join Date: Dec 2005
Location: Manchester
Posts: 19
intelitek_Chris will become famous soon enoughintelitek_Chris will become famous soon enough
Re: EasyC autonomous modes

Good Question!

There are probably many ways to do this (select between multiple autonomous programs). Here is one of many possible suggestions.

Have a series of switches that form a binary number (like the channel selection on your OI). If you had 3 switches, all off, for example, you would have program 1 selected. If the switches were all on, program 8 would be selected.

In your easyC code, have Initialize stuck in a loop, waiting for somekind of input from the controls (say Button BB). When you have all your switches set correctly (this can be after the robot has been placed on the field), press button BB. This will set a variable, say 'AutProg' to a number, as designated by your switches, and exit the loop in Initialize. Now, when the match starts, your autonomous function will immediately begin running the program that corresponds to the variable 'AutProg', and begin running the program.

If you ever have to reset the robot for any reason (from the OI), you can jump out of initialize by pressing the button BB. You won't run any autonomous code, because the field control will be in Operator Control (and the autonomous flag will be off), but this way you will have direct control over how long the initialize function stays looping (it will loop until you hit button BB).

You could do all of this with a single button, if write enough code, and don't have multiple switches. Just set some timers up to record times between button presses, and create a code for entering in which autonomous program to use. Hope this helps!
  #6   Spotlight this post!  
Unread 26-02-2006, 17:14
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: EasyC autonomous modes

Thanks, that really does help. Or at least it eases my worries Right now we were thinking of having:

while ( !IsEnabled() )
{
p4_trig = GetOIDInput ( 4 , 1 ) ;
if ( p4_trig )
{
if ( autoProgram < 6 )
{
autoProgram ++ ;
}
else
{
autoProgram = 1 ;
}
SetUserDisplay ( autoProgram ) ;
while ( p4_trig )
{
}
}
}

This would be in our initialize loop. This should work right? The idea being that the only time we will be setting the Autonomous program will be while the robot is in disabled mode. We plan on just using a joy plugged into port 4 to cycle between 6 programs. The program number should show up in user display I hope. So even if the RC needs to be reset during the match, since the field is enabled the autonomous selection code above won't even run right?
  #7   Spotlight this post!  
Unread 26-02-2006, 20:34
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: EasyC autonomous modes

Quote:
Originally Posted by TubaMorg
Thanks, that really does help. Or at least it eases my worries Right now we were thinking of having:

while ( !IsEnabled() )
{
p4_trig = GetOIDInput ( 4 , 1 ) ;
if ( p4_trig )
{
if ( autoProgram < 6 )
{
autoProgram ++ ;
}
else
{
autoProgram = 1 ;
}
SetUserDisplay ( autoProgram ) ;
while ( p4_trig )
{
}
}
}

This would be in our initialize loop. This should work right? The idea being that the only time we will be setting the Autonomous program will be while the robot is in disabled mode. We plan on just using a joy plugged into port 4 to cycle between 6 programs. The program number should show up in user display I hope. So even if the RC needs to be reset during the match, since the field is enabled the autonomous selection code above won't even run right?
Here's another example of setting the autonomous mode. Each time you click the joystick trigger, the mode increases by one. In this case there are 5 modes so the MOD (%) operator limits the modes to have values from 0 - 4.

This code can be placed at the end of the initialize function - and just continues to run waiting for either autonomous or operator control to start. That way the robot is continuously allowing the mode to be set right up to the start of the match. There is no need to check if the robot is enabled.
Code:
// code sample from EasyC (or WPILib)
void Initialize ( void )
{
      unsigned char mode = 0; 

      while ( 1 )
      {
            while ( GetOIDInput(1,1) == 0 )     // wait for the trigger
            {
            }
            mode++ ;                            // increment mode
            while ( GetOIDInput(1,1) == 1 )     // wait for trigger release
            {
            }
            mode %= 5 ;                         // make sure mode < 5
            SetUserDisplay ( mode ) ;           // put mode in LED for feedback
      }
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #8   Spotlight this post!  
Unread 26-02-2006, 21:00
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: EasyC autonomous modes

That is pretty slick. My only concern was/is that the code would be stuck in Initialize() in the while(1) loop, but from what you said this isn't true? So say we start the robot up normally for testing with our dongle set to enable and manual (OperatorControl). Initialize is called first, but how does it get out of the while loop and continue on to OperatorControl? Similarly, during competition, how does the program know when Initialize is done if it's always in the while loop in Initialize()?
  #9   Spotlight this post!  
Unread 26-02-2006, 22:01
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: EasyC autonomous modes

Quote:
Originally Posted by TubaMorg
That is pretty slick. My only concern was/is that the code would be stuck in Initialize() in the while(1) loop, but from what you said this isn't true? So say we start the robot up normally for testing with our dongle set to enable and manual (OperatorControl). Initialize is called first, but how does it get out of the while loop and continue on to OperatorControl? Similarly, during competition, how does the program know when Initialize is done if it's always in the while loop in Initialize()?
You are correct... I don't know what I was thinking.

How's this:
Code:
// code sample from EasyC (or WPILib)
void Initialize ( void )
{
      unsigned char mode = 0; 

      while ( !IsEnabled() )
      {
            while ( GetOIDInput(1,1) == 0 )     // wait for the trigger
            {
            }
            mode++ ;                            // increment mode
            while ( GetOIDInput(1,1) == 1 )     // wait for trigger release
            {
            }
            mode %= 5 ;                         // make sure mode < 5
            SetUserDisplay ( mode ) ;           // put mode in LED for feedback
      }
}
Thanks for pointing out the error!

The only other thing with this method is making sure that the field doesn't become enabled before the operator is finished incrementing the mode to the right value. Otherwise, autonomous will start with some intermediate setting.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #10   Spotlight this post!  
Unread 26-02-2006, 22:32
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: EasyC autonomous modes

Great! Now it is 100% cool I will add this on to the ole to-do list for competition.

Hopefully the driver will set the auto program and back away behind the line before the field is enabled. Of course if anything goes wrong it ALWAYS operator error and not the program's fault.

Thanks for all the help this season. Yall have always been very timely in your responses to any EasyC questions!
  #11   Spotlight this post!  
Unread 26-02-2006, 23:01
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: EasyC autonomous modes

Uh...hate to be a wet blanket, but for others that are looking at this I just thought of another problem with your snippet. Won't the INNER while loops also cause the program to stick in Initialize()? Say the operator sets the auto program he wants then backs away, then the code sits here in:

while ( GetOIDInput(1,1) == 0 ) // wait for the trigger
{
}


Right? The only way to escape to the outside loop is to press the trigger again after the field is enabled (not allowed).
  #12   Spotlight this post!  
Unread 26-02-2006, 23:25
Dillon Compton Dillon Compton is offline
Jack-Of-All-Trades
FRC #1391 (Metal Moose)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Malvern, PA
Posts: 186
Dillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud of
Send a message via AIM to Dillon Compton
Re: EasyC autonomous modes

Quote:
Originally Posted by TubaMorg
Uh...hate to be a wet blanket, but for others that are looking at this I just thought of another problem with your snippet. Won't the INNER while loops also cause the program to stick in Initialize()? Say the operator sets the auto program he wants then backs away, then the code sits here in:

while ( GetOIDInput(1,1) == 0 ) // wait for the trigger
{
}


Right? The only way to escape to the outside loop is to press the trigger again after the field is enabled (not allowed).
Would this work (changes in red)? If I am not mistaken, this will break you out of the inner loop as soon as the field is enabled, eliminating the infinite loop type issue.

Quote:
// code sample from EasyC (or WPILib)
void Initialize ( void )
{
unsigned char mode = 0;

while ( !IsEnabled() )
{

while ( GetOIDInput(1,1) == 0 && !IsEnabled())// wait for the trigger, but only if the field is disabled
{
}
mode++ ; // increment mode
while ( GetOIDInput(1,1) == 1 ) // wait for trigger release
{
}
mode %= 5 ; // make sure mode < 5
SetUserDisplay ( mode ) ; // put mode in LED for feedback
}
}
__________________
www.metalmoose.com
  #13   Spotlight this post!  
Unread 26-02-2006, 23:31
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: EasyC autonomous modes

I was thinking that, too, which will certainly get you out of Initialize(). The only problem with that, though, is that the mode counter increments 1 more, taking you off the program you set. I'm thinking my original sample is the answer, although if you like the %= (which is pretty slick) you could substitute that for my way of counting.
  #14   Spotlight this post!  
Unread 27-02-2006, 00:06
Dillon Compton Dillon Compton is offline
Jack-Of-All-Trades
FRC #1391 (Metal Moose)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Malvern, PA
Posts: 186
Dillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud of
Send a message via AIM to Dillon Compton
Re: EasyC autonomous modes

Quote:
Originally Posted by TubaMorg
I was thinking that, too, which will certainly get you out of Initialize(). The only problem with that, though, is that the mode counter increments 1 more, taking you off the program you set. I'm thinking my original sample is the answer, although if you like the %= (which is pretty slick) you could substitute that for my way of counting.
Yea...you are probably right on this one, i'll give you that.

But for the sake of argument (and because I like the way Brad's code is layed out more[no offense]), I think this might work...

Code:
// code sample from EasyC (or WPILib)
void Initialize ( void )
{
      unsigned char mode = 0; 

      while ( !IsEnabled() )
      {
            while ( GetOIDInput(1,1) == 0 && !IsEnabled() ) 
            // wait for the trigger, but only if the field is disabled.
            {
            }

	    if ( !IsEnabled() )
	    {
           	 mode++;      // increment mode  
            }
         
            while ( GetOIDInput(1,1) == 1 )     // wait for trigger release
            {
            }

            mode %= 5 ;                         // make sure mode < 5
            SetUserDisplay ( mode ) ;           // put mode in LED for feedback
      }
}
__________________
www.metalmoose.com
  #15   Spotlight this post!  
Unread 27-02-2006, 00:54
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: EasyC autonomous modes

That's it! And I agree, Brad's code passes the coolness (and elegance) test better than mine
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
White Paper Discuss: C Programming and Autonomous Modes for Newbies cbolin Extra Discussion 3 09-01-2008 19:32
Rookie autonomous modes StephLee General Forum 6 30-04-2005 13:16
Question about switching autonomous modes DemonYawgmoth Programming 2 23-03-2005 17:02
Alternative autonomous modes Jon Reese Programming 1 14-01-2004 13:17


All times are GMT -5. The time now is 23:05.

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