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.

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

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

hi! I put servo_track(), and camera_handler() in the autonomous 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

There are a lot of while statements in that code that don’t look at all right to me. For example,

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.

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.

Ifs and Elses are the key in FRC. :cool:

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.

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:


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;
  }

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:)

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. :smiley: Thanks

Tether to your OI and make the Team number 0000.

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.

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.