What do you guys use the pre-autonomous code block for in robotC?
I just keep it blank, is that okay?
Well I suppose it gets executed before the autonomous starts, so if you want to run anything before the match, you can do it there? I don’t know that we have ever made use of it, however I would like to know exactly when the preAuton task gets executed, as I have some ideas of things I would like to do using it. However, these mostly relate to custom sensors, so I doubt there is much of a use for it at high school level. But, you never know what clever ideas people come up with.
pre_auton() is discussed a bit on this thread. Just searching for “pre_auton” yields several relevant threads.
Perhaps this would be a good place to display battery levels on the LCD, so you can check the reported voltages just before the match.
Also a good place to read any jumpers, and possibly present feedback to the user that they read OK (message on the LCD, or flashing an LED some number of times).
If you have any complex data structures, you could set those up and save yourself a few precious microseconds of auton time.
Cheers,
- Dean
I’ve used it to create an autonomous selection routine with the LCD… I have also used it to “reset” a gyro, and to clear a motor encoder.
Basically, you can use it to do anything that doesn’t require a motor.
Re: when it runs - in my experience, it runs as soon as the robot is connected to the joystick for the first time. For example:
- Robot and joystick are turned on.
- Robot and joystick connect
- pre_auton() starts
- Robot and joystick disconnect (pre_auton() is still running)
- Robot and joystick reconnect.
- Field control sys activates autonomous mode
- If pre_auton() is over, autonomous begins.
Note that pre_auton() must terminate before the autonomous task will run. This causes issues if you put an infinite loop in pre_auton… :rolleyes:
//Andrew
This is true. If you use ROBOTC, and you want code that continuously does something during the time between turning your robot on and and the time Autonomous starts, you could put this into pre_auton():
while (bIfiRobotDisabled)
{
// Stuff to loop (I.E. Checking sensors)
}
This executes the code inside the loop while the robot is disabled. As soon as Autonomous starts, the loop exits.
(EasyC has a similar feature as well I believe.)
Alternatively, you could define and start a task that contains a loop doing things you want it to do during pre_auton()
Oooh… I should do that… nothing is as bad as forgetting to press the auton button on your robot, and not having the robot start moving…
Thanks!
//Andrew
We use pre-autonomous in EasyC to select between different autonomous routines and indicate which one has been selected, described here.
Certain Devices that need at least a One Time Initialization before use, like the Optical Encoders and Counters and Interrupts would be Setup here as well. Plus, as Quazar stated, it will save you the Time you would spend Initializing them later in the Autonomous or Usercontrol sections.
To reach the Optimum Effectiveness of an Embedded Control System, it requires you doing what you need, when you need, and preferably, no more.
If you don’t need to clear a block of Memory, don’t… Or reinitialize Variables or Devices you don’t need. For most tasks you will encounter, your Vex Controller will have way more Speed and Power than you need… But when you start pushing the limits, you will need to keep in mind all that is going on in it, and keep reducing the Inefficient Code to the Minimum…
and yes…
It is OK to leave it blank…
I cannot find the pre_auton section on EasyC v4. Is it under a different name?
EDIT: oh wait! It is initialize isnt it?
Why, yes! Yes it Is…
Keep up the Good Work…
Thanks! When I saw the name I thought I was missing something but then I realized that I already use initialize for all my sensors. :rolleyes: