RobotC Programming Question?

Our team frequently has either one or multiple people working on the robot. I’m curious if it is possible to detect whether or not there is a partner remote in order to change the remote button programming. In pseudocode, it would be something like this:


if (there is not two remotes)
{
   while (true)
   {
       ...remote button programming... 
   }
}

else
{
   while (true)
   {
       ...button programming for two remotes...
   }
}

If you could help me with this I would really appreciate it!

Yes, for example.

    if( nVexRCReceiveState & vrXmit2 )
        writeDebugStreamLine("Transmitter 2 connected");

See this post for more details.
https://vexforum.com/showpost.php?p=327629&postcount=136

Thanks for the reply! I am really new to coding, so if you could help me apply it to my specific usage, that would really help me. For instance, I do not understand how the writeDebugStreamLine(“Transmitter 2 connected”); part fits in exactly. Thanks again!

I think “writeDebugStreamLine(“Transmitter 2 connected”);” is just test code-- it’s just used to tell the programmer where the program is basically.
(more specifically it prints “Transmitter 2 connected” to something called a Debug Stream. Basically if the programmer opens up the debug stream window he can see whatever “writeDebugStreamLine(…)” prints in real time. This can be used to tell where the program is in real time)

Just replace that part with whatever you want (i.e. while(true){…})

Ok I suspected that but like I said I’m really new to programming so I wasn’t sure. What exactly is the breakdown of the meaning of nVexRCReceiveState & vrXmit2 ?

writeDebugStreamLine had nothing to do with it, just an example showing how to test for the partner joystick bit being present in the nVexRCReceiveState variable.

Here.

task main()
{
    bool  partnerJoystickIsPresent = false;
    
    // Check at beginning of the code for the partner joystick
    if( (nVexRCReceiveState & vrXmit2) == vrXmit2 )
        partnerJoystickIsPresent = true;
    
    // Driver control
    while(true)
        {
        // Tank drive, main joystick
        motor port1 ]  = vexRT Ch2 ];
        motor port10 ] = vexRT Ch3 ];
        
        if( partnerJoystickIsPresent )
            {
            // partner joystick is present
            // Let it control the lift
            if( vexRT Btn6UXmtr2 ] == 1 )
                motor port4 ] = 127;
            else
            if( vexRT Btn6DXmtr2 ] == 1 )
                motor port4 ] = -127;
            else
                motor port4 ] = 0;
            }
        else
            {
            // We control the lift using main joystick as partner
            // is not available
            if( vexRT Btn6U ] == 1 )
                motor port4 ] = 127;
            else
            if( vexRT Btn6D ] == 1 )
                motor port4 ] = -127;
            else
                motor port4 ] = 0;            
            }
            
        // Don't hog the cpu
        wait1Msec(25);
        }
}

Okay I understand this much better now! Thanks!

Okay so I tried to implement what I’ve learned from this thread, and it will not allow me to use the partner remote at all or the functionality of anything past the drive. Essentially, anything dependant on whether or not there is a partner remote will NOT work. Here’s the code:


task usercontrol()
{
	bool  partnerJoystickIsPresent = false;
    
  // Check at beginning of the code for the partner joystick
  if((nVexRCReceiveState & vrXmit2) == vrXmit2)
  {
  	partnerJoystickIsPresent = true;
    
    // Driver control
    while(true)
    {
    	// Tank drive, main joystick
			motor[LFrontDrive] = vexRT[Ch3];
			motor[LMidDrive] = vexRT[Ch3];
			motor[LBackDrive] = vexRT[Ch3];
			motor[RFrontDrive] = vexRT[Ch2];
			motor[RMidDrive] = vexRT[Ch2];
			motor[RBackDrive] = vexRT[Ch2];
    }
        
    if(partnerJoystickIsPresent == true)
    {
    	//Lift
			motor[LLift] = vexRT[Ch3Xmtr2];
			motor[RLift] = vexRT[Ch3Xmtr2];
					
			//Intake
			motor[RIntake] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
			motor[LIntake] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
					
			if(vexRT[Btn6U] == 1)         // If button 6U (upper right shoulder button) is pressed:
    	{
      	SensorValue[solenoid] = 1;  // ...activate the solenoid.
    	}
    
   		else
   		{
    		SensorValue[solenoid] = 0;
    	}
    }
         
    else
    {
    	//Lift
      if( vexRT Btn5U ] == 1 )
      {
      	motor[LLift] = 127;
        motor[RLift] = 127;
      }

      if( vexRT Btn5D ] == 1 )
      {
      	motor[LLift] = -100;
        motor[RLift] = -100;
      }           
          	
      if(vexRT[Btn6U] == 1)
      {
      	motor[LIntake] = 127;
        motor[RIntake] = 127;
      }
          	
      if(vexRT[Btn6D] == 1)
      {
      	motor[LIntake] = -127;
        motor[RIntake] = -127;
      }
              
      if((vexRT[Btn6U] == 1) && (vexRT[Btn6D] == 1))         // If button 6U (upper right shoulder button) is pressed:
    	{
      	SensorValue[solenoid] = 1;  // ...activate the solenoid.
    	}
    
   		else
   		{
    		SensorValue[solenoid] = 0;
    	}
  	}
    // Don't hog the cpu
    wait1Msec(25);
  }
}

if((nVexRCReceiveState & vrXmit2) == vrXmit2)

should be just


if(nVexRCReceiveState & vrXmit2)

I know it’s weird that it’s only one & instead of && but & is a bitwise AND (comparing bits). I’m not too familiar with bitwise stuff to explain more though.

EDIT: Actually I’m not sure about this but try it. Source

It does exactly the same thing.

this

if(nVexRCReceiveState & vrXmit2)

will be either 0 or 2 (vrXmit2 is 2)

this


if((nVexRCReceiveState & vrXmit2) == vrXmit2)

compares the result of the bitwise and to 2, so the result will be either 0 or 1 (false or true).

The OPs problem is that this code blocks.

    // Driver control
    while(true)
    {
    	// Tank drive, main joystick
			motor[LFrontDrive] = vexRT[Ch3];
			motor[LMidDrive] = vexRT[Ch3];
			motor[LBackDrive] = vexRT[Ch3];
			motor[RFrontDrive] = vexRT[Ch2];
			motor[RMidDrive] = vexRT[Ch2];
			motor[RBackDrive] = vexRT[Ch2];
    }

I will post revised code later if you have not figured it out.

Oh ok makes sense

Revised code, it can still be improved :slight_smile: You had (and still have with this version) the solenoid and intake on button 6U and 6D when not using two joysticks, choose another button.

task usercontrol()
{
    bool  partnerJoystickIsPresent = false;
    
    // Check at beginning of the code for the partner joystick
    if((nVexRCReceiveState & vrXmit2) == vrXmit2)
        partnerJoystickIsPresent = true;
    
    // Driver control
    while(true)
        {
        // Tank drive, main joystick
        motor[LFrontDrive] = vexRT[Ch3];
        motor[LMidDrive]   = vexRT[Ch3];
        motor[LBackDrive]  = vexRT[Ch3];
        
        motor[RFrontDrive] = vexRT[Ch2];
        motor[RMidDrive]   = vexRT[Ch2];
        motor[RBackDrive]  = vexRT[Ch2];
        
        // Solenoid, main joystick
        if(vexRT[Btn6U] == 1)         // If button 6U (upper right shoulder button) is pressed:
            SensorValue[solenoid] = 1;  // ...activate the solenoid.
        else
            SensorValue[solenoid] = 0;
    
        // Lift and intake
        if(partnerJoystickIsPresent == true)
            {
            //Lift
            motor[LLift] = vexRT[Ch3Xmtr2];
            motor[RLift] = vexRT[Ch3Xmtr2];
                    
            //Intake
            motor[RIntake] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
            motor[LIntake] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;                   
            }
        else
            {
            //Lift
            if( vexRT Btn5U ] == 1 )
                {
                motor[LLift] = 127;
                motor[RLift] = 127;
                }
            else
            if( vexRT Btn5D ] == 1 )
                {
                motor[LLift] = -100;
                motor[RLift] = -100;
                }           
            else
                {
                motor[LLift] = 0;
                motor[RLift] = 0;
                }
            
            // Intake
            if(vexRT[Btn6U] == 1)
                {
                motor[LIntake] = 127;
                motor[RIntake] = 127;
                }
            else            
            if(vexRT[Btn6D] == 1)
                {
                motor[LIntake] = -127;
                motor[RIntake] = -127;
                }
            else
                {
                motor[LIntake] = 0;
                motor[RIntake] = 0;
                }             
            }
            
    // Don't hog the cpu
    wait1Msec(25);
    }
}

The idea was that I would be able to launch while I’m driving but since its only testing it should be fine.

Btw thanks for all your help! I’ll post on here later as to whether or not it is working completely fine.

The code detects and changes button programming perfectly now. The only problem is that buttons 5U and 6U will not work, even though the if else statements for them are in the same section as all the rest of the if else statements for the other buttons which do work. It consistently is those two buttons. I’m pretty sure it isn’t the controller.


/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
	bool  partnerJoystickIsPresent;
    
  // Check at beginning of the code for the partner joystick
  if((nVexRCReceiveState & vrXmit2) == vrXmit2)
  {
  	partnerJoystickIsPresent = true;
  }
  else
  {
  	partnerJoystickIsPresent = false;
  }
  
  while(true)
  {
  	// Driver control
	  while(partnerJoystickIsPresent == true)
  	{
   		// Tank drive, main joystick
			motor[LFrontDrive] = vexRT[Ch3];
			motor[LMidDrive] = vexRT[Ch3];
			motor[LBackDrive] = vexRT[Ch3];
			
			motor[RFrontDrive] = vexRT[Ch2];
			motor[RMidDrive] = vexRT[Ch2];
			motor[RBackDrive] = vexRT[Ch2];
        
  	 	//Lift
			motor[LLift] = vexRT[Ch3Xmtr2];
			motor[RLift] = vexRT[Ch3Xmtr2];
				
			//Intake
			motor[RIntake] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
			motor[LIntake] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
						
			if(vexRT[Btn6UXmtr2] == 1)         // If button 6U (upper right shoulder button) is pressed:
  	 	{
  	   	SensorValue[solenoid] = 1;  // ...activate the solenoid.
  	 	}
    
  		else
  		{
  	 		SensorValue[solenoid] = 0;
  	 	}
    	
  	 	//check to see if there is one or two controllers again  
  	 	if((nVexRCReceiveState & vrXmit2) == vrXmit2)
 		 	{
 				partnerJoystickIsPresent = true;
  		}
  		else
  		{
  			partnerJoystickIsPresent = false;
  		}
  			
  		wait1Msec(25);
  	}
  	       
  	while(partnerJoystickIsPresent == false)
  	{
  	 	// Tank drive, main joystick
			motor[LFrontDrive] = vexRT[Ch3];
			motor[LMidDrive] = vexRT[Ch3];
			motor[LBackDrive] = vexRT[Ch3];
				
			motor[RFrontDrive] = vexRT[Ch2];
			motor[RMidDrive] = vexRT[Ch2];
			motor[RBackDrive] = vexRT[Ch2];
  	  
  	 	//Lift
 	  	if( vexRT Btn5U ] == 1 )
 	   	{
  	  	motor[LLift] = 127;
  	    motor[RLift] = 127;
  	 	}
  	 	else
 			{
 	   		motor[LLift] = 0;
  	    motor[RLift] = 0;
    	}

 	  	if( vexRT Btn5D ] == 1 )
 		  {
   		 	motor[LLift] = -100;
    	  motor[RLift] = -100;
    	}           
    	else
    	{
    		motor[LLift] = 0;
    	  motor[RLift] = 0;
    	}
          	
    	//intake
    	if(vexRT[Btn6U] == 1)
    	{
    		motor[LIntake] = 127;
    	  motor[RIntake] = 127;
    	}
    	else
    	{
    	 	motor[LIntake] = 0;
    	  motor[RIntake] = 0;
    	}
    	     	
    	if(vexRT[Btn6D] == 1)
    	{
    		motor[LIntake] = -127;
    	  motor[RIntake] = -127;
    	}
    	else
    	{
	  		motor[LIntake] = 0;
    	 	motor[RIntake] = 0;
    	}
    	         
    	//launcher
    	if(vexRT[Btn8D] == 1)
   		{
    	 	SensorValue[solenoid] = 1;
   		}
    	
  		else
  		{
   			SensorValue[solenoid] = 0;
   		}
   		//check to see if there is one or two controllers again  
   		if((nVexRCReceiveState & vrXmit2) == vrXmit2)
 	 		{
 				partnerJoystickIsPresent = true;
  		}
  		else
  		{
  			partnerJoystickIsPresent = false;
  		}
  		
  		wait1Msec(25);
  	}
	}
}

You have an “else” statement with both the up and down buttons, this forces the motors to 0 when that’s not what you intended. Revised code.

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
    bool  partnerJoystickIsPresent;
    
    // Check at beginning of the code for the partner joystick
    if((nVexRCReceiveState & vrXmit2) == vrXmit2)
        partnerJoystickIsPresent = true;
    else
        partnerJoystickIsPresent = false;

    while(true)
        {
        // Driver control
        while(partnerJoystickIsPresent == true)
            {
            // Tank drive, main joystick
            motor[LFrontDrive] = vexRT[Ch3];
            motor[LMidDrive]   = vexRT[Ch3];
            motor[LBackDrive]  = vexRT[Ch3];
            
            motor[RFrontDrive] = vexRT[Ch2];
            motor[RMidDrive]   = vexRT[Ch2];
            motor[RBackDrive]  = vexRT[Ch2];
        
            //Lift
            motor[LLift] = vexRT[Ch3Xmtr2];
            motor[RLift] = vexRT[Ch3Xmtr2];
                
            //Intake
            motor[RIntake] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
            motor[LIntake] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
                        
            if(vexRT[Btn6UXmtr2] == 1)         // If button 6U (upper right shoulder button) is pressed:
                {
                SensorValue[solenoid] = 1;  // ...activate the solenoid.
                }
            else
                {
                SensorValue[solenoid] = 0;
                } 
        
            //check to see if there is one or two controllers again  
            if((nVexRCReceiveState & vrXmit2) == vrXmit2)
                partnerJoystickIsPresent = true; 
            else
                partnerJoystickIsPresent = false;
            
            wait1Msec(25);
            }
           
        while(partnerJoystickIsPresent == false)
            {
            // Tank drive, main joystick
            motor[LFrontDrive] = vexRT[Ch3];
            motor[LMidDrive]   = vexRT[Ch3];
            motor[LBackDrive]  = vexRT[Ch3];
                
            motor[RFrontDrive] = vexRT[Ch2];
            motor[RMidDrive]   = vexRT[Ch2];
            motor[RBackDrive]  = vexRT[Ch2];
      
            //Lift
            if( vexRT Btn5U ] == 1 )
                {
                motor[LLift] = 127;
                motor[RLift] = 127;
                }
            else
            if( vexRT Btn5D ] == 1 )
                {
                motor[LLift] = -100;
                motor[RLift] = -100;
                }           
            else
                {
                motor[LLift] = 0;
                motor[RLift] = 0;
                }
            
            //intake
            if(vexRT[Btn6U] == 1)
                {
                motor[LIntake] = 127;
                motor[RIntake] = 127;
                }
            else
            if(vexRT[Btn6D] == 1)
                {
                motor[LIntake] = -127;
                motor[RIntake] = -127;
                }
            else
                {
                motor[LIntake] = 0;
                motor[RIntake] = 0;
                }
                 
            //launcher
            if(vexRT[Btn8D] == 1)
                {
                SensorValue[solenoid] = 1;
                }   
            else
                {
                SensorValue[solenoid] = 0;
                }
            //check to see if there is one or two controllers again  
            if((nVexRCReceiveState & vrXmit2) == vrXmit2)
                partnerJoystickIsPresent = true;
            else
                partnerJoystickIsPresent = false;
        
            wait1Msec(25);
            }
        }
}

This is what your code is doing:


if button6U turn motors forward
else turn motors off
if button6d turn motors backward
else turn motors off

The else after if button6d is turning off your motors without checking whether button6u is pressed.
This is what your code should be doing:


if button6U turn motors forward
else if button6D turn motors backward
else turn motors off

Edit:
Note to self:
I should always refresh the page before posting so I don’t say the same thing as the previous poster. :stuck_out_tongue:

after if button6d is turning off your motors without checking whether button6u is pressed.
This is what your code should be doing:


if button6U turn motors forward
else if button6D turn motors backward
else turn motors off

Edit:
Note to self:
I should always refresh the page before posting so I don’t say the same thing as the previous poster. :stuck_out_tongue:

lol don’t worry your explanation really helped me. Thanks so much to both of you!