View unanswered posts | View active topics It is currently Fri Dec 19, 2014 4:14 am






Reply to topic  [ 1 post ] 
Recognizing whether or not Competition Control is plugged in 
Author Message
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 619
Post Recognizing whether or not Competition Control is plugged in
The question was recently asked on the VEX forums if there was a way to use ROBOTC to check if a VEXNet-connected Joystick Controller was plugged into a Competition Switch or not. We would like to share the answer here for future reference and in case anyone had any similar questions:

Quote:

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:

Code:
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):

Image

vrNoXmiters
vrXmit1
vrXmit2
vrCompetitionSwitch
vrGameController
vrAutonomousMode
vrDisabled

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

Code:
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!

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Mon Mar 04, 2013 5:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.