Go to Post Don't trust everything you read on Chief Delphi. - Peter Matteson [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 05-02-2007, 17:30
fallen751 fallen751 is offline
Registered User
FRC #2052
 
Join Date: Jan 2007
Location: Minnesota
Posts: 17
fallen751 is an unknown quantity at this point
Autonomous Mode

I have been coding our autonomous mode, but it seems that everytime I switch into autonomous mode it kills the camera. I was wondering if anyone could tell me if this code would keep the camera from running during autonomous mode.

Code:
void User_Autonomous_Code(void)
{

  /* Initialize all PWMs and Relays when entering Autonomous mode, or else it
     will be stuck with the last values mapped from the joysticks.  Remember, 
     even when Disabled it is reading inputs from the Operator Interface. 
  */
  pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
  pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;
  relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;
  relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;
  relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;
  relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;

  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! */

        /* Add your own autonomous code here. */
		if(Get_Tracking_State() == CAMERA_ON_TARGET)
		 {
			
			static char oldpwm01, oldpwm02, oldpwm03, oldpwm04;
			int slowpwm01, slowpwm02, slowpwm03, slowpwm04;

			while (PAN_SERVO > 130) 
				{
					pwm01 = 147;
					pwm02 = 147;
					pwm03 = 147;
					pwm04 = 147;
				}
			while (PAN_SERVO < 124)
				{
					pwm01 = 107;
					pwm02 = 107;
					pwm03 = 107;
					pwm04 = 107;
				}
			while (rackdistance[servotodegrees(TILT_SERVO) * 2] >= 24)
				{
					int prepwm01, prepwm02, prepwm03, prepwm04;

					prepwm01 = prepwm02 = prepwm03 = prepwm03 = 127;

					prepwm01 += 1;
					prepwm02 -= 1;
					prepwm03 += 1;
					prepwm04 -= 1;

					if (prepwm02 > 127 && prepwm02 < 170)
						{
							prepwm02 += 12;
						}

					if (prepwm04 > 127 && prepwm04 < 170)
						{
							prepwm04 += 12;
						}

					pwm01 = prepwm01;
					pwm02 = prepwm02;
					pwm03 = prepwm03;
					pwm04 = prepwm04;

					oldpwm01 = pwm01;
					oldpwm02 = pwm02;
					oldpwm03 = pwm03;
					oldpwm04 = pwm04;
				}

			slowpwm01 = oldpwm01;
			slowpwm02 = oldpwm02;
			slowpwm03 = oldpwm03;
			slowpwm04 = oldpwm04;

			while ((rackdistance[servotodegrees(TILT_SERVO) * 2] < 24) && (rackdistance[servotodegrees(TILT_SERVO) * 2] >= 5))
				{
					slowpwm01 = slowdown(slowpwm01);
					slowpwm02 = slowdown(slowpwm02);
					slowpwm03 = slowdown(slowpwm03);
					slowpwm04 = slowdown(slowpwm04);

					pwm01 = slowpwm01;
					pwm02 = slowpwm02;
					pwm03 = slowpwm03;
					pwm04 = slowpwm04;
				}

			if (rackdistance[servotodegrees(TILT_SERVO) * 2] < 5)
				{
					pwm01 = pwm02 = pwm03 = pwm04 = 127;
				}
		}

	else
		{
			pwm01 = pwm02 = pwm03 = pwm04 = 127;
		}

        Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
}
  #2   Spotlight this post!  
Unread 05-02-2007, 18:14
Samuel H. Samuel H. is offline
Registered User
no team
 
Join Date: Dec 2005
Rookie Year: 1000
Location: World
Posts: 40
Samuel H. has a spectacular aura aboutSamuel H. has a spectacular aura about
Re: Autonomous Mode

Hello.

For the camera to track, you need to copy the camera tracking stuff (ie. Camera_Handler and Servo_Track) from Process_Data_From_Master_uP to User_Autonomous_Code. PM me if you need more details.

Good luck,
Sam
  #3   Spotlight this post!  
Unread 05-02-2007, 19:00
fallen751 fallen751 is offline
Registered User
FRC #2052
 
Join Date: Jan 2007
Location: Minnesota
Posts: 17
fallen751 is an unknown quantity at this point
Re: Autonomous Mode

hi! I put servo_track(), and camera_handler() in the autonomous code

Code:
 while (autonomous_mode)   /* DO NOT CHANGE! */
  {
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {

	Getdata(&rxdata);
	Camera_Handler();
	Servo_Track();


	// Turn on the "Switch 3" LED on the operator interface if
	// the camera is pointed at the green light target. The
	// Switch3_LED variable is also used by the Default_Routine()
	// function below, so disable it inside Default_Routine()
	// if you want to keep this functionality. 
	if(Get_Tracking_State() == CAMERA_ON_TARGET)
	{
		Switch3_LED = 1;
	}
	else
	{
		Switch3_LED = 0;
	}

        /* Add your own autonomous code here. */
		if(Get_Tracking_State() == CAMERA_ON_TARGET)
		 {

			static char oldpwm01, oldpwm02, oldpwm03, oldpwm04;
			int slowpwm01, slowpwm02, slowpwm03, slowpwm04;
yet, still no camera searching while in autonomous mode! any help is much appreciated. we plug a wire between pins 8 and 5 to activate autonomous mode on our control - and it seems to work fine, so I don't think its an issue on that side. however, any autonomous code I put in doesn't seem to be read by the control - like if I started autonomous with a pwm01 = 254 the first victor light would still be orange. thanks!

p.s. why does the autonomous mode need to be a large while loop? isn't it checked every cycle of the main function? so wouldn't it be easier to leave the up_master_data stuff out and just run autonomous from main.c

Last edited by fallen751 : 05-02-2007 at 19:06.
  #4   Spotlight this post!  
Unread 05-02-2007, 21:06
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: Autonomous Mode

There are a lot of while statements in that code that don't look at all right to me. For example,
Code:
while (PAN_SERVO > 130) 
  {
    pwm01 = 147;
    pwm02 = 147;
    pwm03 = 147;
    pwm04 = 147;
  }
looks like it will get stuck forever if the PAN_SERVO is greater than 130. Nothing is done inside the loop to let the value of PAN_SERVO change. Take a look at your RC and see if the CODE ERROR light is turning red when you try to run your autonomous routine.

And then try changing those while statments into if statements, which is what it looks like they really ought to be.
  #5   Spotlight this post!  
Unread 06-02-2007, 01:50
code_lacky code_lacky is offline
Registered User
AKA: Mark
FRC #0840
Team Role: Programmer
 
Join Date: Feb 2007
Rookie Year: 2006
Location: San Mateo, CA
Posts: 12
code_lacky is an unknown quantity at this point
Re: Autonomous Mode

just a hint. Try to stay away from while loops as previously mentioned. They mess with your code because othe essential functions are not able to be called when your code is in a while loop.
  #6   Spotlight this post!  
Unread 06-02-2007, 02:05
Bomberofdoom's Avatar
Bomberofdoom Bomberofdoom is offline
Biggest FIRST addict in Israel
AKA: Nir Levanon
FRC #2230 (Zcharia's Angels)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Israel
Posts: 471
Bomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond repute
Send a message via MSN to Bomberofdoom
Re: Autonomous Mode

Ifs and Elses are the key in FRC.
  #7   Spotlight this post!  
Unread 06-02-2007, 07:01
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: Autonomous Mode

Don't forget to copy over all the includes at the top of user_routines dealing with the camera. IE tracking.h. You can just copy all the includes from user_routines to user_routines_fast if you wish.
__________________
Amperage Robotics Team 1225
Site under-going revamp. :/
  #8   Spotlight this post!  
Unread 07-02-2007, 11:28
Zero_Cool Zero_Cool is offline
Registered User
FRC #1208
 
Join Date: Feb 2007
Location: Illinois
Posts: 3
Zero_Cool is an unknown quantity at this point
Re: Autonomous Mode

don't forget the switch statement, which can be more useful or better for use in autonomous.
  #9   Spotlight this post!  
Unread 08-02-2007, 13:15
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: Autonomous Mode

Quote:
Originally Posted by Zero_Cool View Post
don't forget the switch statement, which can be more useful or better for use in autonomous.
Indeed, it's very useful for programmers doing autonomous work to understand the concept of the finite state machine (http://en.wikipedia.org/wiki/Finite_state_machine), since that is one of the easiest ways to come up with a clearly written and debug-able autonomous routine.

Most of our routines end up looking something like:

Code:
switch (auto_state) {
	case INITIALIZE:
	  Auto_Initialize(); // Set up auto mode
          auto_state=FASTASPPROACH
	  break;
       case APPROACH: 
          // Code that drives towards goals quickly, and at some point
          // resets auto_state to SCORE
          break;
       case SCORE: 
          // Score many points!
	  break;  
	case DONE:
	default:
        // do nothing!
        
      break;
  }
  #10   Spotlight this post!  
Unread 08-02-2007, 17:53
Ryan O's Avatar
Ryan O Ryan O is offline
FRC Eclipse Plug-in Developer
no team (FRC Eclipse)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Plaistow
Posts: 111
Ryan O is an unknown quantity at this point
Send a message via AIM to Ryan O
Re: Autonomous Mode

Yeah, definately don't do loops in autonomous. The while loop in the default code provides the repeat. Just use if-elses to get one thing done before the next happens. That eliminates the possiblility of running into an error becuase the code takes too long to execute and fills the buffer. That would stop the bot cold for the entire match. (Beleive me, I've done it
  #11   Spotlight this post!  
Unread 08-02-2007, 22:52
dpick1055's Avatar
dpick1055 dpick1055 is offline
David Pick
FRC #1739 (Chicago Knights)
Team Role: Alumni
 
Join Date: May 2005
Rookie Year: 2004
Location: Chicago
Posts: 75
dpick1055 is on a distinguished road
Send a message via AIM to dpick1055
Re: Autonomous Mode

Could someone please explain how to "switch" into autonomous mode without using a dongle. I want to test my autonomous code but haven't had time to make a dongle yet. Thanks
__________________
Always remember to take your powered wheels off the ground when first testing code. Otherwise you'll end up with holes in the wall like us
  #12   Spotlight this post!  
Unread 08-02-2007, 23:08
d.courtney's Avatar
d.courtney d.courtney is offline
Registered User
AKA: David
FRC #0781 (Kinetic Knights)
Team Role: Alumni
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Kincardine, Ontario
Posts: 196
d.courtney has much to be proud ofd.courtney has much to be proud ofd.courtney has much to be proud ofd.courtney has much to be proud ofd.courtney has much to be proud ofd.courtney has much to be proud ofd.courtney has much to be proud ofd.courtney has much to be proud ofd.courtney has much to be proud ofd.courtney has much to be proud of
Re: Autonomous Mode

Quote:
Originally Posted by dpick1055 View Post
Could someone please explain how to "switch" into autonomous mode without using a dongle. I want to test my autonomous code but haven't had time to make a dongle yet. Thanks
Tether to your OI and make the Team number 0000.
__________________
  #13   Spotlight this post!  
Unread 08-02-2007, 23:25
dpick1055's Avatar
dpick1055 dpick1055 is offline
David Pick
FRC #1739 (Chicago Knights)
Team Role: Alumni
 
Join Date: May 2005
Rookie Year: 2004
Location: Chicago
Posts: 75
dpick1055 is on a distinguished road
Send a message via AIM to dpick1055
Re: Autonomous Mode

Thanks.
__________________
Always remember to take your powered wheels off the ground when first testing code. Otherwise you'll end up with holes in the wall like us
  #14   Spotlight this post!  
Unread 08-02-2007, 23:46
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Autonomous Mode

Quote:
Originally Posted by dpick1055 View Post
Could someone please explain how to "switch" into autonomous mode without using a dongle. I want to test my autonomous code but haven't had time to make a dongle yet. Thanks
You really should use a dongle. They're easy to make, and you can't forget to change anything back before you go to a match. (I'd hate to be plugged into the field and the IFI guy coming up and saying, "You're team number isn't set.")

If everyone on your team is deathly afraid of soldering, you can buy a dongle from AndyMark.
  #15   Spotlight this post!  
Unread 09-02-2007, 00:28
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: Autonomous Mode

Quote:
Originally Posted by dpick1055 View Post
Could someone please explain how to "switch" into autonomous mode without using a dongle. I want to test my autonomous code but haven't had time to make a dongle yet. Thanks
It's pretty easy:

1. Make dongle.
2. Use dongle.

Seriously, you really, really, should have a dongle with a disable switch handy when you test autonomous mode. 1 trip to Radio Shack and a half hour with a soldering iron is all it takes.
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
Autonomous Mode Slick Programming 22 01-02-2007 19:26
autonomous mode seanl Programming 6 31-01-2007 15:59
Autonomous mode chs938 Programming 1 03-02-2006 10:19
Autonomous Mode David Bryan Programming 1 21-01-2003 21:15
autonomous mode? bigwalt Technical Discussion 1 21-01-2003 01:14


All times are GMT -5. The time now is 04:12.

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