# Arm Code Help

My students are trying to code their robot for our class competition, but we can’t get the arm to move at all. The wheels are working just fine, but the motors for the arm aren’t even responding. Their robot is based on a basic clawbot design, but there is an extra joint between the arm and the chassis. I’m new to teaching PLTW (just this semester), and I’m struggling to help them with this code. Can someone tell me where we might have gone wrong?

#pragma config(Motor, port2, RR, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port3, LR, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, RF, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port5, LF, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, Claw, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, Arm2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, Arm1, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{

while(1==1)
{
motor(RF)=vexRT(Ch2);
motor(RR)=vexRT(Ch2);
motor(LF)=vexRT(Ch3);
motor(LR)=vexRT(Ch3);
}
wait(0.01);

if(vexRT(Btn8U) == 1)
{
motor(Arm1) = 100;
wait(0.01);
}

if(vexRT(Btn8D) == 1)
{
motor(Arm1) = -100;
wait(0.01);
}
if(vexRT(Btn7U) == 1)
{
motor(Claw) = 100;
wait(0.01);
}

if(vexRT(Btn7D) == 1)
{
motor(Claw) = -100;
wait(0.01);
}

else
motor(Arm2) = 0;
motor(Arm1) = 0;
motor(Claw) = 0;
}

The `while(1==1)` tells the programming to repeat the code within the braces. The close brace ends the while section of code before it reaches the if statements. This is why they don’t respond. You need the close brace for the while loop to be at the end of the code instructions.

``````#pragma config(Motor, port2, RR, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port3, LR, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, RF, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port5, LF, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, Claw, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, Arm2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, Arm1, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{

while(1==1)
{   //Begin While Loop

motor(RF)=vexRT(Ch2);
motor(RR)=vexRT(Ch2);
motor(LF)=vexRT(Ch3);
motor(LR)=vexRT(Ch3);

}   //End While Loop <-- This close brace needs to be at the bottom.
wait(0.01);

if(vexRT(Btn8U) == 1)
{
motor(Arm1) = 100;
wait(0.01);
}

if(vexRT(Btn8D) == 1)
{
motor(Arm1) = -100;
wait(0.01);
}
if(vexRT(Btn7U) == 1)
{
motor(Claw) = 100;
wait(0.01);
}

if(vexRT(Btn7D) == 1)
{
motor(Claw) = -100;
wait(0.01);
}

else
motor(Arm2) = 0;
motor(Arm1) = 0;
motor(Claw) = 0;
}
} // <-- Down here
``````

One other thing to correct is your `if` statements and you only need the `wait(0.01)` one time.

``````// The motors have 3 states - Fwd, Rev, Stop
// You need to test for two conditions - Up, Down, (or Nothing)
if(vexRT(Btn8D) == 1)
{
motor(Arm1) = -100;  //Down
}
else
{
if(vexRT(Btn8U) == 1) // (Notice nested If statement)
{
motor(Arm1) = 100; //Up
}
else //Nothing being pressed
{
motor(Arm1) = 0;  //Stop
}
}``````
5 Likes

Thank you so much! I really appreciate your help, and my students do, too!

4 Likes

Thank you so much for this code! My students returned from spring break and were excited to try it out. Now, they just can’t get the second part of their robot’s arm to move. How can we add Arm2 to this? Thank you!

1 Like

Wherever you see `motor(Arm1) = 100; ` add `motor(Arm2) = ###; ` on the following line.

``````motor(Arm1) = 100;
motor(Arm2) = 100;
``````

Make sure you match the value (0,100) and operator (+,-) to the adjacent line. Then both motors for the arm will work together.

2 Likes