Presentation is loading. Please wait.

Presentation is loading. Please wait.

ROBOTC for VEX Online Professional Development

Similar presentations


Presentation on theme: "ROBOTC for VEX Online Professional Development"— Presentation transcript:

1 ROBOTC for VEX Online Professional Development

2 Homework Questions Thoughts? Questions? Concerns?
Homework Policy: All homework is due Wednesday, March 20th by midnight.

3 Warm-up Questions What is Firmware?
Why does the robot spin if both motors are set to the same power level? What are valid power levels on the VEX? All commands that we want the robot to follow must be in _________? Each command must end with a(n) _________?

4 Troubleshooting Questions
Step 1: Identify the problem Step 2: What can we tell about the student’s understanding based on the problem? Step 3: What could we tell the student to address the problem, and their understanding? Just giving the answer to the student teaches dependence! This method teaches!

5 Troubleshooting Student: I want my robot to move forward, then turn. I had it moving forward, and added the turn. Now it’s turning, then moving forward.

6 Troubleshooting Student: My code compiles, but I get an error when I try to download it to the robot. Check: Is the robot turned on and sufficiently powered? (blinking green light) Is the robot connected to the computer? Is the correct platform type selected in ROBOTC? Is the correct port selected in ROBOTC? Has the driver for the programming cable been installed? Has the firmware been loaded on the VEX? Does the Master Firmware need re-downloaded? Is another ROBOTC window open, using the debugger windows?

7 Shaft Encoders

8 The Problem with Wait States
Motor Speed is affected by battery power If the battery is fully charged, the robot moves quickly If the battery is running low, the robot moves slowly Consequently, the robot will not move consistently as the battery power drains Makes completing the Labyrinth tricky Anyone experience these effects? Wouldn’t it be better if we could control the distance the robot moves, regardless of how long it took to complete?

9 Quadrature Shaft Encoders
How they work Digital counting sensor As the inner shaft spins, the encoder “counts” Capabilities and Resolution 360 “counts” per revolution of the inner shaft Counts Up and down Cortex counts by 1, PIC counts by 2 “Quadrature” vs. Original Original only detects 90 “counts” per revolution, only counts up

10 Shaft Encoders: Cortex

11 Better Movement with Encoders
Forward for Distance

12 Better Movement with Encoders
Turning

13 The SensorValue Command
The SensorValue command is used to read the value of sensors In the case of the encoders, it can also write values Consist of two parts: The SensorValue keyword The [sensorsPort#] or the [sensorsAlias] SensorValue[dgtl1] or SensorValue[leftEncoder]

14 While Loops While Loops are a form of Conditional Statements
Also known as ‘Control Statements’ Consist of three basic parts: The while keyword The (condition) The { code to be executed }

15 Better Movement with Encoders
Forward for Distance

16 Remember! It’s almost always better to clear your encoders before using them! Drift, jitter (from other components), outside forces, etc all play into encoder counts Absolute > Relative

17 Better Movement with Encoders
Practice implementing what you just learned in the Labyrinth Challenge! Watch VEX Cortex Video Trainer videos for review. Movement > Shaft Encoders

18 Moving Straight Even with the shaft encoders, the robot still veers to the left or right (probably). Does it have to? By comparing the values of the two encoders, we should be able to tell which side is falling behind, and adjust motor power in real time! Open the Moving Straight sample program and try it out!

19 Moving Straight

20 If Statements If Statements are a form of Conditional Statements
Also known as ‘Control Statements’ Consist of three basic parts: The If keyword The (condition) The { code to be executed }

21 If Statements (cont.) Can also contain an “Else” or “Else if” statement

22 Boolean Operators Operator Result > Greater than < Less than ==
Equal to != Not equal to <= Less than or equal to >= Greater than or equal to && AND || OR

23 Moving Straight

24 Variables

25 Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Variables A variable is a space in your robot’s memory where data can be stored, including whole numbers, decimal numbers, and words Variable names follow the same rules as custom motor and sensor names: capitalization, spelling, availability Variables can improve the readability and expandability of your programs

26 Variable Types Data Type Description Example Code Integer
Positive and negative whole numbers, as well as zero -35, -1, 0, 33, 100 int Floating Point Number Numeric values with decimal points (even if the decimal part is zero) -.123, 0.56, 3.0, float Boolean True or false – Useful for expressing the outcomes of comparisons true, false bool Character Individual characters, placed in single quotes ‘L’, ‘f’, ‘8’ char String Strings of characters, such as words and sentences placed in double quotes “Hello World!”, “asdf” string

27 Creating a Variable To create a variable you must give it a:
Type for type of data it will hold Name by which variable can be referenced Variables can be set to different values throughout program Naming variables follows the same rules as naming your Motors and Sensors Giving a variable an initial value is called “initializing the variable”

28 Common Variable Uses Variables are useful for keeping track of loop iterations The following code lets the loop run 10x Note that the side on the right of the equal sign is evaluated first, then set to the variable on the left. This is always the case.

29 Common Variable Uses Variables are useful for keeping track of sensor or timer values at different parts of the program

30 Common Variable Uses Variables are useful for keeping track of results from complicated equations

31 Global Variables Window
Displays all of the Global variables in your program in real-time

32 Moving Straight and Variables
Watch VEX Cortex Video Trainer videos for review. Movement > Automated Straightening

33 The M in STEM Current method for moving the robot: Do it smarter!
Guess-and-check - true for wait states and encoder rotations Do it smarter! We can measure the distance for the robot to travel We can measure the circumference of the wheel We know 360 degrees = 1 wheel rotation Spend minutes working out a solution Use your idea to move forward and reverse Discuss how well your ideas worked Discuss Turning Is having the robot turn 90 degrees the same as having the encoder turn 90 degrees? Why or why not?

34 The M in STEM How did you solve the math problem? Some common methods:
Scale Factor (“Scaling” multiples of a known quantity) Rate: Unit Ratio (# of X in a single Y, times the number of Y’s) “Rate” relationship Find #degrees/1in, then multiply that rate by the total What about #degrees per floor-line? Rate: Raw Ratio (# of X per # of Y, times the number of Y’s) Find 360degrees/8.6in, then multiply that rate by the total Direct Proportion (Traditional “ratio” equation) 8.6 in = 24 in deg X deg Solved mechanically using cross-multiplication Solved algebraically as a Linear Equation of One Variable

35 Everyone is a Math Teacher
How did you solve the math problem? Many STEM teachers will not be teaching in Math class, yet Math is clearly what they are teaching Make the math explicit; don’t waste the opportunity! Embrace multiple methods of solving the same problem; students need more tools at their disposal, not conflicting information about which ones are “better” than others (none are, use what works!)

36 Shaft Encoder Natural Language Commands

37 Until Commands that allow you to create behaviors where the robot acts “until” a certain event untilEncoderCounts() untilRotations()

38 Forward and Reverse for Distance

39 Precise Turning

40 ROBOT Motion Commands that cause the entire robot to perform a behavior moveStraightForRotations() moveStraightForTime()

41 Moving Straight

42 Additional Slides: Functions

43 Moving Straight Discussion
The automatic moving straight code works great, but imagine using it to solve the Labyrinth. Automatic moving straight code = ~20 lines 5 Forward movements needed for the Maze 5 x ~20 = ~100 Lines of code! And that doesn’t include turns or other commands! Notice that the moving straight code is mostly comprised of the same exact code, over and over. What if there were a way to reuse the same set of code? There is: Functions!

44 Functions Functions are used to group together several lines of code, which can then be referenced many times in task main, or even other functions. Convenient uses in the Labyrinth Moving Straight Turning 90 Degrees Left Turning 90 Degrees Right Creating Functions Simplified Example: Moving Forward Function Header (Part1 – The name of the function) Function Definition (Part 2 – The code that goes with the function) Using Functions Function Call (Part 3 – Where you want the function code to run)

45 Function Definition

46 Function Call

47 Advanced Functions What about the very similar lines of code that go with the automatically moving straight code? Is there a way to include those lines in the function? What’s different each time we use the code? The number of degrees for the distance of the straight movement! What programming tool do we have that lets us store numbers in our code? Variables! Functions allow use for a special kind of variable, called a Parameter. Parameters allow you to pass values into functions to account for small differences, like the number of degrees to move forward.

48 Advanced Function Definition

49 Advanced Function Call

50 Functions Watch VEX Cortex Video Trainer videos for review. Sensing> Behaviors and Functions


Download ppt "ROBOTC for VEX Online Professional Development"

Similar presentations


Ads by Google