Presentation is loading. Please wait.

Presentation is loading. Please wait.

Xtreme Robot Olympiad Programming Basics Dr. Peter Laz Associate Professor Department of Engineering University of Denver.

Similar presentations


Presentation on theme: "Xtreme Robot Olympiad Programming Basics Dr. Peter Laz Associate Professor Department of Engineering University of Denver."— Presentation transcript:

1 Xtreme Robot Olympiad Programming Basics Dr. Peter Laz Associate Professor Department of Engineering University of Denver

2 Outline Basic commands Variables Loops Conditional statements Motor and servo operation PWM signals Programming with EasyC How to program the microcontroller?

3 Variables Different types of variables int = integer (whole number) float = decimal char = character

4 Common Commands Operations Sets variables equal to specific values Standard operators: + - * / Loops – cause actions to be repeated for while Conditional statements – actions executed depend on results of comparisons if … then if … then … else Comparators: >, =, <=, ==

5 Program Tracking VariableValue Printed to the screen Other Actions

6 Basic Commands Example: if else int x If (x>10) { x=x+5 } else { x=x-1 } What value does x have if x = 5? x = 18? x = 10?

7 Basic Commands Example: for loop int i for (i=0;i<7;i=i+1) { print(“tiger\n”) } How many times is tiger printed to the screen?

8 Basic Commands Example: for loop int i for (i=0;i<7;i=i+2) { print(“tiger\n”) } How many times is tiger printed to the screen?

9 Basic Commands Example: while loop int i int flag i=0; flag = 0 while (flag != 1) { i=i+1 print(i) If (i>=9) { flag = 1 } What is printed to the screen?

10 Exercise Using basic commands, develop a flow chart/program to print the first 10 numbers of the Fibonacci sequence 1,1,2,3,5,8,13,21,34,55

11 Motor and Servo Components Motors – operate continuously Servos – have a range of 120 degrees Both use pulse width modulated signals PWM values range from 0 to 255 Corresponds to the duty cycle or amount of time the pulse is on 0 = full counterclockwise 127 = stop 255 = full clockwise

12 PWM Signals Repeating pulse signal Pulse width determines the amount of voltage to the motor 127 or 50% duty cycle corresponds to 1.5ms http://en.wikipedia.org

13 Motor Control Note: to make the robot go forward Left motor CW Right motor CCW

14 Basic Commands Define variables Type of and initial value of variable Assignment Assign a value to a variable Wait(time in ms) wait(500) 1000 ms = 1 sec This applies a delay to allow the vehicle to move forward or turn Sensors Read in data into a variable Commands vary depending on the sensor

15 Programming Lab with EasyC

16 Programming 1.Determine the appropriate com port Right click on my computer, properties, hardware, device manager Look at which com port has “Prolific USB to Serial Comm port” 2.Open easyC 3.Under Build&Download, choose loader setup Pick the correct com port

17 Programming 4.With the vehicle off, plug the programming module into the microcontroller. 5.Turn the vehicle on, be aware the robot will begin to run the previously loaded program 6.Hit the orange button on the programming cable to connect the vehicle and the computer 7.Initiate programming through the build and download menu

18 EasyC

19 Exercises Download Testprogram.ecp Download Online Window

20 Exercises Write a program to drive in a 5 foot square Challenge: use a for loop in your code 1. Draw the flowchart 2. Write the program 3. Test the wait() values

21 This workforce solution was funded by a grant awarded under the Workforce Innovation in Regional Development (WIRED) as implemented by the U.S. Department of Labor’s Employment and Training Administration working in partnership with the Colorado Department of Labor and Employment, the Metro Denver Economic Development Corporation, and the City and County of Denver's Office of Economic Development. The solution was created by the grantee and does not necessarily reflect the official position of the U.S. Department of Labor. The Department of Labor makes no guarantees, warranties, or assurances of any kind, express or implied, with respect to such information, including any information on linked sites and including, but not limited to, accuracy of the information or its completeness, timeliness, usefulness, adequacy, continued availability, or ownership. This solution is copyrighted by the institution that created it. Internal use by an organization and/or personal use by an individual for non-commercial purposes is permissible. All other uses require the prior authorization of the copyright owner.


Download ppt "Xtreme Robot Olympiad Programming Basics Dr. Peter Laz Associate Professor Department of Engineering University of Denver."

Similar presentations


Ads by Google