Recognizing whether or not Competition Control is plugged in


#1

I was digging around in the ROBOTC intrinsics and I stumbled upon the vrCompetitionSwitch in the TVexReceiverState (line 310 in RobotCIntrinsics.c). I realized I could potentially use this to find out whether a competition switch was even plugged in. If not, the robot would skip the Pre-Autonomous function and the Autonomous function, so that we could jump straight into driver control. Can I use the vrCompetitionSwitch to achieve this, and, if so, what would be the best way to achieve this?


#2

You can absolutely use the vrCompetitionSwitch value to determine whether a switch is connected or not. To do so, you would use the ‘nVexRCReceiveState’ to evaluate the bitmasked value being sent from the VEXNet Joystick. For example:

if (nVexRCReceiveState & vrCompetitionSwitch)
{
 //Code to execute if switch is connected
}

else
{
//Code to execute if switch is not connected
}

Since you are evaluating the individual bit’s value (and not the whole bit mask), you will need to use the single ampersand (bitwise AND operation) instead of the double ampersand (logical AND operation) that is normally used in conditional statements.

There are also other values that you can check for using the ‘nVexRCReceiveState’ command, such as if a main/partner joystick is connected, if VEXNet is connected, etc (full mapping below):

http://img20.imageshack.us/img20/4791/screenshot2013030413222.png

vrNoXmiters
vrXmit1
vrXmit2
vrCompetitionSwitch
**vrGameController **
vrAutonomousMode
vrDisabled

As another example; suppose you wanted to check and display which joysticks are connected (main and partner):

task main()
{
	while(true)
	{
		clearLCDLine(0);

		if (nVexRCReceiveState & vrXmit1)
		{
			displayLCDString(0, 0, "Joystick 1");
		}

		else
		{
			displayLCDString(0, 0, " ");
		}
		

                if (nVexRCReceiveState & vrXmit2)
		{
			displayLCDString(1, 0, "Joystick 2");
		}

		else
		{
			displayLCDString(1, 0, " ");
		}
		wait1Msec(20);
	}
}

This code will first check for the main joystick and display if it is connected on the first line of the LCD screen, then check for a partner joystick and display if it is connected on the second line of the LCD screen.

Let us know if you have any other questions on this, we are more than happy to help!