Our arm 1 is not working

Our arm 1 is not working. Can someone please help?

using namespace vex;
vex::motor Frontleftmotor (vex::PORT1, vex::gearSetting::ratio18_1, false);
vex::motor Frontrightmotor (vex::PORT2, vex::gearSetting::ratio18_1, true);
vex::motor Backleftmotor (vex::PORT3, vex::gearSetting::ratio18_1, false);
vex::motor Backrightmotor (vex::PORT4, vex::gearSetting::ratio18_1, true);
vex::motor Arm1 (vex::PORT5, vex::gearSetting::ratio18_1, true);
vex::motor Arm2 (vex::PORT6, vex::gearSetting::ratio18_1, true);
vex::motor Claw1 (vex::PORT7, vex::gearSetting::ratio18_1, true);
vex::motor Claw2 (vex::PORT8, vex::gearSetting::ratio18_1, true);
vex::motor Capflipper (vex::PORT9, vex::gearSetting::ratio18_1, true);
#include “robot-config.h”

int main() {

while(true) {
    Backleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis3+Axis4)/2
    Backrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);//(Axis1-Axis2)/2
    Frontleftmotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis2+Axis1)/2
    Frontrightmotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct); //(Axis4+Axis3)/2
    
    vex::task::sleep(20); 
    
    


if(Controller1.ButtonX.pressing())

{
Arm1.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}
if(!Controller1.ButtonX.pressing())
{
Arm1.stop();
}

else if (Controller1.ButtonB.pressing())
{
    Arm1.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
    
}
  if(!Controller1.ButtonB.pressing())

{
Arm1.stop();
}
if(Controller1.ButtonX.pressing())
{
Arm2.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
vex::task::sleep(20);
}
if(!Controller1.ButtonX.pressing())
{
Arm2.stop();
}
else if (Controller1.ButtonB.pressing())
{
Arm2.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
vex::task::sleep(20);
}
if(!Controller1.ButtonB.pressing())
{
Arm2.stop();
}
if(Controller1.ButtonR1.pressing())
{
Claw1.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);

    }
    if(!Controller1.ButtonR1.pressing())

{
Claw1.stop();
}
else if (Controller1.ButtonR2.pressing())
{
Claw1.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);

    }
    if(!Controller1.ButtonR2.pressing())

{
Claw1.stop();
}
if(Controller1.ButtonR1.pressing())
{
Claw2.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);

    }
    if(!Controller1.ButtonR1.pressing())

{
Claw2.stop();
}
else if(Controller1.ButtonR2.pressing())
{
Claw2.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);

    }
    if(!Controller1.ButtonR2.pressing())

{
Claw2.stop();
}
if(Controller1.ButtonL1.pressing())
{
Capflipper.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);

    }
    if(!Controller1.ButtonL1.pressing())

{
Capflipper.stop();
}
else if(Controller1.ButtonL2.pressing())
{
Capflipper.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
}
if(!Controller1.ButtonL2.pressing())
{
Capflipper.stop();
}

}

}

I don’t believe any of these motors will work correctly. You should have one single if…else if…else control structure for each motor. All of your motors here have multiple if… control blocks. This will cause conflicting commands to the motors in rapid succession, and unintended behavior. Like your reverse for arm1 (b pressed) only being reachable if it is also being told to go forward (x pressed).

Here’s an example of a motor controlled by two buttons with no conflicts:

if (button1 && !button2) {
    mMotor.spin(fwd);
} else if (!button1 && button2) {
    mMotor.spin(rev);
} else {
    mMotor.stop();
}

We are only using the 1st 5 motors and the 1st 4 were working.

The drive motors here are not controlled by


if

control structures. I wasn’t talking about them.

Ok but doesent ! mean if it is not being pressed? I am new to Coding.

And I was trying to control 2 motors with one button.

And we removed the Arm 2 code completely and it still did not work.

So here’s the code for your first arm motor cut out and formatted for ease of viewing:

if(Controller1.ButtonX.pressing()) {
    Arm1.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}

if(!Controller1.ButtonX.pressing()) {
    Arm1.stop();
} else if (Controller1.ButtonB.pressing()) {
    Arm1.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
}

if(!Controller1.ButtonB.pressing()) {
    Arm1.stop();
}

The first thing we notice is that there are three separate


if

blocks. This could be fine if all of them have mutually exclusive conditions, but they don’t. We have three cases that we care about: no buttons pressed, x button pressed and b button not pressed, and finally the case of x button not pressed and b button pressed. We don’t particularly care what happens if both buttons are pressed.

Let’s start with the first case, no buttons pressed:

  1. The first if block does not execute.
  2. The if…else if block executes its first condition (x not pressed), and stops the motor.
  3. The final if block executes, and stops the motor.

So two commands were sent to the motor, but they were both stop commands and don’t conflict.

The next case is x button pressed, b button not pressed:

  1. The first if block executes, and runs the motor forward.
  2. The if…else if block does not execute either case.
  3. The final if block executes, and stops the motor.

Two commands were sent to the motor, and they conflict. The result in this particular conflict will tend to be that the motor does nothing, as more time passes after the stop command than the run command.

The final case we care about is if the x button is not pressed, and the b button is pressed:

  1. The first if block does not execute.
  2. The if…else if block executes its first case, and stops the motor.
  3. The final if block does not execute.

One command is sent to the motor: stop.

In short, what I was trying to tell you, is that you have written a lot of code that makes the motor do nothing. The motor is working exactly as it has been programmed to do. Rewrite it into a single if… else if… else and these problems can be avoided:

if (x) {
    forward
} else if (b) {
    reverse
} else {
    stop
}

By using multiple if blocks for a single motor, you can have multiple if blocks firing at once. A single if else chain can only ever have one of its blocks fire, as it ignores any checks that come after the first match.