Integrated Encoder Not Working Properly

  1. 5 months ago

    Hello,

    I have a VEX integrated encoder on my left and right side drive motors. I can see them counting in the debug window on my laptop, but when I use them in a while loop, the motors keep running way past my specified value and don't stop unless I stop them with the competition switch. I've included the code below. Please let me know if there is something that I am doing wrong.

    Thanks!

    //motor and sensor setup
    #pragma config(I2C_Usage, I2C1, i2cSensors)
    #pragma config(Sensor, in1, lineFollowerLeft, sensorLineFollower)
    #pragma config(Sensor, in2, lineFollowerCenter, sensorLineFollower)
    #pragma config(Sensor, in3, lineFollowerRight, sensorLineFollower)
    #pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign )
    #pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign )
    #pragma config(Motor, port2, leftMotor, tmotorVex393_MC29, openLoop, reversed, driveLeft, encoderPort, I2C_2)
    #pragma config(Motor, port3, rollerLiftMotor, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port5, mobilePostMotor, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port6, leftScissor, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port7, rightScissor, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port8, coneLiftMotor, tmotorVex393_MC29, openLoop, reversed)
    #pragma config(Motor, port9, rightMotor, tmotorVex393_MC29, openLoop, driveRight, encoderPort, I2C_1)

    //autonomous command that is not stopping the motors after the right motor hits 2400

    resetMotorEncoder(leftMotor);
    resetMotorEncoder(rightMotor);

    while(getMotorEncoder(rightMotor) < 2400)
    {
    motor[leftMotor]=127;
    motor[rightMotor]=127;
    }

    motor[leftMotor]=0;
    motor[rightMotor]=0;

  2. jpearman

    Dec 7 Moderator, ROBOTC Tech Support, V5 Beta Moderator Los Angeles 8888

    check they are counting in the correct direction in the motors debug window and not the sensor debug window. Make sure that you have not reversed motor direction using the wiring (by connecting black to red motor wires)

 

or Sign Up to reply!