Go to Post Anyone who makes a minibot that poots out another minibot that blows the wall apart deserves to have it displayed in the Smithsonian. - Koko Ed [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 15-02-2005, 19:05
VideoMan053's Avatar
VideoMan053 VideoMan053 is offline
Computer Freak
AKA: Dan J.
FRC #0063 (Red Barons)
Team Role: Alumni
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Erie, Pennsylvania
Posts: 18
VideoMan053 is an unknown quantity at this point
Send a message via AIM to VideoMan053
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?
__________________
GET OVER IT! ~ not the most useful words in competitions, but some of the most useful in life!
My Jobs: Programming
  #2   Spotlight this post!  
Unread 16-02-2005, 01:54
ace123's Avatar
ace123 ace123 is offline
Registered User
AKA: Patrick Horn
FRC #0008 (Paly Robotics - http://robotics.paly.net/)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Palo Alto, CA
Posts: 50
ace123 has a spectacular aura aboutace123 has a spectacular aura about
Send a message via AIM to ace123
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.
__________________
-Patrick Horn, Paly Robotics

Check out the space simulator called Vega Strike, modelled after the space simulator games Elite and Wing Commander. It's Open Source too!
If you have ever played Wing Commander, or especially Privateer, and had a feeling of nostalga derived from the you will enjoy these two Vega Strike mods: Privateer Gemini Gold and Privateer Remake!
I'm working on adding multiplayer support this year...
  #3   Spotlight this post!  
Unread 16-02-2005, 08:23
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: 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.
  #4   Spotlight this post!  
Unread 16-02-2005, 11:21
phillutz phillutz is offline
Registered User
FRC #0851 (The Froggers)
Team Role: Mentor
 
Join Date: Nov 2004
Rookie Year: 2004
Location: El Segundo,CA
Posts: 28
phillutz is on a distinguished road
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)
  #5   Spotlight this post!  
Unread 16-02-2005, 11:25
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
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)
Why do you say the robots will be disabled at the end of autonomous mode?
__________________
-
An ounce of perception is worth a pound of obscure.
  #6   Spotlight this post!  
Unread 16-02-2005, 12:54
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
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...?
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #7   Spotlight this post!  
Unread 16-02-2005, 16:04
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
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.
  #8   Spotlight this post!  
Unread 16-02-2005, 16:15
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: 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?)
  #9   Spotlight this post!  
Unread 17-02-2005, 09:01
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,586
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
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.
  #10   Spotlight this post!  
Unread 17-02-2005, 10:38
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
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.
  #11   Spotlight this post!  
Unread 17-02-2005, 11:37
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: 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.
  #12   Spotlight this post!  
Unread 17-02-2005, 16:27
Moloch's Avatar
Moloch Moloch is offline
Registered User
no team
 
Join Date: Feb 2005
Location: Michigan
Posts: 39
Moloch can only hope to improve
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! */
}
}
}
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
Updated: Serial Port Driver Code Kevin Watson Programming 4 05-02-2005 18:39
Wolrd Triple Play Autonomous Mode (WAM) Standards Natchez General Forum 3 11-01-2005 15:52
Despite what IFI says, you can configure autonomous from OI... TedP Programming 19 31-03-2004 10:09
autonomous mode problem on field Chris_C Programming 17 26-03-2003 19:11


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

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