Robot Not Moving

I’ve been having trouble getting the robot to move. I feel like the code is correct. Here is all of the stuff in our TeamCode file.TeleOpPrototype1.java (2.17 KB) HardwareHyper.java (4.51 KB)

TeleOpPrototype1.java (2.17 KB)
HardwareHyper.java (4.51 KB)


TeleOpPrototype1.java (2.17 KB)
HardwareHyper.java (4.51 KB)

Clamp and Ejector are never assigned in TeleOpPrototype1, so line 47 (Clamp.setPosition) will throw a null pointer exception. The same can be said for lines 49, 53, and 56. In addition to that, you are using assignment operators where you should be using comparison operators. You also do not need to compare boolean values at all, and should use the else statement in place of a comparison to false.

So should I do:

if(gamepad2.a = true) {
Clamp.setPosition(0);
}
else {
Clamp.setPosition(1);
}

Also, what do you mean by defining? I thought that having the
“Private Servo Clamp = null;”,
“Private Servo Ejector = null;”, and it is also used elsewhere in the code, like LeftWheel and RightWheel would define it.

I’ve never used this language but I’m pretty sure “if(gamepad2.a = true)” is still an assignment statement. So you either need to do “if(gamepad2.a == true)” or just “if(gamepad2.a)”. Usually, that defaults to checking for a true value.

Edit: Also, when assigning, you should very rarely assign something to null. If that variable were to get used before reassigning, it will return the “null pointer exception”. That is an error you get when you try to use a null value. That probably contributes to why the robot isn’t moving.

Where did I say “defining”? I did say you weren’t assigning them a value. You’ve declared the variables, but they contain no value (null) - which, when you try to use them, throws a NullPointerException, crashing the robot code, and preventing your robot from moving.

No. gampad2.a = true is an assignment operation. This assigns true to gamepad2.a. What you want to do is a comparison, which would look something like this:


if(gamepad2.a == true ) { // note the double equals sign
   Clamp.setPosition(0);
}else{
   Clamp.setPosition(1);
}

…however, a comparison operator simply returns true or false, so for values which are already a boolean (such as gamepad2.a), no comparisons are necessary.


if(gamepad2.a){ // will execute if gamepad2.a is true
  Clamp.setPosition(0);
}else{
  Clamp.setPosition(1);
}

Okay. Yeah, I realized that having one = was a statement. I changed it to

if(gamepad2.a) {
Clamp.setPosition(0);
}
else{
Clamp.setPosition(1);
}
if (gamepad2.b) {
Ejector.setPosition(0);
}
else{
Ejector.setPosition(1);

I also tried assigning the servos to the hardwareMap, which I didn’t do for them, and also tried assigning positions to the Servos and Directions to the DcMotors:

@Override
public void runOpMode () throws InterruptedException{
LeftWheel = hardwareMap.dcMotor.get (“LeftWheel”);
RightWheel = hardwareMap.dcMotor.get (“RightWheel”);
ForeArm = hardwareMap.dcMotor.get (“ForeArm”);
UpperArm = hardwareMap.dcMotor.get (“UpperArm”);
Clamp = hardwareMap.servo.get (“Clamp”);
Ejector = hardwareMap.servo.get (“Ejector”);

        LeftWheel.setDirection (DcMotor.Direction.FORWARD);
        RightWheel.setDirection(DcMotor.Direction.FORWARD);
        ForeArm.setDirection(DcMotor.Direction.REVERSE);
        UpperArm.setDirection(DcMotor.Direction.REVERSE);
        Clamp.setPosition(1);
        Ejector.setPosition(1);

and it still wouldn’t move. Also, don’t mind the semicolon that is a space out form the RightWheel.setDirection. That’s a formatting error on CheifDelphi.

Hmm… are you sure all of those objects are in your config? It’s been a while since I did FTC (almost a year now), but I’m pretty sure if you try to pull something out of the hardware map that doesn’t exist, you’ll get an error.

Also make sure the gamepad icons are visible on the DS app.


On an unrelated note, reading your code is somewhat confusing as you aren’t abiding by Java naming conventions. It would also be nice if you could provide a complete copy every time you modify the code - what may seem like the correct way to implement my (or other’s) advice to you may not be what we meant. A great way to do this is with a public gist, which you can link once, then edit each time you make changes (the URL won’t change). Plus, I can link to and comment on specific parts of the code easier. I would recommend regular github, but you really only have 1 file right now (HardwareHyper is completely ignored by TeleOpPrototype1).

Here is the Gist:

https://gist.github.com/Xbox180/8b757e995747bbaf402984576467bef6

That looks correct.

Can you confirm that the clamp and ejector servos move to position 1 when the robot is initialized? This would indicate whether or not lines 34 and 35 run.

I would also verify the naming of your motors and servos in the configuration file, and the electrical connections on your robot.

We figured out what was wrong. Do you notice the ‘OpMode extends LinearOpMode’? Well that was contradictory to the import.qualcomm.blabla.blablabla. So we changed OpMode to the file name, and it worked. Thanks for your input. That probably solved somethings that would’ve gone wrong.

Sent from my iPhone using Tapatalk

Wow, no I did not notice that. If I had I would’ve told you. I was looking for logic errors, not something like that. Don’t mess with the names of your classes, Android Studio will generate them for you (you can still add extends / implements etc.)!

Glad to hear you got it working.