- :-

Topics Covered

  • Encoders and Variables
  • Integer Variable Type
  • Lesson Links

    Check Your Understanding:
    1. 1. True / False: Greyscale mode tells the color sensor to look for a specific color instead of the reflectivity of a surface.
    2. True
      False
    3. 2. True / False: Integer is an example of a data type for a variable.
    4. True
      False
    5. 3. Which of the following in not an example of a number that can be stored as an integer variable?
    6. 28
      .28
      -28
      280
    7. 4. True / False: A single equal sign (=) is used in ROBOTC to assign one value to another.
    8. True
      False
    9. 5. In the "Store Distance" program, the value 493 was assigned to the variable encoderLine 1.
      What does the number 493 represent?
    10. The number of centimeters the robot traveled
      The number of millimeters the robot traveled
      The amount of encoder counts of the left wheel of the robot
      The combined encoder counts of both wheels of the robot
    Try It!
    Try it! 1

    Clearing Encoder Values

    Try commenting out the "resetMotorEncoder" command that is right under the Task Main

    Save the program as "StoreDistance v2" and download and run the program several times in a row.



    With each run of the program, examine the value of the encoderLine1 variable in the ROBOTC Debugger Window.

    Try it!
    What Happens?

    The motor encoders do not reset between runs so the value that is being stored in the variable encoderLine1 is incorrect.

    The variable is now storing the value of all the cumulative runs of the robot because the motor encoder is not being reset.

    Try it! 2

    Using Encoders Driving Backwards

    Create a program that has the robot run backwards until it reaches a certain encoder value.

    Remember to use the resetMotorEncoder command, turn the motors on with the setMotorSpeed commands, and use a waitUntil command to set the condition of the motor's encoder value.

    How is the condition in the waitUntil command different than what it would be if the robot was moving forward?

    Try it!
    What Happens?

    Since the robot is moving backwards for a certain amount of encoder counts, we have to use getMotorEncoder in the waitUntil command.


    Encoders and Variables - Mini Challenge

    Mini Challenge 1: Loading Dock

    Program the robot to pick up blocks that are placed at random distances away from the starting point.

    Encoder values should then be utilized to travel the correct distance back to the starting point.

    Once back to the starting point, the block can be cleared off of the challenge board.
    • Recreate the table below on any surface, then use objects that serves as the blocks.

    Mini Challenge PDF[ Loading Dock VEX IQ Challenge.pdf ]