Go to Post Patents are an issue of law which, alas, has little to do with engineering or common sense. - Mike Betts [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 19-02-2006, 01:13
Adrien's Avatar
Adrien Adrien is offline
Registered User
FRC #1414 (IHOT)
Team Role: Leadership
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Atlanta, GA
Posts: 13
Adrien is an unknown quantity at this point
Send a message via MSN to Adrien
Sending variables to Auto Mode

Hey,

As ship date ominously approaches, our team is scrambling to get some testing in. Currently our robot is set up to do all three autonomous positions (forward, middle, and back) however I've had some problems setting up our toggle switch so we can quickly toggle between positions.

Basically we've got a custom 3-state DPDT switch hooked up to our OI through Port 3 so that Switch Forward makes p3_sw_trig true, and switch back makes p3_sw_top true... if you know what I mean.

Anyway, the 3-state switch is used to determine our position in autonomous, but we also use it for harvesting and expelling balls in manual mode. It works properly in manual mode so I know it's wired and working properly. Getting it to work with auto mode is not so successful. Let me show you what I have set up:

main.c:
Code:
char position = 0;

void main (void)
{
#ifdef UNCHANGEABLE_DEFINITION_AREA
  IFI_Initialization ();        /* DO NOT CHANGE! */
#endif

  User_Initialization();        /* You edit this in user_routines.c */

  statusflag.NEW_SPI_DATA = 0;  /* DO NOT CHANGE! */ 

  while (1)   /* This loop will repeat indefinitely. */
  {
#ifdef _SIMULATOR
    statusflag.NEW_SPI_DATA = 1;
#endif

    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {                                 /* I'm slow!  I only execute every 26.2ms because */
                                      /* that's how fast the Master uP gives me data. */
      position = Process_Data_From_Master_uP();   /* You edit this in user_routines.c */

      if (autonomous_mode)            /* DO NOT CHANGE! */
      {
		printf("Main: p: %d\r\n",(int)position);
        User_Autonomous_Code(position);        /* You edit this in user_routines_fast.c */
      }
    }
    Process_Data_From_Local_IO();     /* You edit this in user_routines_fast.c */
                                      /* I'm fast!  I execute during every loop.*/
  } /* while (1) */
}  /* END of Main */
user_routines.c:
Code:
char pos = 0;

char Process_Data_From_Master_uP(void)
{

	Getdata(&rxdata);
/* Camera and other important Stuff... */

	if(trig_fwd) //trig_fwd is p3_sw_trig
	{
		pos = 0;
	}
	else if(trig_rev) //trig_rev is p3_sw_top
	{
		pos = 2;
	}
	else
	{
		pos = 1;
	}
	Putdata(&txdata);

return pos;
}
user_routines_fast.c:
Code:
void User_Autonomous_Code(char position)
{
/* Important Stuff */

 while (autonomous_mode)   /* DO NOT CHANGE! */
  {
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {
        Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */

		if(position == 0)
		{
                            // Auto Stuff
		}
		else if(position == 1)
		{
                            // Auto Stuff
		}
		else
		{
                            // Auto Stuff
		}
        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
}
For some reason in user_routines.c, I think it falls through to the else so that pos=1 because no matter where the switch is, the position is always 1. So I do know the variable is being passed through he functions correctly, I just don't know why trig_fwd or trig_rev aren't being what they should be there... It looks like it should work to me, but maybe somebody will be able to find something messed up in the code.

Thanks for the help!

Last edited by Adrien : 19-02-2006 at 01:17.
  #2   Spotlight this post!  
Unread 19-02-2006, 01:47
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,112
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: Sending variables to Auto Mode

The problem is simple. When autonomous mode begins, all inputs from the OI are set to their neutral/off state. So neither trig_fwd nor trig_rev will be active when you read them the first time after the autonomous mode flag is set.

Fortunately, the solution too is simple. Instead of always calling Process_Data_From_Master_uP(), inside main(), only call it if you're not in autonomous mode. Make it the else clause of your if (autonomous_mode) statement. Make position a global (or static local) variable so you can use it later.
  #3   Spotlight this post!  
Unread 19-02-2006, 12:09
Adrien's Avatar
Adrien Adrien is offline
Registered User
FRC #1414 (IHOT)
Team Role: Leadership
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Atlanta, GA
Posts: 13
Adrien is an unknown quantity at this point
Send a message via MSN to Adrien
Re: Sending variables to Auto Mode

Thanks for the response.

So basically you're saying that when autonomous_mode is true, everything from the OI is set to neutral, or off?

So that means when we're at the real competition, as soon as the bots are activated, they're put into autonomous mode, right? So that wouldn't work because it would never go to Process_Data_From_Master_uP()...

Although, when we start the bots up, they are running, but in a disabled state... Could the bots receive values from the OI before the match starts and then use them in auto mode? You know what I mean?
  #4   Spotlight this post!  
Unread 19-02-2006, 18:29
jgannon's Avatar
jgannon jgannon is offline
I ᐸ3 Robots
AKA: Joey Gannon
no team
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Pittsburgh, PA
Posts: 1,467
jgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond repute
Re: Sending variables to Auto Mode

Quote:
Originally Posted by Adrien
Could the bots receive values from the OI before the match starts and then use them in auto mode?
Yes. The last values from the OI before autonomous starts, even when disabled, are available to you in autonomous mode.
__________________
Team 1743 - The Short Circuits
2010 Pittsburgh Excellence in Design & Team Spirit Awards
2009 Pittsburgh Regional Champions (thanks to 222 and 1218)
2007 Pittsburgh Website Award
2006 Pittsburgh Regional Champions (thanks to 395 and 1038)
2006 Pittsburgh Rookie Inspiration & Highest Rookie Seed

Team 1388 - Eagle Robotics
2005 Sacramento Engineering Inspiration
2004 Curie Division Champions (thanks to 1038 and 175)
2004 Sacramento Rookie All-Star

_
  #5   Spotlight this post!  
Unread 19-02-2006, 21:51
TimeOut's Avatar
TimeOut TimeOut is offline
Registered User
AKA: Sean Kelly
FRC #0499 (The Toltechs)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: San Antonio, TX
Posts: 50
TimeOut is on a distinguished road
Re: Sending variables to Auto Mode

Try this:

instead of of doing:
position = Process_Data_From_Master_uP();

do this:
if (!autonomous_mode) {
position = get_auto_mode();
}

The write a new function that all it does is return the position of the switch. We put ours in a seperate file that is just the TOLTECH's code.

During the disable and user modes you want the position to be updated. I'm not 100% sure how the game masters will transition to Autonomous. If they switch to autonomous BEFORE the loop hits the position assignment, then you'll get a 0 (or whatever you default case is). This solved the problem for us.

Sean

Quote:
Originally Posted by jgannon
Yes. The last values from the OI before autonomous starts, even when disabled, are available to you in autonomous mode.
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
auto mode nuggetsyl General Forum 12 13-02-2006 19:45
Cross Mode Variables? Mr. Steve Programming 16 26-01-2006 14:34
camera auto mode pwm contention? AL_E Programming 4 24-01-2006 22:10
Did you use Auto Servo Mode? Greg Marra Programming 8 27-04-2005 15:35
pic: 233 after Auto mode Jeff Rodriguez Extra Discussion 13 26-04-2005 19:33


All times are GMT -5. The time now is 16:58.

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