Announcement

Collapse
No announcement yet.

Motor stop at specific position.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Motor stop at specific position.

    How would you write the code to make a dc motor stop at a specific position using an encoder? We have ran this code multiple times and can not seem to figure out the problem with it. When the code is ran no motors will work what so ever. the motor labeled middleMotor is the specific encoded DC motor we are having problems with. The motor is a Neverest 40.
    Attached Files

  • #2
    The first time through the code the joystick for middle motor is zero. With no power the motor never turns, the encoders never advance, and you're stuck in the while loop checking the encoder forever.

    Just get rid of the while statement altogether. Keep the if max set Power to zero.

    Comment


    • #3
      Now that we changed that code our encoder will stop the motor but we want the motor to be able to go back in the opposite direction. We only want the middle motor to go so far in one direction but have unlimited rotations in the opposite direction.

      Comment


      • #4

        Try
        if (middleMotor.getCurrentPosition() <= -999 && gamepad2.right_stick_y < 0) {
        middleMotor.setPower(0);
        }

        Comment

        Working...
        X