Announcement

Collapse
No announcement yet.

Motor stop at specific position.

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

  • DuckTech5444
    started a topic Motor stop at specific position.

    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

  • 3805Mentor
    replied
    I looked at your code again. Once I saw that you set mid motor to run using encoders my brain read the run to position as referring to a different motor.

    The motor can only be in one mode at any time. If you choose run to position anytime the motor has power regardless of + or - the motor will drive to the target position. This is not what you want.


    Leave the mode for the mid motor in run using encoder. Then use this code for the mid motor and nothing else. (adjust encoder number as needed.)

    if (Arm.getCurrentPosition()< -100 && gamepad1.left_stick_y < 0 ) Arm.setPower(0);
    else Arm.setPower(gamepad1.left_stick_y);

    Leave a comment:


  • 3805Mentor
    replied
    Can you post your current version

    Leave a comment:


  • DuckTech5444
    replied
    That does not seem to be working for us, could you possibly supply or direct us to a very simple opmode that would limit the encoder motor?

    Leave a comment:


  • 3805Mentor
    replied

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

    Leave a comment:


  • DuckTech5444
    replied
    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.

    Leave a comment:


  • 3805Mentor
    replied
    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.

    Leave a comment:

Working...
X