Presentation is loading. Please wait.

Presentation is loading. Please wait.

Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with.

Similar presentations


Presentation on theme: "Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with."— Presentation transcript:

1 Autonomy using Encoders Intro to Robotics

2 Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with timers. We use our new sensor, the ENCODER.

3 Autonomy/Encoders Forward for Distance In this unit, you will learn to use the encoders to control the distance the robot moves, and to self-correct its steering to counteract the random drift that occurs during movement. This will eventually serve two purposes.

4 Autonomy/Encoders Forward for Distance First, it will provide you with a new form of Operator Assist that uses the sensors on the robot to drive straighter than a human operator might be capable of doing. Second, it will begin building a base of behaviors that the robot can use on its own during the Autonomous Period that is part of the revised challenge. For 20 seconds at the start of the match, your robot will have a chance to run and score points completely on its own.

5 The Encoder The Encoder is a sensor that measures rotation. On the Squarebot 3.0, encoders are attached to the wheels of the robot. The encoders measure how far the wheels have turned, and therefore, how far the robot has moved. The distance the robot covers moving forward is equal to the length of the tire tread that spins by.

6 The Encoder We will be able to make reasonably accurate predictions about exactly how far the robot will move after every full turn of the wheels. The encoder measures in 4-degree increments, and so will register 90 counts for a full 360-degree rotation. For this lesson, the important part is simply that the number of encoder counts is directly linked to the amount that the wheels turn, and therefore, to the distance that the robot travels. Being able to directly measure the turning of the wheels allows us to dictate the motion of the robot in terms of distances rather than simply defining a period of time that the robot should move. This is a much more reliable method, because it is unaffected by factors like speed or battery power. Using the encoder-based distance to determine movement, therefore, will result in much better consistency of movement. This is exactly what your robot needs to do its job well, with or without human supervision!

7 Open a sample program Save in the UCF folder as Encoder Test

8 Motors & Sensors Setup Notice that the encoders are a DIGITAL sensor and that we named them “rightEncoder” and “leftEncoder”. Each encoder is plugged into TWO ports on the Cortex.

9 Let’s inspect our code The “SensorValue” command is used for ALL sensors and can be used to clear any digital value stored in the sensor. Each command must specify which sensor it is referring to by its NAME. In this case, we are setting each encoder to ZERO. This clears out the encoder so that it can measure out distance. This MUST be done each time you travel a distance or make a turn.

10 Let’s inspect our code This is a special type of CONTROL STRUCTURE, called a WHILE LOOP.

11 while ( ) When the program reaches most commands, it runs them and then moves on. When the program reaches a while ( ) loop, however, it steps INSIDE the loop, and stays there as long as the while ( ) loops decides that it should. The commands repeat over and over.

12 Let’s inspect our code The CONDITION inside the parenthesis states that the encoder values need to be LESS than 1800. As long as the counts are less than 1800 the COMMANDS(simple statements) inside the curly braces will loop over and over. As soon as the count goes OVER 1800, the loop will END and the next line of code will begin.

13 Modifying our Labyrinth Code Checkpoint Your robot should begin executing the first behavior two seconds after it is turned on. The robot will start moving — and keep moving! If you pick it up and let it run for a while, you will notice that it eventually stops, but nowhere near the right distance. The guess we used for the number of encoder counts was off. 1800 is far too many counts for the distance that the robot needs to move.

14 Encoder count off? Change this value until you reach the turn in the labyrinth. Compile and download each time until the robot reaches the correct position.

15 Test the Encoder count

16 Making turns with the Encoder You must ZERO the left encoder before using it for a different leg of the labyrinth. We use a NEW COUNT for the right turn and also make sure we reverse the right motor to make the turn correctly. All of this is done inside a second WHILE loop.

17 Rule of thumb

18 Finish the program

19 Test & make changes to encoder counts Save the program as MAZE using encoders. Complete the maze using encoder counts. Use comments in the code as well.

20 Motor power changes?

21 Motor Power Changes

22 What happened?

23

24 Encoder usefulness

25 Automated Straightening Earlier in the course, we tweaked the power motor values to get the robot to go straight even though the task was tedious.

26 Automated Straightening

27

28 The “If” statement The “IF” statement is similar to a while loop in that it is a CONTROL STRUCTURE. But it is very different in that it only runs the commands ONCE instead of looping. Just like the while loop, the “IF” statement has a CONDITION that robotC checks to see if it is true. If the condition is true, it runs the commands inside the curly braces. If it is false, it exits and runs the next line of code. Save your code from before as LABYRINTH AUTO STRAIGHT.

29 Using the “RIGHT” Encoder Since BOTH encoders will be used to monitor whether the robot moves straight it is important to make sure you ZERO out each encoder before each turn.

30 Using the “IF” statements Locate your FIRST while loop and inside set up the framework for the THREE “IF” statements.

31 If the LEFT is greater than the RIGHT This says, if the counts on the left encoder are greater than the counts on the right encoder then lessen the power on the left motor and increase the power on the right

32 If the RIGHT is greater than the LEFT

33 If the RIGHT is equal to the LEFT The WHILE loop still makes sure the distance is set at the correct # of counts while the “IF” statements make sure the robot moves straight over this distance.

34 Using /* comments */ to test program Note: Make sure the last */ - comment tag is BEFORE your last “task main” punctuation pair. “Commenting out your code” is a great way to go back and test out individual parts of the code as you work on changes. Comment out your MAZE code and test just the first leg of the STRAIGHT program.

35 Test!

36 Finish the changes! Now change the REST of the code for the OTHER behaviors which require the robot to go straight. Be sure to RESET the encoder values to zero before each while loop.

37 Boolean Logic The programming we just did is called Boolean logic which is simply based on whether the condition is TRUE or FASLE.

38 Boolean Logic – Comparison Operator A comparison operator is one where the condition is either YES(true) or NO(false).

39 Boolean Logic – Logical Operator A logical operator takes TWO conditions and makes ONE truth statement.

40 Test the Labyrinth Save your code and make sure it has comments!


Download ppt "Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with."

Similar presentations


Ads by Google