Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 27
Program Planning
Behavior Based Programming
A behavior is anything your robot does: turning on a single motor, moving forward, tracking a, 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
The Labyrinth Challenge The Labyrinth Challenge 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 Pseudocode Sample Pseudocode: 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. 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, dont try to implement it all at once! Systematically add sections of code, testing at every step! Configuring Inputs and Outputs Then open the Motors and Sensors Setup Window to configure the motors and sensors connected to your Testbed Motors Digital Sensors Note: Digital Sensors can be configured as both inputs (touch sensors) and outputs (LEDs). Naming Conventions The names of your motors and sensors follow the same conventions as variable names (which you will learn more about later on): Must be all one word (leftMotor, frontLight, etc.) Cannot contain any special characters (%, ^, #, etc.) Cannot already be a ROBOTC Reserved Word (while, motor, task, etc.) ROBOTC Natural Language Movement Commands that allow you to control individual motors Special Commands that control the more unique VEX Hardware LEDs Until Commands that allow you to create behaviors where the robot acts until a certain event Button Press Line Tracker Value Potentiometer Value Wait Commands that wait for an elapsed amount of time in seconds or milliseconds Sample Programs PLTW Template PLTW Template Top comment section for students to fill their personal information, as well as program planning work. Section between curly braces is designated for the actual program. Beginning and end of a multi-line comment Basic Programming: Motor and Wait Commands VEX Motors Main Type: 2-wire motor 269 Newer 2-wire motor 393 Number is written on motor
All motors are programmed the same way in ROBOTC Accept values between 127 (full forward) and -127 (full reverse)
Motor 2 for 5 Seconds Defines the main task of the robot All commands belonging to task main must be in-between these curly braces Connecting the Motors Two-wire motors can be plugged directly into MOTOR ports 1 & 10 on the Cortex, and 2-9 using the Motor Controller 29 Motor 2 for 5 Seconds Turns the port2 rightMotor on at half power forward Motor 2 for 5 Seconds Causes the robot to wait here in the program for 5.0 seconds Motor 2 for 5 Seconds Stops the port2 rightMotor. End Result: rightMotor spins for 5.0 seconds.