Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Encoders to go Straight

Similar presentations


Presentation on theme: "Using Encoders to go Straight"— Presentation transcript:

1 Using Encoders to go Straight
Limit drifting when trying to go straight In this section we will look at if else Variables and types Applying all of this to help the robot go straight

2 Pseudo Code (What we are trying to get the robot to do)
While the robot has not reached the destination If the left motor has gone farther, slow the left motor and have right motor go at speed If the right motor has gone farther, slow the right motor and have the left motor go at speed If the motors are the same, have both motors go at speed

3 If Statements When your robot reaches an if Statement in the program, it evaluates the condition contained between the parenthesis. If the condition is true, any commands between the braces are run. If the condition is false, those same commands are ignored. Very similar to how a while loop works, but does not repeat the code!

4 Going Straight: Translating to Code
Pseudo Code While the robot has not reached the destination If the left motor has gone farther, slow the left motor and have right motor go at speed If the right motor has gone farther, slow the right motor and have the left motor go at speed If the motors are the same, have both motors go at speed

5 If-else statements The if-else Statement is an expansion of the basic if Statement. The “if” section still checks the condition and runs the appropriate commands when it evaluates to true Using the “else” allows for specific code to be run only when the condition is false. Either the “if” or the “else” branch is always run; no more, no less.

6 Chaining if..else if ..else

7 Implementing if..else

8 But… If the motors are not close in their Power to Speed then the difference between 50 and 63 might not be sufficient. So it will take some tweaking. Rather than changing the 63 to another value when modifying the ‘at speed’ needed, you can use variables.

9 RobotC Variables int float string char bool
Stores integer values: 5, 0, -100 float Stores floating point (real) values: 3.01, -5.21, 0 string Stores words: “Hello World” char Stores single characters: “A”, bool Stores Boolean (true, false) values

10 Code After Using Variables for Speed Values
Declaring the variables. type name Initialize the variables. Try modifying the fullSpeed and slowerSpeed values to see how if changes the robot behavior.

11 Summary motor[] SensorValue[] wait1Msec() while if if..else Conditions
Conjunctions Motors and Sensor Quadrature Encoder Strategies on going straight Timing vs. distance

12 Driving Straight Activity
Use the Clawbot Driving Straight II using encoders When complete, demo to Smith, continued on Physical Movement Challenges, and installing Shaft Encoders.


Download ppt "Using Encoders to go Straight"

Similar presentations


Ads by Google