i have no idea what i am doing with encoders... help

  1. 4 months ago

    Alpha Entity

    Jan 12 Sachse High School 5408c

    OK so here's the rundown. i am new to robot c ( have been using easy c for the past 3 years and i decided to make the big jump) and in about 2 hours i got all the drive and autonomous working and so today i went to go put encoders on because i thought that OK, so if drive wasn't so bad how bad can this be... its bad. right now this is all i have done and looking at the examples robot c has made hasn't helped . i talked to a teammate that has been using robot c for about 6 months now and he wasn't able to figure it out because he is using PID controls. however we found that it is never leaving the IF loop. currently rde= Right Drive Encoder and we are testing it on one motor before we attach it to our robot. (motor ml_bl__Y)

    if (SensorValue[rde] < 1000)
    	{
    		motor[ml_bl__Y]= 127;
    		motor [fl]=127;
    		motor [mr_br__Y]=127;
    		motor [fr] =127;
    	}
    
    	else
    	{
    		motor[ml_bl__Y]= 0;
    		motor [fl]=0;
    		motor [mr_br__Y]=0;
    		motor [fr] =0;
    	}
  2. [TVA]Connor

    Jan 12 South Texas 1814D
    Edited 4 months ago by [TVA]Connor

    First of all, an if() statement is not a loop, but just a statement that declares running the portion inside the curly brackets "{}" only once from top to bottom if the statement inside the brackets "()"is true. A while() statement is a loop that runs the portion inside the curly brackets "{}"infinitely as long as what's inside the parenthesis"()" has a value that is true...... If that's not the solution to what you're asking, read more:
    The first thing I would do is check if the encoder is working correctly. Try following these steps to see if your encoder works:

    1. Make sure your robot is plugged in to your computer is turned on
    2. When connected to your computer, go to Robot>Open Debugger Manually
    3. While the debugger is open, go to Robot>Debugger Windows>Sensors (This should let you see the current sensorvalue of the sensors on your robot.
    4. If the encoder is showing a -1(skip this and go to my second suggestion if it doesn't show a -1), the input/output ports are probably switched, the encoder is on the wrong ports, or the encoder is broken. Double check that the encoder is on the correct port, and try swapping the input/output pins on the ports.
    5. If even after these steps, and you still have a -1, try replacing the encoder.

    When I first started with ROBOTC, I didn't actually learn by following the videos. I rather more opened the sample programs and dissected what the programs mean. Sample programs are really useful for people who don't exactly know how to program a specific sensor, variable, and much more. Go to File>Open Sample Program to see a great amount of examples you can use when learning to program. When you open a sample program, and you wish to tinker that program, make sure you save it before doing anything else :).
    Hopefully this helps :)
    - [TVA]Connor

  3. Alpha Entity

    Jan 12 Sachse High School 5408c
    Edited 4 months ago by Alpha Entity

    @[TVA Connor]First of all, an if() statement is not a loop, but just a statement that declares running the portion inside the curly brackets "{}" only once from top to bottom if the statement inside the brackets "()"is true. A while() statement is a loop that runs the portion inside the curly brackets "{}"infinitely as long as what's inside the parenthesis"()" has a value that is true...... If that's not the solution to what you're asking, read more:
    The first thing I would do is check if the encoder is working correctly. Try following these steps to see if your encoder works:

    1. Make sure your robot is plugged in to your computer is turned on
    2. When connected to your computer, go to Robot>Open Debugger Manually
    3. While the debugger is open, go to Robot>Debugger Windows>Sensors (This should let you see the current sensorvalue of the sensors on your robot.
    4. If the encoder is showing a -1(skip this and go to my second suggestion if it doesn't show a -1), the input/output ports are probably switched, the encoder is on the wrong ports, or the encoder is broken. Double check that the encoder is on the correct port, and try swapping the input/output pins on the ports.
    5. If even after these steps, and you still have a -1, try replacing the encoder.

    When I first started with ROBOTC, I didn't actually learn by following the videos. I rather more opened the sample programs and dissected what the programs mean. Sample programs are really useful for people who don't exactly know how to program a specific sensor, variable, and much more. Go to File>Open Sample Program to see a great amount of examples you can use when learning to program. When you open a sample program, and you wish to tinker that program, make sure you save it before doing anything else :).
    Hopefully this helps :)
    - [TVA]Connor

    we were able to see the encoder count but our problem was that when the IF statement hit 1000 the motor didn't stop. it just kept going. we have also tried another encoder but had the same result (may i add this is a 2 wire encoder not single for both)

  4. Vex 9185

    Jan 13 Bellefontaine, Ohio 9185B
    Edited 4 months ago by Vex 9185

    As Connor said, a "while" statement is better suited for this task. There's a sample program that does something similar in VEX2\Shaft Encoder. It's called Forward For Distance.

     //Clear Encoders
      SensorValue[rightEncoder] = 0;
      SensorValue[leftEncoder] = 0;
    
      while(SensorValue[leftEncoder] < 1800)  // While less than 5 rotations on the leftEncoder...
      {
        //...Move Forward
        motor[rightMotor] = 63;
        motor[leftMotor] = 63;
      }

    This is the main part of that program. First, it clears the encoder values, which I believe is automatically done each time you compile. Then comes the while loop. It checks the condition in the parentheses, and if it's true, runs the program in the {}s, and returns to checking the condition in the parentheses again. When the SensorValue goes over 1800, the condition becomes false, and the robot exits out of the loop.
    The only part missing from this program is stopping the motors. The sample works because the whole program ends when the while loop is finished. I believe your program has more components than that, so it may be that the stop command is never given. If you were to use something similar to the sample program, you would add,

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

    at the end, after the while loop.

    If that doesn't work, you could post your whole program here, and we could look at it for you.

  5. Alpha Entity

    Jan 13 Sachse High School 5408c

    @Vex 9185 As Connor said, a "while" statement is better suited for this task. There's a sample program that does something similar in VEX2\Shaft Encoder. It's called Forward For Distance.

     //Clear Encoders
      SensorValue[rightEncoder] = 0;
      SensorValue[leftEncoder] = 0;
    
      while(SensorValue[leftEncoder] < 1800)  // While less than 5 rotations on the leftEncoder...
      {
        //...Move Forward
        motor[rightMotor] = 63;
        motor[leftMotor] = 63;
      }

    This is the main part of that program. First, it clears the encoder values, which I believe is automatically done each time you compile. Then comes the while loop. It checks the condition in the parentheses, and if it's true, runs the program in the {}s, and returns to checking the condition in the parentheses again. When the SensorValue goes over 1800, the condition becomes false, and the robot exits out of the loop.
    The only part missing from this program is stopping the motors. The sample works because the whole program ends when the while loop is finished. I believe your program has more components than that, so it may be that the stop command is never given. If you were to use something similar to the sample program, you would add,

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

    at the end, after the while loop.

    If that doesn't work, you could post your whole program here, and we could look at it for you.

    so i just went to try and see if the pre-made program would work... it didn't. i tried 2 different encoders and had the same results. any other ideas? i also posted the program i wrote in first thread

  6. Xinghao Li

    Jan 13 RoboSavage 2S

    @Alpha Entity so i just went to try and see if the pre-made program would work... it didn't. i tried 2 different encoders and had the same results. any other ideas? i also posted the program i wrote in first thread

    You might want to check if your cortex port is broken or not, it goes into digital, and you have to make sure that you plugged your wires in correctly, a good way to check is by using the debugger window after you have downloaded your program into the cortex, the encoder reading should change as you rotate your robot. If that works, then it must be your code.

  7. Xinghao Li

    Jan 13 RoboSavage 2S

    @Alpha Entity so i just went to try and see if the pre-made program would work... it didn't. i tried 2 different encoders and had the same results. any other ideas? i also posted the program i wrote in first thread

    Void Driveforward (int rotation)
    {
    SensorValue[leftencoder] = SensorValue[rightencoder] = 0;

    While(SensorValue[left encoder] < rotation)
    {
    motor[leftdrive] = motor[rightdrive] = 127;
    }

    motor[leftdrive] = motor[rightdrive] = 0;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Task autonomous()
    {
    Driveforward(1000);
    }

    You can write it like this. the rotation is your targeted rotation for your distance.

  8. Alpha Entity

    Jan 13 Sachse High School 5408c

    @Xinghao Li Void Driveforward (int rotation)
    {
    SensorValue[leftencoder] = SensorValue[rightencoder] = 0;

    While(SensorValue[left encoder] < rotation)
    {
    motor[leftdrive] = motor[rightdrive] = 127;
    }

    motor[leftdrive] = motor[rightdrive] = 0;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Task autonomous()
    {
    Driveforward(1000);
    }

    You can write it like this. the rotation is your targeted rotation for your distance.

    we have a 6 motor drive on our robot,how would we add the other motors for each side? would we just add:

    motor[ leftdrive]=motor [leftdrive2]=motor [rightdrive]=motor [ rightdrive2]=127;

    or would it be something different?

  9. Xinghao Li

    Jan 13 RoboSavage 2S
    Edited 4 months ago by Xinghao Li

    @Alpha Entity we have a 6 motor drive on our robot,how would we add the other motors for each side? would we just add:

    motor[ leftdrive]=motor [leftdrive2]=motor [rightdrive]=motor [ rightdrive2]=127;

    or would it be something different?

    yes, it'll be like that. If you want to make it look more better, you can always type out

    Motor[left1] = motor[left2] = 127;
    motor[right1] = motor[right2] =127;

 

or Sign Up to reply!