I have a year of experience with RobotC (teaching PLTW POE) in both autonomous and driver control mode, but I am a newbie at coding for switching modes. So, I have a few questions.
How does the actual switch from autonomous mode to driver control occur in competition?
When starting in autonomous mode, is the team allowed to hit a bump switch or something to start?
I am assuming one file with both types of code is loaded onto the cortex. Does anyone have a template they’d be willing to share from an old event or something that would show me how the two types of code are laid out in one program?
You need to program your robot in the Competition Template. There is a section in the template for autonomous and for driver-control. When coming to the field, your students will connect their joystick to the field controller. The field control computer will lock out the joystick during autonomous and enable it during driver control, then shuts it down at the end of driver control. The students need not hit a switch. You can find the competition template by going to File > Open Sample Programs > Templates > Vex_competition_template.c. Make sure you save any changes as a different file.
All the code gets loaded into the Cortex. The switch tells the competition template code which task to run. It turns on the auton task when it receives the auton switch and runs the user control task when it gets that command. If neither case, the motors are forced off.
The diagram in the link below shows the switch. Basically it puts one wire to ground and the competition template sees that and puts you into one of the modes. The joystick sees that and sends the value back to the Cortex of the intent of the competition switch.
In the unlikely case where both went to ground (if you built your own), you would have to look at the competition code template you include to see what wins. (who is first condition in the if statements or case statement)
I think the answers here went deeper than the OP’s question.
In a competition, the tournament manager software will automatically start the autonomous period, then after scoring is done, automatically starts driver-control until the end of the match. The teams don’t need to do anything. For practice (and usually on the programming skills field) you can get a switch: for your teams to use for testing.
Actually, in ROBOTC, all you have to do is go to File > New… > Competition Template. The file is very well commented any will explain where to put your autonomous code and where to put driver control code.
If you don’t have a competition switch, a quick way to test your autonomous code is to add this to your usercontrol task:
stopTask(usercontrol); //prevents user control code from interfering with autonomous movements
Just make sure to remove that when you’re done testing!
During autonomous mode this year, no interaction with the robot is permitted, whatsoever. See rule G8:
Also, I believe it’s the master firmware, not the field control computer, that blocks joystick input during autonomous and stops the motors when the robot should be disabled. The actual field controller (jpearman’s posts explain this in more detail) is really just saying, “Time for autonomous” or “Time for driver control,” with the rest up to the firmware and the VEX Competition Includes file.
I’ve looked at the field controller documentation and read the links above. Am I correct to assume that this the correct sequence of commands during a match:
(1) all robots are disabled
(2) match operator presses “start” in tournament manager to start autonomous. (This also enables the robots)
(3) after autonomous, everything is paused (but robots are not “disabled”)
(4) match operator presses “resume” in tournament manager and driver controller period starts.
The reason I am asking is because I can’t tell if the robots are disabled again (bIfiRobotDisabled flag set to true) after autonomous or if the pause in tournament manager accomplishes the same thing. So if I put “if(blfiRobotDisabled == true)” in my preautonomous, will the preautonomous code try to run again in between autonomous and driver control?
Also, if I use a competition switch, none of these flags are present - correct? So the only way to test whether the if statement works - “if(blfiRobotDisabled == true)” - is on an actual field controller. This kind of makes me nervous since I won’t know what will happen until the match starts - and if it doesn’t work, it could ruin the match! Any suggestions?
What evan10s describes looks like the sequence during a match would be:
starting state: switch 1 disabled
step 1: switch 1 - enabled
step 2: switch 2 - enable autonomous
step 3: switch 1 - disable
step 4: switch 1 - enable
step 5: switch 2 - enable driver control
However, in looking at the field controller software, it kind of looks like this would be the sequence:
starting state: switch 1 disabled
step 1: switch 2 - enabled (this also enables switch 1)
step 2: operator presses “start” in tournament manager and this starts autonomous (switch 1 remains enabled)
step 3: after counting autonomous score, operator presses “resume” in tournament manager and this starts driver control (switch 1 remains enabled)
step 4: switch 1- are robots disabled after the end of driver control??
I see it more as the switches start in Disabled/Autonomous.
Step 1: Enable robots, starting autonomous
Step 2: Disable robots
Step 3: Switch to Driver Control
Step 4: Enable robots
Step 5: Disable Robots.
My method is only change between Driver and Autonomous while the robot is disabled. That’s what we do with our competition test switch. Flipping between Autonomous and Driver Control while enabled usually has undesirable results.
You are over analyzing this, there are really only three mode the robot can be in.
enabled in autonomous
enabled in driver control.
The bIfiRobotDisabled flag will always be set if the robot is disabled, the pre-auton code will only run once when the robot is reset (ie. turned on and connects to VEXnet, unless low battery or other issues causes a reset).
The competition switch will simulate field control with the exception that field control will place your robot on a special “competition” radio channel, the selection of disabled/auton/driver is exactly the same.