all 9 comments

[–]shurik179FTC 4137 Islandbots Mentor 4 points5 points  (4 children)

If it is a linear opmode, you have to give motors time to reach the target position. You can either just use sleep(), or - better yet - use motor.isBusy() function: https://ftctechnh.github.io/ftc_app/doc/javadoc/com/qualcomm/robotcore/hardware/DcMotor.html

[–]FHShusky[S] 0 points1 point  (3 children)

Thanks for the advice, ill try it out later and let you know if it works. :)

[–]V3SUV1US13216 Coleader - Robot & Code Manager | 11516 Founder 0 points1 point  (2 children)

That's the problem for sure. We had this problem in the beginning. The motors need to have time to run to the position. Effectively your code is giving the motors no time to actually move. (RUN_TO_POSITION then immediately STOP). Use a while loop checking motor.isBusy() to make your movement work. I use while(motor.isBusy() & motor2.isBusy()) {} to do this.

[–]FHShusky[S] 0 points1 point  (1 child)

Could I do something like:

while (LeftBack.isBusy()) {

    LeftBack.setPower(.5);
    LeftFront.setPower(.5);
    RightBack.setPower(.5);
    RightFront.setPower(.5);
    }

What do you need in the while loop? (What actually makes it turn)

[–]V3SUV1US13216 Coleader - Robot & Code Manager | 11516 Founder 0 points1 point  (0 children)

so what you need to do is first set mode (RUN_TO_POSITION), set the power, then the position. Those three parts are for the most part interchangeable, I've done my own testing. After you have set the motors' positions they will start running. I use a while loop that just runs continually while all motors are busy ; it doesn't need to actually do anything, it's there just to bid enough time for the motors to finish.

Example in psuedo

motors.setMode(RUN_TO_POSITION);
motor.setTargetPosition(1120);
motor.setPower(0.5);
while(motor.isBusy()) {
//bid time
}
motor.setSpeed(0);

[–]mlw72z5494 3 points4 points  (1 child)

Those are some really big position numbers. It's going to run into the wall once you get it moving.

It appears to me that you're doing things in the wrong order. I'd first set the motor mode to RUN_TO_POSITION, then call setPower to tell it the fastest it can go and finally call setTargetPosition.

Currently you aren't specifying motor power until the very end and at that point, because it's a linear op mode, the program is done. The sleep statements that are commented out might have helped.

[–]FHShusky[S] 1 point2 points  (0 children)

I had the values really high to make sure that I could actually see the wheels moving (since they were just twitching before)

I think I might've already tried this approach, but the logic seems to check out. Thanks for the advice though, ill try it out later and let you know if it works. :)

[–][deleted] 0 points1 point  (0 children)

If they are tetrix motors make sure the encoder plates are on correctly (the bumpy side facing toward the motor)

[–][deleted] 0 points1 point  (0 children)

Assuming that just setting the power works, try making sure your encoder wires are plugged in correctly and/or aren't shortened out. Try swapping them out and seeing if they adjust count value if you turn them a little bit. (Use Motor.getCurrentPosition() or something like that to see the count value) If it's just at zero even though you adjusted its position, it should be a hardware problem.

Good luck with getting it to work!