Autonomous vs controller

For the two phases, autonomous and non-autonomous, does the program for each phase need to be in the cortex at the same time? Or do we get time to switch one program to the other?

There is a file in RobotC called the competition template. That is where you need to put your code for your robot. Within that template, there is a place for your autonomous program and your driver-controlled program and it gets downloaded to the as a single program. The field control then tells the robot to start and stop the autonomous part of the program, then enables the driver-control portion.

I hope this helps.

You would put it on the competition template. That’s where you can put your code. Or you can use a LCD code chooser which is a lot more programming. You would be able to put up to 4 autonomous codes onto the code chooser. If you are going to do the code chooser then pm me.

Just to clarify. You MUST put your code in the Competition Template. AND you can use a LCD panel to choose between different autonomi, if you are at that level. It is not “OR you can use an LCD chooser”.
I don’t mean to sound trollish, but the OP sounds like a newcomer and the wording of the response needs to be very clear.

Yes sorry i am just used to people knowing what i am talking about.

Unlike most programs, you don’t write the “main” or starting function. Instead you write two functions, which are usually provided for you in a template by the development environment you choose to use (ROBOTC, easyC, PROS, etc.).

There are actually two pieces of code running on the Cortex, one is talking to field control, the joystick, etc. and internally links to the other code over I2C. Messages are exchanged that allow your code to know when to run autonomous and when to run the tele-operated code.

Typically the vendor of your development environment has code that reads these messages for you and does the appropriate action. If you’re interested in specifics check out the file that PROS uses to handle messages from the other code.

Specifically:

// Run VEX daemon
static void daemon_task(void *ignore) {
	// We must wait for about 1 s to limit start up glitches before running serious stuff
	uint16_t flags;
	while (1) {
		flags = svFlags;
		if (flags & SV_FMS) {
			// On-line, read VEX mode control
			if (!(flags & SV_ENABLED))
				invDisable();
			else if (flags & SV_AUTONOMOUS)
				invStartAuto();
			else
				invStartTeleop();
			// We will be woken on the next mode change
		} else
			// Not on-line, start teleop
			invStartTeleop();
		taskSuspend(NULL);
	}
}

We dont use the compition template. Is that a problem?

It may or may not be. If you do not have any autonomous code then I guess not. The robot will still be enabled and disabled by field control, the main task will continue to run but motors and joystick will be disabled during the autonomous period. If you do have autonomous code then yes, you should be using the template.

There some discussion on the way the competition template works here (a quite old thread at this point, we have improved it slightly since 2011)
https://vexforum.com/t/the-robotc-competition-template/20175/1