robotc for vex online professional development. warm-up activity review/watch videos from vcvt...

56
ROBOTC for VEX Online Professional Development

Upload: tracy-lamb

Post on 04-Jan-2016

218 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

ROBOTC for VEXOnline Professional Development

Page 2: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Warm-up Activity

• Review/Watch videos from VCVT– Especially the ones from the Fundamentals and

Movement sections

• Work on:– Labyrinth Challenge with obstacles with real robot– Movement > Sentry Challenge or Utility > Robotics

Academy Challenge with virtual robot

Page 3: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Warm-up Questions

• What is Firmware?• What are valid motor power levels on the VEX?• All commands that we want the robot to follow

must be within _________?• Each command must end with a(n) _________?• What VEX sensors are Analog? Digital? What

distinguishes them?

Page 4: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Standard ROBOTC: Basic Movement

Page 5: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Platform Type

1. Choose ROBOTC for VEX Robotics 4.X (not graphical)

2. Choose VEX 2.0 Cortex3. Deselect Natural Language if

needed

Page 6: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Get Your Motors Running

• Motor Check– Right Motor is plugged into MOTORS 2– Left Motor is plugged into MOTORS 3

• Open Sample Program– File > Open Sample Program > Training Samples >

Motor Port 3 Forward

Page 7: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Motor Port 3 ForwardDefines the “main task” of the robot

All commands belonging to task main must be in-between these curly braces

Page 8: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Motor Port 3 Forward

Turns the port3 motor on at full power forward

Page 9: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Motor Port 3 Forward

Robot stays here in the program for 3000 milliseconds

End Result: robot spins one motor for 3 seconds

Try it out!

Page 10: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Basic Movements

• Forward / Reverse

Page 11: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Basic Movements

• Point Turns

Page 12: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Basic Movements

• Swing Turns

Page 13: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Basic Movements

• Manual Adjustments

Page 14: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Movement Challenges

• VCVT Videos (recommended)– Watch videos in the Movement > Moving Forward

Section– Watch videos in the Movement > Speed and Direction

Section

• The Labyrinth– Remember to Pseudocode– Remember to Journal– The two are not mutually exclusive!

Page 15: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Troubleshooting

Page 16: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Troubleshooting Method1. Identify the problem. Don't tell me how to fix the

problem. Just tell me what it is.

2. What can we tell about the student because of the problem? What do they know? What don't they know?

3. What can we tell the student to fix their understanding AND the problem?

• Just giving the answer to the student teaches dependence!

• This method teaches!

Page 17: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

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.

Page 18: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Troubleshooting• Student:

My code won’t compile.

Page 19: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Troubleshooting• Student: I want my robot to move forward, then reverse. I

had it moving forward, and added the reverse, but it never actually backs up.

Page 20: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

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 lights)

– 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 ROBOTC firmware been loaded on the VEX?– Does the Master Firmware need re-downloaded?– Is another ROBOTC window open, using the debugger

windows?

Page 21: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

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?

Page 22: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Better Movement:Integrated Motor

Encoders

Page 23: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Integrated Motor Encoders• How they work

– “I2C” Smart Sensor

– Replaces the back plate of 269 and 393 Motors

– As inner striped wheel spins, internal light sensor detects and counts

• Capabilities and Resolution– 627 Counts Per Revolution in High Torque Configuration

– 392 Counts Per Revolution in High Speed Configuration

– Up to 8 encoders “daisy chained” in a row

– Counts Up and down

– Allows you to control the distance a robot moves, by monitoring how much the wheels spin

– Due to “closed-loop” configuration, “PID” control is possible

Page 24: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Motors and Sensors Setup

• Enabled and configured on the Motors tab

• Motor “Type” is important, as their resolution is not uniform

Page 25: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Testing your Encoder Setup

• You can try to follow the wires from the sensors to the I2C and Motor ports…

• …or use the Motor Debug Window!

Page 26: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Better Movement with Encoders

• Forward and Backward for Distance

Page 27: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Better Movement with Encoders

• Turning Right and Left

Page 28: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

PID Control • Proportional-Integral-Derivative• With the integrated motor encoders, we have

what is called a “closed-loop” system– The Cortex knows exactly how fast the motors should be

spinning versus how fast they are actually spinning and can make rapid adjustments to compensate for the difference

Page 29: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Variables• A variable is a space in your robots 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

Page 30: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Variable TypesData 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, 1000.07

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

Page 31: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Creating a Variable• To create a variable you must give it a:

1. Type for type of data it will hold

2. 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”

Page 32: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

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.

Page 33: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Common Variable Uses

• Variables are useful for keeping track of sensor or timer values at different parts of the program

Page 34: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Common Variable Uses

• Variables are useful for keeping track of results from complicated equations

Page 35: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Variable Exercises

• Create and initialize the following variables in your Labyrinth Program:– int motorSpeed– int encoderCount1– int encoderCount2– int encoderCount3– int encoderCount4

• Replace the corresponding values in your program with variables.– Download and run. What happens?– Try increasing and decreasing the speed of your robot only by

adjusting the variable.

Page 36: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Variables Continued

Page 37: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

More Data Types• There are 8 different types of variables in

ROBOTC– Integer (int) – Memory Usage: 16 bits / 2 bytes

• Integer Numbers Only• Ranges in value from -32768 to +32767

– Long Integer (long) – Memory Usage: 32 bits / 4 bytes• Integer Numbers Only• Ranges in value from -2147483648 to +2147483647

– Floating Point (float) – Memory Usage: 32 bits / 4 bytes• Integer or Decimal Numbers• Variable precision, maximum of 4 digits after decimal

Page 38: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

More Data Types• There are 8 different types of variables in

ROBOTC– Single Byte Integer (byte) – Memory Usage: 8 bits/1 byte

• Integer Numbers Only• Ranges in value from -128 to +127

– Unsigned Single Byte Integer (ubyte) – Memory Usage: 8 bits / 1 byte

• Integer Numbers Only• Ranges in value from 0 to +255

– Boolean Value (bool) – Memory Usage 4 bits / .5 bytes• True (1) or False (0) values only.

Page 39: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

More Data Types• There are 8 different types of variables in

ROBOTC– Single Character (char) - Memory Usage:

8 bits / 1 byte • Single ASCII Character only• Declared with apostrophe – ‘A’

– String of Character (string) - Memory Usage: 160 bits / 20 bytes

• Multiple ASCII Characters• Declared with quotations – “ROBOTC”• 19 characters maximum per string (NXT Screen limit)

Page 40: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Constants• Some additional notes

– Adding “const” in front of a variable will make that variable a constant.

• This will prevent the variable from being changed by the program

– Constants do not take up any memory on the VEX IQ– The VEX IQ has room for 7500 bytes of variables

Page 41: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

The M in STEM

Page 42: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

The M in STEM• Current method for moving the robot:

– 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 627 encoder counts = 1 wheel rotation– Spend 10 - 15 minutes working out a solution

• Use your idea to move forward and reverse– Discuss how well your ideas worked

• Now Consider Turning– Is having the robot turn 90 degrees the same as having the

encoder turn 90 counts? Why or why not?

Page 43: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

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

627 deg X deg• Solved mechanically using cross-multiplication• Solved algebraically as a Linear Equation of One Variable

Page 44: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

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!)

Page 45: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Exercise: Precise Turning

• Now that you know how to calculate the encoder counts for any forward movement, can you apply that to point turns and swing turns?

• Figure it out! • Keep in mind what “distance” the wheels are

traversing to accomplish the turn.• Be prepared to share your findings!

Page 46: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Programming Discussion• The behaviors we are using work, but imagine

using them to solve the Labyrinth.– Moving Forward or Turning with Encoders = ~8 lines– 7 movements needed for the Labyrinth– 7 x ~8 = ~56 Lines of code!

• Notice that the behaviors are 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!

Page 47: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Functions

Page 48: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

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 Forward– Turning 90 Degrees Left– Turning 90 Degrees Right

• Creating Functions– 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)

Page 49: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Function Definition

Page 50: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Function Call

Page 51: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Function Practice

• Create Functions to:– Point Turn 90 Degrees Right– Point Turn 90 Degrees Left– Reverse for 2 Rotations

• Review VCVT Videos– Note: The code is different,

but the process is the same

Page 52: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

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.

Page 53: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Advanced Function Definition

Page 54: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Advanced Function Call

Page 55: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Advanced Function Practice

• Expand your previous functions :– Point Turn x Degrees Right– Point Turn x Degrees Left– Reverse for x Rotations

• Review VCVT Videos

Page 56: ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement

Homework!• Homework assignments can always be found

and turned-in on CS2NLearn

• You’ll also be expected to watch a series of videos for review• Optional practice quizzes will prepare you for the certification

exam at the end