UNOFFICIAL answer to Programming buttons

@stewa007 posted in the official RobotC tech support channel:

if (vexRT[Btn5U]==1) {
   motor[LeftArm]=127;
}
else if (vexRT[Btn5D]==1){
   motor[LeftArm]=-127;
}
else {
   motor[LeftArm]=0;
}
if (vexRT[Btn6U]==1){
   motor[RightArm]=127;
}
else if (vexRT[Btn6D]==1){
   motor[RightArm]=-127;
}
else{
   motor[RightArm]=0;
}

  1. To help the people who are helping you, please wrap your code inside opening & closing code tags (or highlight all of the code &
    press the </> button in the menu bar.

  2. Does it compile?

  3. Is all of the above code inside a giant while loop? something like

while (1) {  
   all that code goes here 
} 

If your joystick code were inside the loop, but this code was outside the while loop, that would result in what you’re describing.

  1. Can you describe more about the robot? Without context, it’s hard to imagine what these motors do, when they do work. Which arm was connected to which channel on the joystick when it was working? It seems like you have 2 not-connected-to-each-other arms, yes?

More context would help.

Thanks for trying to help.

  1. Yes it compiles with no errors.
  2. Yes everything is in a giant loop.
  3. Yes I have 2 not-connected-to-each-other arms. Ports 2-5 are wheels, 6 is left arm, 7 is right arm and 8 is claw. I’ll paste a copy of the whole program.

#pragma config(Motor, motor2, FrontRight, tmotorVexIQ, openLoop, reversed)
#pragma config(Motor, motor3, BackRight, tmotorVexIQ, openLoop, reversed)
#pragma config(Motor, motor4, FrontLeft, tmotorVexIQ, openLoop, reversed)
#pragma config(Motor, motor5, BackLeft, tmotorVexIQ, openLoop, reversed)
#pragma config(Motor, motor6, LeftArm, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor7, RightArm, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor8, Claw, tmotorVexIQ, PIDControl, reversed, encoder)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
motor[FrontRight]= 127;
motor[BackRight]= 127;
motor[FrontLeft]= 127;
motor[BackLeft]= 127;
motor[LeftArm]= 127;
motor[RightArm]= 127;
motor[Claw]=80;

while(true)
{
  motor[FrontLeft]=vexRT[Ch2]-vexRT[Ch1];
	motor[FrontRight]=vexRT[Ch2]+vexRT[Ch1];
	motor[BackLeft]=vexRT[Ch2]-vexRT[Ch1];
	motor[BackRight]=vexRT[Ch2]+vexRT[Ch1];

	if (vexRT[Btn7U]==1)
	{
		motor[Claw]=80;

	}
	else if (vexRT[Btn7D]==1)
	{
		motor[Claw]=-80;

	}
	else
	{
		motor[Claw]=0;
	}
	if (vexRT[Btn5U]==1)
	{
		motor[LeftArm]=127;

	}
	else if (vexRT[Btn5D]==1)
	{
		motor[LeftArm]=-127;
		}
	else
	{
		motor[LeftArm]=0;
	}
	if (vexRT[Btn6U]==1)
	{
		motor[RightArm]=127;

	}
	else if (vexRT[Btn6D]==1)
	{
		motor[RightArm]=-127;
		}
	else
	{
		motor[RightArm]=0;
	}

}

}

OK - here’s your pseudo-code, which does seem to look OK.

task main() {
   turn on chassis, all 127 forward
   turn on both arms, 127
   turn on claw, 80 power

while(true) {
   chassis arcade drive; set motors based on Channel 1/2 joystick control

   set claw power based on Buttons 7U & 7D
   if no buttons pressed, set claw to 0

   set LeftArm based on buttons 5U & 5D
   set LeftArm to 0 if neither button pressed

   set RightArm based on buttons 6U and 6D
   set RightArm to 0 if neither button pressed
}
}

So when you connect your arms to the joystick control, instead of buttons, what does that code look like?

Please paste your code then highlight all of the code and press the button in the toolbar that looks like this < /> and then it will appear like it does above. Thanks!

Another thought – have you tried other buttons on the joystick, other than 5 & 6? Perhaps your joystick has a physical problem?

To test the arms to make sure they worked, I disconnected everything out of the ports. I put the arms in ports 2 and 3 which controls the wheels for the right side of the robot. I did the same thing for the claw to make sure all motors are actually working. I ran the program on another robot and the same thing happens. So it’s not the joystick. I also tried all buttons, 5, 6, 7, and 8. So the only programming I had to test the arms was what I used for the wheels. I’ll paste it. Also, at one point when on the phone with Vex we reset the robot to original settings and the button would work then. I don’t remember what all he told me to do because I tried to just get it back like that but can’t. Once I put a program on it, the buttons won’t work.

Where is the menu bar you are referring to? I don’t see anything like that on my screen. I highlight but nothing else comes up.

while(true)
{
motor[FrontLeft]=vexRT[Ch2]-vexRT[Ch1];
motor[FrontRight]=vexRT[Ch2]+vexRT[Ch1];

I just found the code you are talking about on the menu bar - the angle my screen was at was blocking my view of it - sorry

while(true)
{
motor[FrontLeft]=vexRT[Ch2]-vexRT[Ch1];
motor[FrontRight]=vexRT[Ch2]+vexRT[Ch1];

I don’t mean to be a bother but I’m getting desperate lol

Why are all your motors set as VexIQ ?

#pragma config(Motor, motor2, FrontRight, tmotorVexIQ, openLoop, reversed)
#pragma config(Motor, motor3, BackRight, tmotorVexIQ, openLoop, reversed)
#pragma config(Motor, motor4, FrontLeft, tmotorVexIQ, openLoop, reversed)
#pragma config(Motor, motor5, BackLeft, tmotorVexIQ, openLoop, reversed)
#pragma config(Motor, motor6, LeftArm, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor7, RightArm, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor8, Claw, tmotorVexIQ, PIDControl, reversed, encoder)

Go into motors&setup and change everything to 393 motors (it should do that just by opening the dialog)

Other than that I just tried the code and it works here OK.
Except, you have PID control turned on, so turn that off as well.
This is what you want to see (not sure of you really want the reversed flag set everywhere)

#pragma config(Motor,  port2,           FrontRight,    tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor,  port3,           BackRight,     tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor,  port4,           FrontLeft,     tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor,  port5,           BackLeft,      tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor,  port6,           LeftArm,       tmotorVex393_HBridge, openLoop, reversed, encoderPort, None)
#pragma config(Motor,  port7,           RightArm,      tmotorVex393_HBridge, openLoop, reversed, encoderPort, None)
#pragma config(Motor,  port8,           Claw,          tmotorVex393_HBridge, openLoop, reversed, encoderPort, None)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//