robotc for vex on-site professional development. lab procedures logging onto computers –log in...

132
ROBOTC for VEX On-Site Professional Development

Upload: amara-smales

Post on 01-Apr-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC for VEXOn-Site Professional Development

Page 2: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Lab Procedures• Logging onto computers

– Log in with: teachers / teachers1

• VEX Robots/chargers– Make sure during breaks, lunches and end of day to

charge your robot

• Headsets– Each workstation has two headsets to allow both

partners to watch the videos at the same time

• Teacher folders and journals

Page 3: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC this Week

• There are several versions of ROBOTC on your desktops

• This class we will use ROBOTC 3.0 Beta as much as possible

Page 4: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Discussion

• What is a robot?

• What can you teach with a robot?

• Journaling

Page 5: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

VEX 0.5 PICSystem Overview

Page 6: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

VEX 0.5 PIC Testbed• Features:

– VEX PIC– 2 Motors– Servo Motor– Ultrasonic

Rangefinder– Potentiometer– Ambient Light

Sensor– Line Tracking

Sensor– Limit Switch– Bumper Switch– RF Receiver– LED

Page 7: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

VEX 0.5 PIC Overview• Coordinates the flow of

information and power on the robot

• All electronic components interface with the microcontroller

• 8 Motor Ports• 16 Analog/Digital Ports for

Sensors• Rx1 and Rx2 Ports for

Radio Control

Page 8: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Overview

Page 9: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Background Information• ROBOTC is developed specifically with teachers,

classrooms, and competitions in mind• Complete programming solution for the VEX PIC, VEX

Cortex, and several other popular robot platforms• Approved for VEX Robotics, BEST, TSA and RoboFest

Competitions!• Only programming language for the VEX PIC and VEX

Cortex with a real-time debugger– You’ll learn more about this feature later on

• Very similar to industry-standard C programming– Students get real-world programming experience

Page 10: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Industry Standard Coding

Students that learn ROBOTC Programming are also learning key components of Industry Standard Programming Languages...

Page 11: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Industry Standard IDE

Students programming in the ROBOTC IDE are also learning how to use features in Industry Standard IDE’s...

Page 12: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Visual Studio IDE and Code

Page 13: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC IDE and Code

Page 14: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Features

Page 15: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Platform Type

Allows you to toggle ROBOTC’s programming mode between the VEX PIC and VEX Cortex, will enable features and commands for the system

Page 16: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Start Page

Displays the latest ROBOTC news, version of ROBOTC, and ROBOTC Resources

Page 17: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Sample Programs

Over 75 Included ROBOTC Sample programs, organized by robot behavior

Page 18: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Comments• Comments are used to make notes in code for

the human programmers• Every sample program contains comments

pertaining to robot configuration, ROBOTC commands, robot behavior, etc

• // Single line comment – everything after “//” is ignored by the ROBOTC compiler

• /* Multi-line comment*/ - everything between the “/*” and “*/” symbols is ignored by the ROBOTC compiler

Page 19: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Help

In-depth explanations about the ROBOTC interface, commands, debugger, etc

Page 20: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Function Library

Lists the available functions, with a description.List of available functions will expand or shrink depending on the “Menu Level”

Page 21: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Menu Level

Customizes the ROBOTC interface and Function Library based on the user’s experience level

Page 22: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Motors and Sensor Setup

• One central place to configure and name all of the motors and sensors attached to your Cortex

Page 23: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Teaching ROBOTC for IFI VEX Robots

Page 24: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure
Page 25: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Teaching ROBOTC for IFI VEX Robots (TRC4V)

• 40 tutorial videos• 275 pages of printable guides aligned to

the videos• 50 pages of supplementary “helper

guides”• 35 programming challenges • Freely available at www.robotc.net

Page 26: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Student-Paced Instruction

• Everyone learns different things at different paces• Everyone MUST move at a different pace

– Going too fast results in failure and frustration– Going too slow results in loss of attention (i.e. future failure)

• TRC4V can be used as a teaching aid– One instructor can’t teach at 20 different paces simultaneously– One instructor plus 20 computers can

Page 27: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

System Configuration

Page 28: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Downloading Firmware

• What is Firmware?• Step 1: Download Master Firmware• Step 2: Download ROBOTC Firmware• Step 3: Power-cycle the VEX

Page 29: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC “Natural Language”

Page 30: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Natural Language• Goal is to lower the barrier of entry into

syntax-based programming by simplifying the code and using more “natural” command names

• Lines of code for common robot behaviors are consolidated into single commands– forward();– lineTrackforTime();– stop();– untilBump();

Page 31: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Natural Language

• The Natural Language is an additional Platform Type in ROBOTC:

Page 32: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOT Motion

• Commands that cause the entire robot to perform a behavior

Page 33: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Setup

• Allows you to specify what type of robot configuration you have from pre-specified models (RECBOT, Swervebot)

Page 34: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Movement

• Commands that allow you to control individual motors / servos

Page 35: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Special

• Commands that control the more unique VEX Hardware – LED’s and Flashlights

Page 36: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Until

• Commands that allow you to create behaviors where the robot acts “until” a certain event – Button Press– Encoder Count

Reached

Page 37: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Wait

• Commands that wait for an elapsed amount of time in seconds or milliseconds

Page 38: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Sample Programs

Page 39: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Moving Forward and Backward

Page 40: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Basic Programming:Motor and Wait Commands

Page 41: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

VEX Motors

• 3 Main Types:– Original 3-wire motor– Newer 2-wire motor 269– Newer 2-wire motor 393

• All motors are programmedthe same way in ROBOTC– Accept values between 127 (full forward) and -127

(full reverse)

Page 42: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Motor 2 for 5 Seconds

Displays configuration changes from the Motors and Sensors Setup

Defines the “main task” of the robot

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

Page 43: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Motor 2 for 5 Seconds

Turns the port2 rightMotor on at half power forward

Page 44: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Motor 2 for 5 Seconds

Causes the robot to wait here in the program for 5.0 seconds

Page 45: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Motor 2 for 5 Seconds

Stops the port2 rightMotor.

End Result: rightMotor spins for 5.0 seconds.

Page 46: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Quick ROBOTC Exercise

• Create this program yourself and download it to the Robot– Using the Program Debug Window

Page 47: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Renaming and Reversing• Robot > Motors and Sensors Setup

– Optional with Motors (not Sensors)– Giving Motors custom names– Reversing motor polarity

Page 48: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Naming Rules• The Motors and Sensor Setup window allows

you to give your motors and sensors custom names. The names, however:– Should be descriptive of the sensor or motor they

refer to (rightMotor, frontBumper, ect.)– Must be all one word made up of letters, numbers,

and underscores– Must contain no special characters (&, $, /, ect.)– Cannot already be a ROBOTC reserved word (task,

motor, true)

Page 49: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Quick ROBOTC Exercise

• Make Changes to the Program1.Turn on leftMotor

• Download and watch result

2.Reverse both motors• Download and watch result

Page 50: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Motor Exercises

1. Turn the rightMotor on forward at full speed for 6 seconds, then stop.

2. Turn the leftMotor on in reverse at three-fourths speed for 2.5 seconds, then stop.

3. Turn both motors on at half power for 3 seconds, stop for two seconds, reverse at half power for 3 seconds, then stop.

Page 51: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure
Page 52: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Servo Motors• Very similar in appearance

to the normal 3-wire motor• Very different in operation

– Rotates between 0 and ~120 degrees– Where the motor is set to a “power value” the servo is set to

a “position value”– -127 = 0 degrees, 0 = 60 degrees, 127 = 120 degrees, etc– Servo motors can be programmed exactly the same way as

normal motors in ROBOTC, so the programmer must know the hardware and intent

– setServo() Natural Language command

Page 53: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Servo Exercises• Example: Program the servo to go to position

-127 for 2 seconds, position 0 for 2 seconds, and position 127 for 2 seconds.

• Individual: Program the servo to go to position -127 for 2 seconds, position -63 for 3 seconds, position 0 for 2 seconds, position 63 for 3 seconds, and position 127 for 2 seconds.

Page 54: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

VEX LED• Plugged into A/D Port 16• Set as “VEX LED”

– Either ON or OFF

• 1 ON and 0 is OFF• Red, Green, and Yellow

colors available• turnLEDOff(), turnLEDOn

NL commands

Page 55: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Program Planning

Page 56: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Behavior Based Programming• A behavior is anything your robot does:

– turning on a single motor, moving forward, tracking a line, navigating a maze

• Three main types of behaviors: – basic behaviors – single commands to the robot (turn on a motor)– simple behaviors – simple task performed by the robot (move

forward, track a line)– and complex behaviors – robot performs a complex task (solve

the maze)

• Complex behaviors can always be broken down into simple behaviors, which are then broken down into basic behaviors

Page 57: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

The Labyrinth Challenge

Page 58: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

The Labyrinth Challenge

Page 59: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Programming Discussion• The Challenge: The Labyrinth • The Solution: ???• The Programmer’s (your) Role

– Understanding Program Flow and Behavior Based Programming– Plan out the robot’s path / actions - Pseudocoding– Translate the Pseudocode into real code

• The Robot’s role– To carry out your instructions!

• The Solution: Programmer and Robot working together, fulfilling their roles– True for all robotic challenges!

Page 60: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Pseudocode• Pseudocode is a shorthand notation for

programming which uses– informal programming structures (if touch1 is pressed…)– verbal descriptions of code (move forward, stop)

• Emphasis is placed on expressing the behavior or outcome of each portion of code rather than on correct syntax (it should be reasonable, though).

• Your lines of Pseudocode should also be listed in the same order as they will appear in the ROBOTC Program

Page 61: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Pseudocode

• Sample Pseudocode:

Page 62: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Pseudocode

• Additional Details:– Pseudocode is used to outline a program before

translating it into proper syntax.– Helps in the initial planning of a program, by creating

the logical framework and sequence of the code.– An additional benefit is that it can be translated into

different programming languages and is therefore somewhat universal.

Page 63: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Putting it all Together

• Effective Program Planning is essential to writing correct code. Carrying out that plan is equally important!

• Once you have your plan, don’t try to implement it all at once!

• Systematically add sections of code, testing at every step!

Page 64: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure
Page 65: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Rules/Syntax• What does every program have to have?

– task main() – Set of "Curly Braces“ {}

• In what order does ROBOTC run a program?– Sequentially – Top to Bottom

• What is whitespace?– Space in a program to make it easier for a human to read.

• Simple Robot Commands (statements) always end with a…?– Semicolon ;

Page 66: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Rules/Syntax• Paired Punctuation

– Some functions have "square brackets“ [] , other have "parenthesis“ ()

– How do I keep them straight?• Memorization• Functions Library

• Control Structures– Just like task main, they have a set of curly braces defining their

beginning and end. {}– Example?

• Comments– //Necessary Evil– Get into the habit now, or you won't do it ever– Your students learn their habits from you…

Page 67: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

ROBOTC Rules/Syntax• Syntax is the cause of 80% of

programming errors…• Most important thing to do when

troubleshooting: Check Syntax– Missing Semicolons– Incorrect Braces on Structures– Misspelled words– Improper ‘case’ – motor vs. MoToR

• ROBOTC is friendly about most of these errors... but can’t catch everything.

Page 68: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure
Page 69: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Basic Programming:Until Commands

Page 70: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

The Problem with Wait States• Motor Speed is affected by battery power

– If the battery is fully charged, the motors move quickly– If the battery is running low, the motors move slowly– Consequently, the robot will not move consistently as

the battery power drains

• Anyone experience these effects?• Wouldn’t it be better if we could control

how much the robot moves, regardless of how long it took to complete?

Page 71: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Sensor Information:Touch Sensors

Page 72: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Touch Sensors• Touch Sensor Check

– Plugged into A/D 14 & 15

• How they work– Digital sensor - Pressed or Released – 1 = pressed– 0 = released

• Two Types– Limit Switches – Bumper Switches

• Using them– The SensorValue[] command– untilTouch, untilRelease, untilBump

NL commands

Page 73: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Touch Sensors• Other Properties

– Limit Switch arm can be bent to create a more ideal “hit area”– Both sensors spring back to “open” position

• Limitations– Watch out for “bouncing”. As the sensor is pressed or released, it may

bounce between 0 and 1 very briefly and quickly. – A very brief wait can be inserted as part of the untilBump() command, or

after the untilTouch() and untilRelease() commands to reduce the bouncing effect:

Page 74: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Bumper Switch Exercise• Example: Wait for the bumper switch to be

“bumped” before the right motor turns on at half power for 5 seconds, then stops.

• Individual: Wait for the bumper switch to be “bumped” before both motors turn on at half power, and stay on until the sensor is bumped again. Both motors should then move in reverse at half power for 3.5 seconds.

Page 75: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure
Page 76: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Sensor Information:Potentiometer

Page 77: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Potentiometers• Potentiometer Check

– A/D Port 3 • How they work

– Analog sensor– Measures rotation of a shaft

between 0 and ~265 degrees– PIC returns values 0 - ~1023– Cortex returns values 0 - ~4095

• Using them– The SensorValue[] command– untilPotentiometerGreaterThan, untilPotentiometerLessThan NL commands

Page 78: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Potentiometers• Other Properties

– Internal mechanical stops prevent the potentiometer from turning a full revolution.

• Limitations– Caution: Excess torque against the internal mechanical stops

(can be caused by hand or by a VEX motor) will cause them to wear away. The potentiometer will continue to function, but will have a “dead zone” where the mechanical stops were, where no new values are sent.

– Switching the direction the potentiometer is facing will also switch the direction it “counts”. For example: counter-clockwise turns will count 0 to 1023on one side; on the other counter-clockwise turns will count 1023– 0.

Page 79: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Potentiometer Exercise• Example: Turn on the LED until the

potentiometer value is greater than 512. Then the LED should turn off, and the leftMotor should turn on for 3.5 seconds.

• Individual: Turn on the LED until the potentiometer value is greater than 512. Then the LED should turn off, and the leftMotor should turn on until the potentiometer is less than 512.

Page 80: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Sensor Information:Shaft Encoders

Page 81: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

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– Allows you to control the distance a robot moves, by monitoring how

much the wheels spin.

• Using them– The SensorValue[] command– untilEncoderCounts, untilRotations,

moveStraightforTime, moveStraightforRotations NL commands

Page 82: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Shaft Encoders• Other Properties

– Switching which wire is in the A/D port vs. the INTERRUPT port will reverse the polarity of the encoder (whether it counts up or down for CW turns).

– There is an older single-wire version of the encoder, which only counts 90 degrees per revolution of the encoder.

– The Natural Language commandsautomatically clear the encoderfor you. Otherwise, clearing the encoders before using them to track rotations is recommended for consistency.

Page 83: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Shaft Encoder Exercise• Example: Turn on both motors forward until the

encoder has counted 480 degrees.

• Individual: Turn on both motors forward until the encoder has counted 480 degrees. Then turn on both motors in reverse until another 3.5 rotations of the encoder have passed.

Page 84: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure
Page 85: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Sensor InformationUltrasonic Rangefinder

Page 86: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Ultrasonic Rangefinder• Ultrasonic Rangefinder Check

– Output wire plugged into INTERRUPT Port 1 (Input is always first)

– Input wire plugged into A/D Port 10• How they work

– Similar to how bats and submarines work– Digital sensor – but returns distance values between 0 & 255

inches• (Can also return values of -1 or -2 if used improperly)

– Cortex resolution can be in inches, cm, or even mm• Using them

– The untilNear and untilFar NL commands

Page 87: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Ultrasonic Rangefinder• Other Properties

– The Ultrasonic Rangefinder is able to detect objects in a “cone” field of view. As objects get further away, the sensor is able to detect them further away from the center of the sensor.

– The sensor bases distance calculations off of sound waves, which means that some objects may not be detectable: soft objects that absorb sound, sharp objects that deflect sound, etc.

– Do not use the ultrasonic sensor as the very first command in your code. Until the first sound echo returns to the sensor, it will have a value of -1. A simple delay at the beginning of your program solves this.

Page 88: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Ultrasonic Exercise• Example: Turn on both motors until an object is

within 10 inches of the sensor, then turn the motors off, and turn the LED on for 6.25 seconds.

• Individual: Wait until an object is detected within 15 inches to turn the motors on. Then wait for the object to move more than 20 inches away before turning the motors off.

Page 89: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure
Page 90: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Sensor InformationLine Tracker

Page 91: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Line Tracking • “Active” Light Sensor• Set of 3 Analog Sensors• Sends out a IR beam, and

measure how much is reflected back

• VEX Cortex returns values between 0 and 4095

• VEX PIC returns values between 0 to 1023

• Using them– The SensorValue[] command– untilDark, untilLight,

lineTrackforDistance, lineTrackforTime NL commands

Page 92: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Line Tracking• Other Properties

– The Line Tracker should be kept between ¼ and 1/8 of an inch of what it’s measuring for the best results.

– Constant, consistent lighting is also very important for achieving repeatable robot behavior.

– In order to use the Line Tracking sensor(s) you must first calculate a threshold that allows it to distinguish light from dark.

Page 93: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Thresholds Overview• A Threshold is a value (usually halfway

between) two extremes– Light and dark (Light sensors)– Near and Far (Ultrasonic)

• Thresholds allow your robot to make decisions via Boolean Comparisons

• Line Following Kits come with 3 sensors– To use all three, you must choose a Threshold that will work

with all 3 sensors, or 3 separate Thresholds

• The Testbed has only one sensor– You only need to calculate the Threshold for that sensor

Page 94: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Threshold Calculation• Calculate an appropriate Threshold with the

aid of the Sensor Debug Window1. In ROBOTC, create a program that configures your Line

Following sensor.

Page 95: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Threshold Calculation

2. Download the Program to the Robot

3. Open the Sensor Debug Window

Page 96: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Threshold Calculation

4. Verify that the Program Debug Window’s Refresh Rate does not display “Continuous” and press the Start button.

*Press the “Continuous” button if it does.

Page 97: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Threshold Calculation

5. Place a light colored object (or no object) above the line tracking sensor.

6. Record the value for the sensor displayed in the Sensors Debug Window. Only record the value for Analog Port 1 “in1”.

*values displayed will vary from your values

Page 98: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Threshold Calculation

7. Place a dark object above the line tracking sensor (or completely block it).

8. Record the value for the sensor displayed in the Sensors Debug Window.

*values displayed will vary from your values

Page 99: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Threshold Calculation

9. Add the two values and divide by two. The result is the threshold for that sensor.

Light reading + Dark Reading

2= Threshold

10. Use the threshold(s) in your program

Page 100: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Line Tracker Exercise

• Example: Move the servo to position 127 until a light object is detected, then have the servo move to position -127.

• Individual: Move the servo to position 127 until a dark object is detected, then have the servo move to position -127.

Page 101: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Sensor InformationAmbient Light Sensor

Page 102: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Ambient Light Sensor• “Passive” Light Sensor• Measures the amount of

ambient light in its environment• Cortex returns values between 0

and 4095• PIC returns values between 0

and 1023• Range is 0 – 6 feet from the

sensor• Using them

– The SensorValue[] command– untilDark, untilLight, NL

commands

Page 103: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Light Sensor Exercise

• Example: Program the LED to turn on for 5 seconds when the room lights go out

• Individual: Program the LED to turn on when the lights go out, and back off when the lights turn back on.

Page 104: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Decision Making:while loops and Boolean Logic

Page 105: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

While Loops• A while loop is a structure within ROBOTC which

allows a section of code to be repeated as long as a certain condition remains true.

• There are three main parts to every while loop.

Page 106: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

1. The word “while”• Every while loop begins with the keyword “while”.

Page 107: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

2. The Condition• The condition controls how long or how many times a

while loop repeats. While the condition is true, the while loop repeats; when the condition is false, the while loop ends and the robot moves on in the program.

• The condition is checked every time the loop repeats, before the commands between the curly braces are run.

Page 108: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

3. Commands to be Repeated• Commands placed between the curly braces will repeat

while the (condition) is true when the program checks at the beginning of each pass through the loop.

Page 109: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Boolean Logic

Decisions robots make must always based on questions which have only two possible answers: yes or no, true or false.

Statements that can be only true or false are called Boolean statements, and their true-or-false value is called a truth value.

Page 110: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Boolean Logic

Page 111: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure
Page 112: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

While Loop Exercise 1

• Example: Using the Ambient Light Sensor, program the LED to turn on when the lights in the room go out (or the sensor is blocked), and turn back off when the lights are turned back on, forever.

• Individual: Expand the previous program to loop only while the limit switch isn’t pressed.

Page 113: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Timers• More loop control please?

– Question: Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time?

– Answer: Nowhere! We need something else.

• Solution: Timers– Can be thought of as internal stopwatches (4 available)– Like encoders, timers should be “cleared” anytime before they

are used• Watch where you clear them!

Page 114: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Timers

In the program below, timer T1 is used as the condition for the while loop, which will run for 30 seconds:

Page 115: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

While Loop Exercise 2

• Example: Program the greenLED to repeatedly turn on for 2 seconds, then off for 2 seconds, while less than 20 seconds have elapsed.

• Individual: Program the servo to go to position 127 for 3 seconds, then position -127 for 3 seconds, while less than 30 seconds have elapsted.

Page 116: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Decision Making:if, if-else, and Boolean Logic

Page 117: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

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!

Page 118: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

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.

Page 119: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

If-else Exercise 1

• Example: Program the LED to turn on if the bumperSwitch is pressed, and off if it’s released. Loop Forever.

• Individual: Convert the previous program to use an if-else.

Page 120: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Multiple If-else Statements• Be careful when using two separate if-else

statements, particularly when they are used to control the same mechanism.

• One branch of each if-else statement is always run, so you may create a scenario where the two sets of “fight” eachother.

Page 121: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Multiple If-else Statements• In this example, if

one of the touch sensors is pressed, the rightMotor will be turned on in one if-else statement, and immediately turned off in the other.

Page 122: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Multiple If-else Statements• This can be

corrected by embedding the second if-else within the else branch of the first, so that it only runs if the first condition is false.

Page 123: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

If-else Shorthand• An embedded if-else can also be represented as

an else if:

Page 124: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Closing Thoughts

• Downloading Firmware• ROBOTC Natural Language• Behavior Based Programming • Pseudocode and Program Flow • Basic Motor Commands and Wait States• Until Statements with VEX Sensors• Decision Making

Page 125: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Remote Control

Page 126: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Remote Control• An out-of-box VEX Microcontroller comes with

basic built-in Radio Control functionality– The Radio Control Transmitter can be configured to allow some

customization of that built-in functionality– Still very limited customizability and usefulness!

• The ROBOTC firmware enables full customization of how the Radio Control Transmitter signals controls the VEX – By default ROBOTC turns off reception from the transmitter to

save battery life during autonomous programming– One line of code turns it back on

Page 127: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Remote Control• One Transmitter continuously sends out 6

separate values over 6 separate channels– Values range from -127 to 127– Doesn’t something else have values that range from -127 to

127?

• The “crystal” number must match on the transmitter and receiver – The crystal is what controls the frequency of the transmission– One transmitter can control multiple robots, so be careful in your

classrooms– 13 different crystals/frequencies are available

Page 128: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Radio Control Reset• Since the Radio Control Transmitter can be

configured, there’s the possibility that it’s configured inappropriately for our purposes.– Watch the Radio Control Setup and Values and Axes (Part 1)

Videos in TRC4V, found in Radio Control > Control Mapping– Be sure to follow along with the Radio Control Setup Video!

Page 129: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Radio Control Signals

Page 130: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Remote Control Exercise 1

• Example: Implement Basic Remote Control with a while loop.

• Individual: Expand the previous program to only run for 30 seconds.

Page 131: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Remote Control• Direct Value Mapping

– Values from the transmitter are directly used to control the motors (1:1 ratio)

• Program Flow Tracing– Radio Control with Wait States– Radio Control with a Loop (real-time control)

• Indirect Value Mapping– Values from the transmitter are modified before being used to

control motors– Can make the robot easier to control– Appropriate in situations that require more “delicate” movements– Notice: the robot reads the right side of the equal sign first

Page 132: ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure

Remote Control Exercise 2

• Example: Add button control to the basic remote control program so that the servo moves to position 127 when the top Ch5 button is pressed.

• Individual: Expand the previous program so that the servo spins to -127 when the bottom button is pressed.