Presentation is loading. Please wait.

Presentation is loading. Please wait.

2008 SBPLI/FIRST Programming Workshop Tom Boehm Patchogue Medford High School, Team 329 Motorola Inc. Mark McLeod Hauppauge High School Team 358 Northrop.

Similar presentations


Presentation on theme: "2008 SBPLI/FIRST Programming Workshop Tom Boehm Patchogue Medford High School, Team 329 Motorola Inc. Mark McLeod Hauppauge High School Team 358 Northrop."— Presentation transcript:

1 2008 SBPLI/FIRST Programming Workshop Tom Boehm Patchogue Medford High School, Team 329 Motorola Inc. Mark McLeod Hauppauge High School Team 358 Northrop Grumman Corp.

2 Goals Well, duh, we want to actually make these robots DO something. Well, duh, we want to actually make these robots DO something. Learn about some basic programming language elements. Learn about some basic programming language elements. Learn about the structure of a ‘C’ program. Learn about the structure of a ‘C’ program. Learn about programming the robot controller. Learn about programming the robot controller. Learn about how this will all be different from what we actually see in January. Learn about how this will all be different from what we actually see in January. Find out how to get more information. Find out how to get more information.

3 But First, a Little Vocabulary Lesson. You gotta talk the talk… See the handout. There are lots of them to become familiar with, and lots more that I haven’t put down. Memorize all of them, there will be a test on them next week… See the handout. There are lots of them to become familiar with, and lots more that I haven’t put down. Memorize all of them, there will be a test on them next week…

4 Simple Programming Structure A single line of code that does SOMETHING, is usually called a statement. A single line of code that does SOMETHING, is usually called a statement. A group a statements collected together to perform a specific set of actions is typically called a function. A group a statements collected together to perform a specific set of actions is typically called a function. A group of functions that are collected together are called a program. A group of functions that are collected together are called a program.

5 Statements Try to make them very simple: int i, j, k; j = -50; i = 15 + j; k = 22; Try to make them very simple: int i, j, k; j = -50; i = 15 + j; k = 22; But they can get very complex: k = (i * 23) + (j * k * -98.34) / (j >5) ? 23 : 12; /* This is a comment. It does not execute. k = 10509. */ But they can get very complex: k = (i * 23) + (j * k * -98.34) / (j >5) ? 23 : 12; /* This is a comment. It does not execute. k = 10509. */

6 OK, so now what? That’s all well and good, but how do we make decisions? That’s all well and good, but how do we make decisions? We use conditional expressions. if (j > 5) then do something else do some other thing. if (j > 5) k = j + 1; else k = 0; We use conditional expressions. if (j > 5) then do something else do some other thing. if (j > 5) k = j + 1; else k = 0; There are many comparison operations, >, =,, =, <=, ==, !=, etc.

7 What if we need to do something more than once? Loops! They usually have the form: Initialize some loop condition. While (this condition is true) Do this set of stuff. Modify the loop condition. Loops! They usually have the form: Initialize some loop condition. While (this condition is true) Do this set of stuff. Modify the loop condition. For example: j = 0; while ( j < 5 ) { k = k + j; j = j + 1; } For example: j = 0; while ( j < 5 ) { k = k + j; j = j + 1; }

8 Loops are Cool Loops are used to count, repeat actions, or wait for something to occur.Counting loops are so commonplace, in ‘C’ they are given their own keyword: ‘for’: for ( j = 0; j < 5 ; j = j + 1;) k = k + j; // This does the same thing as last page. Loops are used to count, repeat actions, or wait for something to occur.Counting loops are so commonplace, in ‘C’ they are given their own keyword: ‘for’: for ( j = 0; j < 5 ; j = j + 1;) k = k + j; // This does the same thing as last page.

9 Functions A function is a set of statements that can be executed the same way over and over again, without a loop, and without re-writing the same code over and over again. A function is a set of statements that can be executed the same way over and over again, without a loop, and without re-writing the same code over and over again. Benefits: Benefits: –Once you get it working, it will always work that way no matter where you call it. –You do not have to retype the same code over again, possibly mistyping it. –It makes the whole program easier to understand. –If you do it right, maybe you can use it again next year.

10 Peripherals A peripheral is something that is attached to the microcomputer that performs a specialized function. A peripheral is something that is attached to the microcomputer that performs a specialized function. Examples: Examples: –Digital Port Pins: Can be 0 or 1, True or False, High or Low, On or Off, etc. Can be either an input or an output. Used for monitoring and control. –Motor PWM: Used to provide variable power to a motor to control motor speed and direction. –Gear tooth sensor: Counts gear teeth as they whiz by. Can be used to determine distance. –Gyroscope: Can be used to measure a heading. –Accelerometer: Can be used to measure forces acting on the robot. –Digital cameras, Wireless network cards, USB ports, Serial ports, Pneumatic actuators, and many, many more…

11 A Simple Program… Let’s just make this robot move forward, stop, turn around and move backward again… Let’s just make this robot move forward, stop, turn around and move backward again…

12 Now we’ll control it… Let’s see how we can control it with the remote control… Let’s see how we can control it with the remote control…

13 Now let’s combine them… This simple program will have the robot be operator controlled. It will also use a bumper to detect an object (by hitting it) and automatically reverse away from it and then go back to operator control. This simple program will have the robot be operator controlled. It will also use a bumper to detect an object (by hitting it) and automatically reverse away from it and then go back to operator control.

14 Now you try it… Look at the sample program on your laptops… Look at the sample program on your laptops… –Operator control with object avoidance –Autonomous square by counter. –Autonomous square by timing. –Speed incrementing and decrementing.

15 Try This: Modify the program given to make the robot run in a circle. Modify the program given to make the robot run in a circle. Run an oval. Run an oval. Run a figure eight. Run a figure eight. User the bumper to select between the three. User the bumper to select between the three.


Download ppt "2008 SBPLI/FIRST Programming Workshop Tom Boehm Patchogue Medford High School, Team 329 Motorola Inc. Mark McLeod Hauppauge High School Team 358 Northrop."

Similar presentations


Ads by Google