I’ll cut straight to the chase:
void OperatorControl ( unsigned long ulTime )
while ( 1 )
limit = GetDigitalInput (10 ) ;
limit2 = GetDigitalInput (11 ) ;
if ( limit == 0 )
SetMotor (5 , 0 ) ;
if ( limit2 == 0 )
SetMotor ( 5 , 255 )
Tank4 ( 1 , 3 , 2 , 1 , 2 , 3 , 4 , 0 , 0 , 0 , 0 ) ;
Tank2 ( 2 , 3 , 2 , 6 , 7 , 0 , 0 ) ;
MotorRcControl ( 2 , 4 , 5 , 0 ) ;
so the idea is to have 2 limit switches and 3 motors. motors 1-4 are for driving and are standard. motor 5 is supposed to override the operator (on only motor 5 and nothing else) and turn counterclockwise if limit is tripped and clockwise if limit2 is tripped. The operator control on motor 5 is overridden until the limit switches are released again, and everything goes back to normal. motors 6 and 7 are on the same transmitter as 5, but everything is normal with them. So I know that there is a simple solution, but when I try it out, motor 5 freaks out and the limit switches have no apparent effect on anything. Any suggestions are appreciated!
ports 10 and 11 on the controller might not be availible for digital input, in the sample file, ports 5,6 are used. also i dont think you need the else statement for the rc control blocks.
Right now in your code, if either limit switch is pressed and held down, the robot will never be able to drive any motor.
Also, if you ever need to override the operator’s values for any reason, never use a Tank(), Arcade(), OItoPWM(), or MotorRcControl() block and then try to override that with a SetMotor() or SetPWM(). Instead, get the operator value, set it to a variable, modify the variable as needed, and then set that variable to the motor.
Try something like this instead:
void OperatorControl (unsigned long ulTime)
char limit_1; // Since the values you are getting back are only 0 or 1, you can declare your variable as a char instead of an int to save memory
unsigned char arm_motor;
// Set up your robot drive train tank mode blocks.
Tank4 (your own settings...) ;
// Now we get the values that we want to set the arm motor to
arm_motor = GetRXInput(your own settings...);
// And now we check the limit switches
limit_1 = GetDigitalInput(your own settings...);
limit_2 = GetDigitalInput(your own settings...);
// Do we need to override the motor value
if (limit_1 == 0)
arm_motor = 0;
if (limit_2 == 0)
arm_motor = 255;
// Set motor 5
wow, thanks a lot for the help guys!