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!
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 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:
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
Revised code, it can still be improved 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.
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);
}
}
}