Controlling a claw arm with R1 and R2 using vex v5 pro

I am trying to code my robot but when I code it to go up when I hold down R1 it does not work and when I try to put it down with R2 it does not work again. If you need my code I can send a pic on Monday or Tuesday.

As with nearly all programming questions, we need to see your code to be able to offer anything other than guesses as to what is wrong.

5 Likes

i will post it later tonight

RLiftMotor.spin(vex::directionType::rev, Controller1.ButtonR1.pressing(), vex::velocityUnits::pct);
RLiftMotor.spin(vex::directionType::fwd, Controller1.ButtonR2.pressing(), vex::velocityUnits::pct);
LLiftMotor.spin(vex::directionType::rev, Controller1.ButtonR1.pressing(), vex::velocityUnits::pct);
LLiftMotor.spin(vex::directionType::fwd, Controller1.ButtonR2.pressing(), vex::velocityUnits::pct);

I just tried this and it will go up but not down and I am confused why.

if(Controller1.ButtonR1.pressing())

{

RLiftMotor.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);

}

else RLiftMotor.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);

if(Controller1.ButtonR1.pressing())

{

LLiftMotor.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);

}

else LLiftMotor.spin(vex::directionType::rev, 0, vex::velocityUnits::pct);

if(Controller1.ButtonR2.pressing())

{

RLiftMotor.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);

}

else RLiftMotor.spin(vex::directionType::rev, 0, vex::velocityUnits::pct);

if(Controller1.ButtonR2.pressing())

{

LLiftMotor.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);

}

else LLiftMotor.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);

One reason the lift might not work is if you are using 2 motors on opposite sides of the lift, but one of the sides isn’t reversed.

By this, I mean that if flipped onto the other side of the lift, one motor will spin the opposite direction even if given the same command in the code, because it is on the other side of the lift.

Here is a graphic that shows what I mean.
image
As you can see, the 2 motors are moving opposite directions.

To fix this, simply go to the device configuration in the top right of the screen and click a motor and then near the bottom of the motor identification place click “Reverse” and you can try it again. You can also just flip the direction types in the code for either the left or the right side.

Hope that helped, and good luck with programming! :grin:

3 Likes

Is this all in a forever loop?

1 Like

I have it so they are going in the same direction but they are going different speeds and i checked and all the speed and the motor ratio’s are the same but they still are different speeds we tried different ports motors and nothing fixes it. Also they will either use R1 or R2 and either go up or down but only one plz help

no it is not a forever loop

Can you post your entire code? The claw arm controls should be inside a forever loop inside of the driver control function.

void usercontrol(void)
 {
  // User control code here, inside the loop
  while(true) { 
    LFMotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
    LBMotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
    RFMotor.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);    
    RBMotor.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);
    //controlling how the arm goes up with Rliftmotor
    if(Controller1.ButtonR1.pressing())
{
    RLiftMotor.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
}
else RLiftMotor.spin(vex::directionType::rev, 0, vex::velocityUnits::pct);
//controlling how the arm goes up with LliftMotor
     if(Controller1.ButtonR1.pressing())
{
    LLiftMotor.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
}
else LLiftMotor.spin(vex::directionType::rev, 0, vex::velocityUnits::pct);
//controlling how the arm goes down with Rliftmotor  
if(Controller1.ButtonR2.pressing())
{
    RLiftMotor.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
}
else RLiftMotor.spin(vex::directionType::rev, 0, vex::velocityUnits::pct);
//controlling how the arm goes down with Lliftmotor
if(Controller1.ButtonR2.pressing())
{
    LLiftMotor.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
}
else LLiftMotor.spin(vex::directionType::rev, 0, vex::velocityUnits::pct);
     
     

        vex::task::sleep(20);

You are bracketing your if-else statements incorrectly. It should look like:

if ___{
//stuff
}
else{
//stuff
}

You could also just condense it and have both r1 and r2 control. Also, you don’t need individual statements for the two motors. You can just combine the statements together.
Changing your code:

void usercontrol(void)
{
while(true){
///drivetrain control
if(Controller1.ButtonR1.pressing()){
RLiftMotor.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
LLiftMotor.spin(vex::directionType::rev, 100, velocityUnits::pct);
}
else if(Controller1.ButtonR2.pressing()){
RLiftMotor.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
LLfitMotor.spin(vex::directionType::fwd, 100, vex::veloctyUnits::pct);
}
else{
RLiftMotor.stop(hold);
LLiftMotor.stop(hold);
}
4 Likes

I was able to figure it out with the help of a friend. He did the same thing as you so thanks for the help I really appreciate it.