Presentation is loading. Please wait.

Presentation is loading. Please wait.

Autonomy using Encoders

Similar presentations


Presentation on theme: "Autonomy using Encoders"— 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 Create a NEW program/Save
Save the code as Encoder Test

8 Motors & Sensors Setup

9 Motors & Sensors Setup

10 Modifying our Code

11 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. 500 is far too many counts for the distance that the robot needs to move.

12 Encoder count off?

13 Test the Encoder count

14 Making turns with the Encoder

15 Rule of thumb

16 Finish the program

17 Test & make changes to encoder counts

18 Motor power changes?

19 Motor Power Changes

20 What happened?

21 Encoder usefulness

22 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.

23 Automated Straightening

24 Automated Straightening
Take your current open program and save it.

25 Automated Straightening

26 Using the “RIGHT” Encoder

27 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.

28 Test!

29 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.

30 Test the Labyrinth

31 Making changes takes too much time

32 Behaviors and FUNCTIONS
Really, it seems like this whole ordeal is unnecessary. The command for setting the motor power inside all four of these behaviors is exactly the same. Why do we have to make the change four different times in four different places when they’re all exactly the same behavior? Recognizing that all four of these chunks of code represent the same behavior is key. In this lesson, you will learn how a control structure called a function can help by letting you define the moving-straight behavior as a custom command in the language of ROBOTC!

33 Behaviors and FUNCTIONS

34 Behaviors and FUNCTIONS
This is called the CALL.

35 Behaviors and FUNCTIONS

36 Behaviors and FUNCTIONS

37 Behaviors and FUNCTIONS

38 Behaviors and FUNCTIONS

39 Behaviors and FUNCTIONS

40 Behaviors and FUNCTIONS

41 Behaviors and FUNCTIONS

42 Behaviors and FUNCTIONS
If you compare the 2 sets of code you should now realize that by using functions you can greatly reduce the # of lines of code you need. 66 lines of codes vs. 103 lines of code!

43 Let’s test your understanding
Create new FUNCTIONS for your right and left turns. Compile and test the program to see if it makes it into the labyrinth. If successful, use COMMENTS to EXPLAIN each line of code in YOUR own words. Copy and paste the code in word for proper formatting and spell check. Be sure to place your NAME in the comments and turn the code in to the basket for grading.


Download ppt "Autonomy using Encoders"

Similar presentations


Ads by Google