vex 1.0 © 2005 carnegie mellon robotics academy inc. programming in easyc

29
Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Post on 20-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Programming in easyC

Page 2: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

What is Programming?

• Making something do what you want it to do– Circuits and switches– Code

• Demands/commands• Robot obeys commands

Page 3: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

What is the programmer’s role?

• Define parameters for robot behaviors

• Be specific– On/off– Port numbers

Page 4: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

What is Programming?

• Programming is the process of creating a sequence of instructions that tells a computational device how to perform a task.

• True programmers:– Analyze the task at hand– Break the task down into simpler and simpler

behaviors until they reach the level where the robot can understand them

– Arrange and organize instructions to implement the behaviors as needed

Page 5: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

What is easyC?

• Software that allows you to write programs in the ‘C’ style...– Instructions will be executed top to bottom– Uses C-style operators and comparators (<,>,=,==,

etc.)– Comments are ignored

• Hybrid icon-based language– Main program flow is iconic– Some operations require C operators

Page 6: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Hardware Setup

• This setup will allow you to download code you write in easyC from your computer to your robot.

• Plug your motors into any two motor ports you wish.

Page 7: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Test Program

• Goals– Learn the basics of easyC– Learn how to write your

own programs

• Begin by opening easyC on your Desktop

Page 8: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Icons You Should Know

• New Project

• Open Project

• Save Project

• Build and Download: compiles and downloads your easyC code to your robot

• For your challenges, you will be using the L2 code level (this determines which blocks will be available to you).

Page 9: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

• Open the file TESTPROGRAM.ECP from the folder “Test Code”

Page 10: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

• Your screen should look like the screen below• To get this code onto the robot, we will need to compile and

download this code.

Page 11: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

• For the test program to work properly, you must make sure the terminal window appears after downloading code to the robot.

1. Click “Loader Setup” under the “Build & Download” menu.

2. Click the radio button next to “Terminal Window.” This will make the terminal window appear immediately after downloading code to your robot.

Page 12: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

The Compiler

• The compiler is a computer program that translates a completed set of easyC instructions into machine language so the Micro Controller can understand them.

easyC codeMachine code

(.HEX file)

Compiler

Page 13: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Compiling your Code

1. Click on the compile icon.

2. You should get the following screen:

Compiling your code creates a .HEX file which has transformed your easyC program into machine language, or something the computer can understand.

Page 14: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.This is the output window. If you click on the error, it will highlight the line number.

Page 15: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Downloading your Code

• Downloading is the process of sending the compiled machine-language program from your PC to the microcontroller

easyC codeMachine code

(.HEX file)

CompilerCode on robot

Downloader

Page 16: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Downloading your Code

1. Make sure your robot is on and plugged into your computer.

2. To download your code, click on the “Build and Download” icon.

3. The computer will re-compile the code and begin downloading the .HEX file to your robot.

Page 17: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

How the Test Program Works

• The test program will run the motors by running them forward and then backward

• Make sure you pick up your robot so that it does not fall off the table when the program starts

Page 18: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Restoring Default Code• If you would like to restore the “out-of-box” configuration on your robot,

follow these steps.1. Make sure your robot is switched on and plugged into the computer.2. Click the “Download default code” under “Build and Download” menu.3. The code will immediately download to your robot.

Page 19: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 1: Motor On• Now that you have gotten a feel for easyC, the following slides show you five programs to teach

you about motors and timing.• You will need to master all of these programs to accomplish your next challenge.• On your desktop in the folder “Programs,” you will find guides to all the programs.

• Program 1 will teach you how to turn on a motor.• Video: Motors – Motors On

Page 20: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 1: Motor On

• What you learned:– (Add to page during discussion)

Page 21: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 2: Motor Forward

• Program 2 will teach you how to turn both of your robot’s motors on for three seconds.

• Video: Motors – Forward for 3 Seconds

Page 22: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 2: Motor Forward

• What you learned:– (Add to page during discussion)

Page 23: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 3: Turning

• In program 3, you will learn how to turn for three seconds

• Video: Motors – Turn for 3 Seconds

Page 24: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 3: Turning

• What you learned:– (Add to page during discussion)

Page 25: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 4: Forward/Backward

• In program 4, you will learn how to make your robot move forward, then backwards

• Video: Forward for 3 Seconds, Backward for 3 Seconds

Page 26: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 4: Forward/Backward

• What you learned:– (Add to page during discussion)

Page 27: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 5: Half Speed

• In program 5, you will learn how to power your motors on half speed for three seconds.

• Video: Motors – Forward Half Speed

Page 28: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Program 5: Half Speed

• What you learned:– (Add to page during discussion)

Page 29: Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC

Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc.

Programming Guide

• You now have the basics to programming your robot to complete your new challenge.