Robot Infinitely Turning with Encoders

  1. 8 months ago

    SpencerVaughan

    6 Dec 2017 Sydenham, Victoria, Australia 96498A

    So when clicking on this title your probably thinking we just aren't programming our encoders correctly, but they have been working find in all of our recent tournaments and the program has not changed (this part at least) since.
    The problem we are having is that the robot will only stop turning on some occasions, whilst the rest of the time it turns forever,
    We notice that it infinitely turns when it has a mobile goal picked up, whilst when it doesn't it doesn't seem to have this issue.
    The sensors are more than certainly working, as when driving forward to pick up a Mobile Goal they are always travelling the correct distance and stopping, i have had trouble fixing it, and nobody can seem to find a solution!
    I will include the code below:
    Note: We have tried lowering the power which makes it work slightly more often, but we need to run the motors at full power to be able to finish the program within the 15 second Autonomous.

    **Note: The point which seems to be the error is when the leftEncoder is turning until it reaches 1480 encoder ticks, (Line 91), note: this error occurs for both encoders. Help would be appreciated, Thanks in advance**

    #pragma config(Sensor, in1, Potentiometer, sensorPotentiometer)
    #pragma config(Sensor, in2, Potentiometer2, sensorPotentiometer)
    #pragma config(Sensor, dgtl1, leftEncoder, sensorQuadEncoder)
    #pragma config(Sensor, dgtl3, rightEncoder, sensorQuadEncoder)
    #pragma config(Sensor, dgtl5, bumper, sensorTouch)
    #pragma config(Motor, port2, rightDrive, tmotorVex393_MC29, openLoop, driveRight)
    #pragma config(Motor, port3, leftDrive, tmotorVex393_MC29, openLoop, driveLeft)
    #pragma config(Motor, port4, PinionGear2, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port5, Claw, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port6, PinionGear1, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port7, Lift, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port8, Arm, tmotorVex393_MC29, openLoop)
    #pragma config(Motor, port9, Arm2, tmotorVex393_MC29, openLoop)
    //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

    task one()
    {
    moveMotor(port8, 0.4, seconds, 100);
    delay(100000);
    }
    task two()
    {
    moveMotor(port9, 0.4, seconds, 100);
    delay(100000);
    }
    task three()
    {
    moveMotor(port4, 0.5, seconds, -100);
    delay(1000);
    backward(0.2, seconds, 100);
    delay(100000);
    }
    task four()
    {
    moveMotor(port6, 0.5, seconds, -100);
    moveMotor(port5, 0.5, seconds, -100);
    delay(100000);
    }
    task five()
    {
    delay(400);
    moveMotor(port8, 1, seconds, 100);
    delay(100000);
    }
    task six()
    {
    delay(400);
    moveMotor(port9, 1, seconds, 100);
    delay(100000);
    }

    task main()
    {
    enableCompetitionMode();
    repeat (forever) {
    if (getCompetitionAutonomous() == true) {
    startTask(one);
    startTask(two);
    SensorValue[rightEncoder] = 0;
    SensorValue[leftEncoder] = 0;
    while(SensorValue[leftEncoder] < 280)
    {
    motor[rightDrive] = 90;
    motor[leftDrive] = 90;
    }
    stopAllMotors();
    startTask(three);
    startTask(four);
    delay(1000);
    startTask(five);
    startTask(six);
    delay(100);
    moveMotor(port7, 1.9, seconds, -100);
    while (SensorValue[bumper] == 0)
    {
    motor[Lift] = -80;
    }
    moveMotor(port7, 0.1, seconds, 100);
    stopAllMotors();
    forward(0.7, seconds, 100);
    moveMotor(port7, 1.7, seconds, 100);
    while (SensorValue[bumper] == 0)
    {
    motor[Lift] = 100;
    }
    stopAllMotors();
    backward(0.75, seconds, 100);
    stopAllMotors();
    SensorValue[leftEncoder] = 0;
    SensorValue[rightEncoder] = 0;
    while(SensorValue[leftEncoder] < 1480)
    {
    //Buggy, Needs to be fixed, turning forever.
    motor[rightDrive] = 0;
    motor[leftDrive] = 80;
    }
    stopAllMotors();
    forward(2, seconds, 100);
    moveMotor(port7, 1.7, seconds, -100);
    while(SensorValue[bumper] == 0)
    {
    motor[Lift] = -70;
    }
    stopAllMotors();
    backward(0.45, seconds, 100);
    moveMotor(port7, 2.4, seconds, 100);
    delay(3000); // End of 15s auton



    }
    if (getCompetitionDriverControl() == true) {
    arcadeControl(Ch2, Ch1, 100);
    buttonControl(port7, Btn6U, Btn6D, 100);
    buttonControl(port5, Btn7L, Btn7R, 100);
    buttonControl(port6, Btn7U, Btn7D, 80);
    buttonControl(port4, Btn7U, Btn7D, 80);
    buttonControl(port10, Btn5U, Btn5D, 100);
    buttonControl(port9, Btn5U, Btn5D, 100);
    buttonControl(port8, Btn5U, Btn5D, 100);
    }
    }
    }

    Hey an Update: We found a solution to the problem today and it was nothing anybody was expecting.

    We found that the error was being caused by an unused potentiometer. When the robot's arms would reach a certain point they would make the robot turn infinitely, the team has no idea why this is happening, but we are removing the potentiometer completely.
    It seems that the robot works at the start with the encoders as they were moving before the arms reached a certain point, but the arms caused the robot to go forever when reaching a certain point. This does not make sense as these potentiometers had no code in the entire program, but extensive testing proved that these were the saboteurs!

    Thanks for the help. I appreciate it all!

  2. Mystellianne

    6 Dec 2017 Miami, Florida 4411S

    I know this may sound counterintuitive, but is there any small chance that you've mislabeled your encoders and that the leftEncoder in the code is actually the right one? This would make sense as to what's happening, because without a mobile goal on your robot, even though the motor power is 0 it will still some, and with a mobile goal it's heavier so it will be a lot less likely to turn, therefore never reaching its desired value. I highly recommend trying the exact same code using the "rightEncoder" for that code, as that may actually be your left one.

  3. SpencerVaughan

    6 Dec 2017 Sydenham, Victoria, Australia 96498A

    @Mystellianne I know this may sound counterintuitive, but is there any small chance that you've mislabeled your encoders and that the leftEncoder in the code is actually the right one? This would make sense as to what's happening, because without a mobile goal on your robot, even though the motor power is 0 it will still some, and with a mobile goal it's heavier so it will be a lot less likely to turn, therefore never reaching its desired value. I highly recommend trying the exact same code using the "rightEncoder" for that code, as that may actually be your left one.

    Thanks for the reply! We can confirm it isn't this because we have re wired to make sure each encoder is working with the correct side, it also doesn't make sense that it still performs the turn, the weight may affect it, but the turn still completes when it doesn't have the MoGo

  4. Robo_Eng_13

    6 Dec 2017 Indiana 1483

    @SpencerVaughan Thanks for the reply! We can confirm it isn't this because we have re wired to make sure each encoder is working with the correct side, it also doesn't make sense that it still performs the turn, the weight may affect it, but the turn still completes when it doesn't have the MoGo

    Try sending the sensor values to a global variable and watching that variable on the computer while it runs. See if it is doing what you expect. It should show you if the value is counting the wrong direction, not counting at all, or if the problem is elsewhere.

  5. SpencerVaughan

    7 Dec 2017 Sydenham, Victoria, Australia 96498A

    @Robo_Eng_13 Try sending the sensor values to a global variable and watching that variable on the computer while it runs. See if it is doing what you expect. It should show you if the value is counting the wrong direction, not counting at all, or if the problem is elsewhere.

    hey thanks for the response, we tried this and it didnt work;
    we did put the portion of the code which doesnt seem to be working in its own code with a delay, so it would do the turn, wait, than do it again.
    This was working and does show that it is stopping.

    We used Global Variables to find that at the start of the program the encoders work, but towards the end (at the point of the infinite turn) It sets the value to 0, but when the motor moves the encoder does not increase or decrease in value.
    If anybody has a fix for this it would be much appreciated, we have nationals in two days and this thing is going to be the death of us haha!
    Thanks

  6. SpencerVaughan

    8 Dec 2017 Answer Sydenham, Victoria, Australia 96498A

    Hey an Update: We found a solution to the problem today and it was nothing anybody was expecting.

    We found that the error was being caused by an unused potentiometer. When the robot's arms would reach a certain point they would make the robot turn infinitely, the team has no idea why this is happening, but we are removing the potentiometer completely.
    It seems that the robot works at the start with the encoders as they were moving before the arms reached a certain point, but the arms caused the robot to go forever when reaching a certain point. This does not make sense as these potentiometers had no code in the entire program, but extensive testing proved that these were the saboteurs!

    Thanks for the help. I appreciate it all!

 

or Sign Up to reply!