![]() |
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?
|
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) |
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. |
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: |
Re: Use of Functions in Autonomous
Quote:
|
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 ) |
Re: Use of Functions in Autonomous
Quote:
|
Re: Use of Functions in Autonomous
Quote:
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?) |
Re: Use of Functions in Autonomous
Quote:
|
Re: Use of Functions in Autonomous
Quote:
|
Re: Use of Functions in Autonomous
Quote:
Quote:
|
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