Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to VEX IQ Programming with Modkit

Similar presentations


Presentation on theme: "An Introduction to VEX IQ Programming with Modkit"— Presentation transcript:

1 An Introduction to VEX IQ Programming with Modkit
Robotics Lesson Materials: VEX IQ sensor car (per 2 students) Computer running Modkit (per 2 students) An Introduction to VEX IQ Programming with Modkit Lesson 05

2 Sensors What sensors have we used so far? What did they do, how did they work? Today we are working with the ‘color’ sensor again. Please remind students of the American spelling of ‘color’ versus ‘colour’ in Modkit. This is commonplace in most programming languages.

3 The Colo(u)r sensor Remember the settings of the ‘color’ sensor: before programming, we need to choose how we will use the sensor: 3 colours, 12 colours or greyscale (like old black and white TVs and old movies). Note: the sensor is calibrated for fluorescent lighting (typical classroom lighting). How easy was it for the ‘color’ sensor to see the right colour? (Thinking of Lesson 04) Which mode of the sensor do you think would be best to follow a (black) line? (Greyscale) Revisit the ‘color’ sensor and related blocks in Modkit. ‘Color’-block: will tell us the colour name. ‘Color’-Hue: will give us a numerical value for what it sees. Example: all shades of blue under fluorescent lighting will give a value between 200 and 300. Values can be found at the end of the VEX IQ manual. In greyscale mode, this block is changed to ‘Greyscale %’ (values between 0 and 100).

4 Experiment: Black and White Values
Full program provided as experiment-0.mk4v (same as lesson 04) As discussed, in our program we will use the ‘color’ sensor to see greyscales (black and white). Depending on the object that’s underneath we will get a number between 0 and 100. As not every black object is fully black and not every white object is perfectly white, we will run a little program on the robot to check which number our sensor sees. Experiment: run the program ‘experiment-0’ downloaded to a robot. (no need to explain or show this program to the students). Move the robot car over the track and check the values it shows on the robot’s lcd screen. Make sure to see what happens when the ‘color’ sensor is on the white paper and how the values changes as you gently move it across the black track. Our line tracking program will follow the right edge of a black line on a white piece of paper, so make sure to note the values for the following situations: The sensor sees mainly black (in the example program this will be 10) The sensor sees mainly white (in the example program this will be 30) The sensor is located on the edge of the track (in the example program this will be between 10 and 30)

5 Programming task: Line tracking
Challenge You need to program the robot to…. Set up the robot car with the right sensors/ports. Use variables to set values for black and white. Write a program that will drive the car forward and follow the right hand edge of a black line on a white surface. This program is similar to the ‘Drive on Black’ program from lesson 4 (minus the Touch LED functions and with a more complex IF-statement). Guide the students through creating this program using conditional statements for black and white. Avoid too much hand holding, apart from a slightly more complex if-statement, they should be able to do this on their own. The next slides will reveal the programming steps.

6 Programming task: Line tracking
Make sure the ‘color’ sensor is in greyscale mode.

7 Programming task: Line tracking
We will use variables called ‘black’ and ‘white’ to inform the robot of our experimental data. Remind the students of this process. They can create a variable by clicking on the ‘New Variable’ block at the very bottom of interface. A variable name can be anything, but choose it sensibly (Black or White in our example). After entering it, 2 new blocks with that name will appear. One block just has the name, the other also has a field to put in some data.

8 Programming task: Line tracking
The values of the ‘Black’ and ‘White’ variables are listed here as 10 and 30 respectively. The values will depend on the lighting in the classroom. Please refer back to the values of the experiment at the start of the lesson. We will define the values in the ‘Brain’ section of Modkit, but this can be done in any section.

9 Programming task: Line tracking
The bulk of our program takes place in the drivetrain section. Remember the drivetrain setup blocks from lesson 1 (see blocks sheet lesson 1)? Since we need to give our robot enough time to make sure the ‘color’ sensor gets to output a value before we drive over the black line, we will limit the drive and turn speeds. The next slide reveals the full drivetrain program. Before showing and discussing the slide, discuss the 3 different actions we might need to take and when to take these (in plain English first, then translate to pseudo code). We are trying to follow the right hand edge of a black track on white paper. 1. Situation: our robot is too far to the right of the track. Sensor: it will mainly see white. Action to be taking: turn left. 2. Situation: our robot is too far to the left of the track. Sensor: it will mainly see black (too much black). Action to be taking: turn right. 3. Situation: our robot is on the right edge of the track. Sensor: it will mainly see just enough black (in between 1 and 2). Action to be taking: go forward. This is the tricky one as there are 2 conditions that need be fulfilled (not too much black, not too much white). Use the ‘and’ operator to combine them. Ensure enough time is taken so the students understand the logic of the decisions and not just the code. Try to get the students to write the code, if needed refer back to the blocks sheets for control (if-statements), operators (bigger than, smaller than,…) and drivetrain (Forward, turn,..)

10 Programming task: Line tracking
Test the program and adjust values for black and white if needed and possibly also the speed settings of the drivetrain. Note how the accuracy will change. Please note: make sure you start the robot on the right hand edge of the line! Full program provided as LineTracking-0.mk4v

11 Summary Today you have:
Learning objective: Learn how robots gather data from their environment. Learn to program a VEX IQ robot with drivetrain and ‘color’ sensor. Learn about the use of variables, conditional statements and repeat structures . Today you have: Learned how robots can gather data from different sensors. Learned to add the ‘color’ sensor to our robot. Programmed a robot to work autonomously. Learned how to use variables. Programmed a fully automatic car. End the lesson by a brief discussion on how our robot ‘sees’ and how accurate this is/isn’t.


Download ppt "An Introduction to VEX IQ Programming with Modkit"

Similar presentations


Ads by Google