35
Developed in collaboration with Introduction to Programming

Introduction to Programming

  • Upload
    diamond

  • View
    87

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to Programming. ROBOTC Start Page. Displays the latest ROBOTC news, version of ROBOTC, and ROBOTC Resources. Platform Type. Select Innovation First, then Natural Language. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction  to Programming

Developed in collaboration with

Introduction to Programming

Page 2: Introduction  to Programming

ROBOTC Start Page

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

Page 3: Introduction  to Programming

Platform Type

Allows you to toggle ROBOTC’s programming mode between the Natural Language (VEX Cortex), VEX Cortex, and the VEX PIC; enables features and commands specifically for the selected system

Select Innovation First, then Natural Language

Page 4: Introduction  to Programming

VEX Cortex Download Method

Allows you to specify:1. How programs are downloaded 2. Whether the Cortex looks for a

VEXnet connection when it starts up

Page 5: Introduction  to Programming

Sample Programs• To generate the Natural Language Function

Library, go to File, Open Sample Programs, PLTW, PLTWtemplate

Page 6: Introduction  to Programming

Function Library

The Function Library will be populated by all of the Natural Language commands. These can be drag-and-dropped into your program.

Place you cursor over the commands for more details about each one.

Page 7: Introduction  to Programming

ROBOT Motion

• Commands that cause the entire robot to perform a behavior

Page 8: Introduction  to Programming

Setup

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

Page 9: Introduction  to Programming

Movement

• Commands that allow you to control individual motors / servos

Page 10: Introduction  to Programming

Special

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

Page 11: Introduction  to Programming

Until

• Commands that allow you to create behaviors where the robot acts “until” a certain event. For example,– Button Press– Potentiometer Value

Page 12: Introduction  to Programming

Wait

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

Page 13: Introduction  to Programming

ROBOTC Help

Includes in-depth explanations about the ROBOTC interface, commands, debugger, ect

Page 14: Introduction  to Programming

Help Documentation

Additional detail about the Natural Language commands can be found in the ROBOTC Help under “Natural Language Functions”

Page 15: Introduction  to Programming

Motors and Sensors Setup Menu

Allows you to configure and name all of the motors and sensors connected to your Cortex.

Page 16: Introduction  to Programming

Motors and Sensors Setup Menu

The information in ROBOTC Motors and Sensors Setup should match the schematic on your project lab sheets.

Page 17: Introduction  to Programming

Comments

• Comments are used to make notes for the human programmers

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

Page 18: Introduction  to Programming

Comments

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

Page 19: Introduction  to Programming

Let’s start a ROBOTC Program

Page 20: Introduction  to Programming

ROBOTC Practice Program• Open a Sample Program

Go to File > Open Sample Program > PLTW>PLTWtemplate

Page 21: Introduction  to Programming

ROBOTC Practice Program1. Rename file and save to student directory

2. Complete heading information

3. Describe task

Page 22: Introduction  to Programming

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 23: Introduction  to Programming

ROBOTC Practice Program

• Write pseudocode turn the motor on for 3 seconds at full power, then off for 10 seconds. Then back on for 3 seconds at ½ speed, off for 2 seconds and reverse at ½ power for 3 seconds.

Page 24: Introduction  to Programming

ROBOTC Practice Program

• Complete Motors and Sensors Setup

• Notice the #pragma statements that are automatically generated

Page 25: Introduction  to Programming

ROBOTC Practice Program• Convert pseudocode to program code using the

Natural Language Function Library to drag and drop commands.

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

Defines the “main task” of the robot. Every program must contain a task main

Page 26: Introduction  to Programming

ROBOTC Practice Program

1. Save Program2.Connect the Cortex to the Computer (via

USB)3.Turn on the Cortex4.Go to Robot > Compile and Download

Program (f5)5.Run the program – Observe the motor turn

on and off and reverse.

Page 27: Introduction  to Programming

ROBOTC Practice Program

Edit the program to start when a pushbutton switch is pressed and stop when a limit switch is pressed.

Page 28: Introduction  to Programming

ROBOTC Practice ProgramYou may notice warnings or errors.• Make sure you spell motor and sensor

names exactly as defined in Motors and Sensors setup.

• A ; is needed at the end of each line of code.

• Don’t forget every open parenthesis needs a closing parenthesis.

• What is wrong with line 31?

Page 29: Introduction  to Programming

ROBOTC Debugger

• The ROBOTC Debugger allows you to view and manipulate all of the values of your motors, sensors, timers, and variables.

• Now that we’ve configured the motors and sensors, let’s view their values using the ROBOTC Debugger.

Page 30: Introduction  to Programming

ROBOTC Debugger

• Make sure your robot is connected to your computer and turned on, and download the program.

• When the Program Debug Window appears, press the Start button and make sure the Refresh Rate is set to Continuous.

Page 31: Introduction  to Programming

ROBOTC Debugger

• Open the Sensor Debug window by going to Robot > Debug Windows > Sensors

Page 32: Introduction  to Programming

Sensor Debug Window

• The Sensor Debug window will appear, and display all of the values of the configured sensors.

0 = on, 1 = off

0 = released, 1 = pressed

Page 33: Introduction  to Programming

ROBOTC Practice Program

• Modify your program so that an LED comes on when the motor is on, and goes off when the motor is off.

• Where in the function library are the LED commands?

• What do you type into the (digitalPort)?

• Compile and Download the program.

• Test

Page 34: Introduction  to Programming

Resources• ROBOTC.net: http://www.robotc.net/

–The ROBOTC Forum: http://www.robotc.net/forums/

• VEX Cortex Video Trainer–http://www.education.rec.ri.cmu.edu/prod

ucts/teaching_robotc_cortex/index.html• The FIRE Project:

–http://www.education.rec.ri.cmu.edu/fire/competitions/best/

• Robotics Academy–http://www.education.rec.ri.cmu.edu/cont

ent/vex/index.htm

Page 35: Introduction  to Programming

References

Carnegie Mellon Robotics Academy (2011). VEX Cortex Video Trainer. Retrieved from http://www.education.rec.ri.cmu.edu/products/teaching_robotc_cortex/index.html