Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Use of Functions in Autonomous (http://www.chiefdelphi.com/forums/showthread.php?t=34707)

VideoMan053 15-02-2005 19:05

Use of Functions in Autonomous
 
I am hoping to make my autonomous code easy to understand. I was hoping to call functions like: FindColor, PanServo (to find a color) RaiseArm (to raise our arm to the desired height). I was wondering if I call one of these functions and autonomous mode ends, does the robot stop in the middle of my function or does it continue until it returns to the autonomous function?

ace123 16-02-2005 01:54

Re: Use of Functions in Autonomous
 
One thing that I would suggest is to change the part of user_routines_fast.c that says /*DO NOT CHANGE*/

No real code changes, but it is just a small thing to run something when it begins and ends... This is legal, and the "do not change" comment is referring to changing the order or deleting the loop.
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=0;
  pwm05=pwm06=pwm07=pwm08=0;
  pwm09=pwm10=pwm11=pwm12=0;
  pwm13=pwm14=pwm15=pwm16=0;

  printf("Autonomous mode has begun!!!\r");
  // Code executes here when autonomous begins...;
  // Use this to reset all autonomous state variables (if any)

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

        printf("Autonomous mode has ended!!!\r");
        // Code executes here when autonomous mode ends...
        // Use this to stop camera, stop all motors.

      } else {

        // Normal autonomous code

      }
      Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
      Putdata(&txdata);  /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  } while (autonomous_mode);  /* DO NOT CHANGE! */
}

Alternatives that require setting variables while in autonomous mode, etc. are a lot messier than a few if statements in the loop.

Alan Anderson 16-02-2005 08:23

Re: Use of Functions in Autonomous
 
I think AIBob is answering a question that you didn't ask.

The correct answer to your question is that any functions you call from within the autonomous loop will run to completion and return to where they were called from. The only place the provided code checks to see whether the robot is still in autonomous mode is the while (autonomous_mode) line.

phillutz 16-02-2005 11:21

Re: Use of Functions in Autonomous
 
Also, at the end of Auton mode, the robots will be disabled so the answer, will the function finish... No.
If you activate a piston at 14.5 seconds in, the piston will still expand though... (I think) :confused:

Chris Hibner 16-02-2005 11:25

Re: Use of Functions in Autonomous
 
Quote:

Originally Posted by phillutz
Also, at the end of Auton mode, the robots will be disabled so the answer, will the function finish... No.
If you activate a piston at 14.5 seconds in, the piston will still expand though... (I think) :confused:

Why do you say the robots will be disabled at the end of autonomous mode?

gnormhurst 16-02-2005 12:54

Re: Use of Functions in Autonomous
 
I am losing sleep over this issue, too.

There are two flags #defined in ifi_aliases.h:
disabled_mode
autonomous_mode

The state of these is contolled by the match computer. "Disabled", I believe, means that the outputs are all set to neutral (motors stop, relays are off, etc). It does not mean that your program stops running. Your program continues to execute.

An example of how this could be really bad is if you are using error integration in a PID loop. If the outputs are disabled, your program will continue to integrate error while being unable to control anything (the feedback loop is open). When the disabled_mode goes false and the outputs are re-enabled, there will be a huge error signal that may cause very strange behavior.

This is especially an issue since disabled_mode becomes true multiple times during a match: when the human player steps off the switch pad. The robot stops, but the program continues, possibly integrating PID errors!

Another concern is about state machines getting left in a state != START. If the autonomous code stops being called while a state machine is doing something, that machine will be in the middle of its sequence when it is called again e.g. from non-autonomous mode. I wish I had a way to reset all state machines to their initial state.

It is also not clear how the match computer will sequnce autonomous_mode and disabled_mode. disabled_mode is true before autonomous starts, but the state of autonomous_mode at that time is not clear. Likewise, at the end of autonomous I'm pretty sure that disabled_mode will be set to true, but when does autonomous become false?

I think the rule has to be: the state of autonomous_mode should only be trusted when disabled_mode is false. And if PID loops use integration, they should only be updated when the robot is enabled:
Code:

if ( !disabled_mode )
{
  pid( LEFT) ;
  pid( RIGHT );
}

Comments please...?

Dave Flowerday 16-02-2005 16:04

Re: Use of Functions in Autonomous
 
Quote:

Originally Posted by gnormhurst
It is also not clear how the match computer will sequnce autonomous_mode and disabled_mode. disabled_mode is true before autonomous starts, but the state of autonomous_mode at that time is not clear. Likewise, at the end of autonomous I'm pretty sure that disabled_mode will be set to true, but when does autonomous become false?

Our experiences in the past are that before the match starts, your robot is disabled only. IFI does not put your robot into autonomous mode until the round actually starts (they enable your robot and put it into autonomous at the same time). Your robot remains enabled from the start of autonomous until the end of the match (it does not get disabled anywhere around the end of autonomous), with the exception of being disabled by your HP this year. Again, this is from past experience so it's not guaranteed to be true this year, but I'd be surprised if they changed it.

Astronouth7303 16-02-2005 16:15

Re: Use of Functions in Autonomous
 
Quote:

Originally Posted by gnormhurst
Another concern is about state machines getting left in a state != START. If the autonomous code stops being called while a state machine is doing something, that machine will be in the middle of its sequence when it is called again e.g. from non-autonomous mode. I wish I had a way to reset all state machines to their initial state.

It is also not clear how the match computer will sequnce autonomous_mode and disabled_mode. disabled_mode is true before autonomous starts, but the state of autonomous_mode at that time is not clear. Likewise, at the end of autonomous I'm pretty sure that disabled_mode will be set to true, but when does autonomous become false?

I think the rule has to be: the state of autonomous_mode should only be trusted when disabled_mode is false. And if PID loops use integration, they should only be updated when the robot is enabled:

All very important points (though I would implement it differently). The current PID code does not take into account disabled mode (though easily fixed through if's and ternaries). Integral wind-up is probably the biggest problem in this 'active' disabled mode (as opposed to previous years, where if you were after the match started, nobody cared).

I would not be worried so much about the scripting except for testing. The easiest way to fix it is to move the state variables to a single global and use that, and if you enter user mode (when you're enabled), then clear it.

Also, can some one with more expieriance than me reiterate what integral wind-up is? (and add it to FIRSTwiki?)

Joe Ross 17-02-2005 09:01

Re: Use of Functions in Autonomous
 
Quote:

Originally Posted by Chris Hibner
Why do you say the robots will be disabled at the end of autonomous mode?

Because the field people need a chance to remove hanging tetras and add bonus tetras. I highly doubt they will be doing that with the robots enabled. At kickoff, they mentioned a short pause between autonomous and human mode.

Dave Flowerday 17-02-2005 10:38

Re: Use of Functions in Autonomous
 
Quote:

Originally Posted by Joe Ross
At kickoff, they mentioned a short pause between autonomous and human mode.

Ah, that's right. I remember them saying that as well, though they didn't make a big deal out of it.

Alan Anderson 17-02-2005 11:37

Re: Use of Functions in Autonomous
 
Quote:

Originally Posted by Joe Ross
At kickoff, they mentioned a short pause between autonomous and human mode.

It's in the manual.
Quote:

Originally Posted by 4.2.2 Match Format
...Note that there may be a very short pause between the AUTONOMOUS PERIOD and the start of teleoperated play, as the Driver Station controls are activated and the referees determine the VISION TETRA placement and award bonus TETRAS.


Moloch 17-02-2005 16:27

Re: Use of Functions in Autonomous
 
I didnt want to create another thread for this so heres a question for you guys. I am using two encoders and a gyro and am going to run the scripts from the command.h file. Now, to call those functions to see if they work will this code work in my user_routines_fast.c file:

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(rc_dig_in16 = 1)
{

robot_control();

}
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}


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

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi