automation with robotc

27
AUTOMATION WITH ROBOTC Starting to write and troubleshoot computer code

Upload: hayley-ryan

Post on 30-Dec-2015

59 views

Category:

Documents


0 download

DESCRIPTION

Automation with RobotC. Starting to write and troubleshoot computer code. Open a New File. Review of Robot C. When you open a new file in Robot C, you must go to the “MOTORS and SENSORS SETUP” page before you write your code. Review of Robot C. - PowerPoint PPT Presentation

TRANSCRIPT

Automation with RobotC

Automation with RobotCStarting to write and troubleshoot computer code

Open a New File

Review of Robot CWhen you open a new file in Robot C, you must go to the MOTORS and SENSORS SETUP page before you write your code

Review of Robot COnce your new file is open, remember that your program code always needs to be written between the two curly brackets on the screenNatural Language commandsWe will only use 4 of the Natural Language commands when we program, but each of these commands has a number of choices

MovementCommands that allow you to control individual motorsGTT kits do not include Servo motors so make sure students do not use that option.6

SpecialCommands that control the more unique VEX Hardware LEDs and FlashlightsFlashlights not in GTT kits.7

UntilCommands that allow you to create behaviors where the robot acts until a certain event. For example,Button PressPotentiometer Value8

WaitCommands that wait for an elapsed amount of time. The next command will run after the timer is done.9

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.Dont forget every open parenthesis needs a closing parenthesis.What is wrong with line 31?Encourage students to read the error descriptions for suggestions on how to fix their program.

Once errors are fixed. Compile, download and run the program again.

Line 31 closing parenthesis is in wrong place goes after the -63)Presentation NameCourse NameUnit # Lesson #.# Lesson Name10

Whats Wrong with this code?Missing the semicolon.

Why wont the motor stop?Should say leftMotor, not rightMotor.

Why wont the LED turn on?There is nothing between the Turn on and Turn Off commands, so the LED doesnt stay on at all.

Digital SwitchesDigital Switches are either ON or OFF. The command that will always work for these switches is untilBump

LIMIT SWITCHBUMP SWITCHYour warm up ProgramWrite a program so that a motor turns on when the limit switch is pressed.After 2 seconds have that motor turn off and the other motor turn on in the opposite directionPress the bump switch to turn off the second motor.

Have students try to solve this without showing the sample solution first.Presentation NameCourse NameUnit # Lesson #.# Lesson Name15Practice Program Answer

Analog SwitchesThe Potentiometer and Line Tracker work on a scale of 0 4095

POTENTIOMETERLINE TRACKER

PotentiometerThe Potentiometer works on a scale of 0 4095

It is very sensitive, and it is NOT meant to turn all the way around, so please dont force it!

PotentiometerPosition = a number between 0 and 4095sensorPort = in2 or potentiometer

Analog SwitchesWrite a code for the potentiometer that turns on a motor for 3 seconds when you turn it past 3500

POTENTIOMETERtask main(){untilPotentiometerGreaterThan(3500, in2);

startMotor(rightMotor, 127);waitInMilliseconds(3000);stopMotor(rightMotor);}Potentiometer Program AnswerROBOTC DebuggerWhen I write a code with a potentiometer, I need to see what the sensor is reading right now. We do this by looking at a Debugger window.

ROBOTC DebuggerAfter you click on Compile Program, open the Sensor Debug window by going to Robot > Debug Windows > Sensors

Line trackerPosition = a number between 0 and 4095sensorPort = in1 or lineTracker

Line trackerThe line tracker senses light and dark.Right a program that turns on a motor, and has it stop when you cover the line tracker with your finger.

task main(){startMotor(rightMotor, 127);

untillight(100, in1);

stopMotor(rightMotor);}Line tracker Program AnswerOpen SystemAn open system will let you unplug your cortex from the computer and run your program repeated times.