Download presentation
Presentation is loading. Please wait.
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 04
2
Sensing: our 5 senses Revisit the human senses. Did the VEX IQ robot sensors correspond directly to our senses? Today we are focussing on part of our ‘vision’: detecting different colours. Making robots see and make sense of visual data is called ‘machine vision’. It is a notoriously difficult field in engineering and programming. The challenges include: lots of data, quickly changing, different sizes of objects depending on where they are, different colours, different lighting,… our brain can cope and make sense of it all, but this is a difficult task for a robot.
3
Sensors Which sensor did we use last session: what did it do, how did it work? New sensor for today: the ‘color’ sensor, please note the American spelling of ‘color’ versus ‘colour’ in Modkit. This is commonplace in most programming languages. The ‘color’ sensor is one step into the world of machine vision.
4
The Colo(u)r sensor Touch LED block:
Let’s examine the ‘color’ sensor. The name of the sensor already explains what it does. Note 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). Have a look at the ‘color’ sensor and related blocks in Modkit. ‘Color’-block: will tell us the colour name. Note how this shape is the same shape as the colour choice in the Touch LED ‘Set Color to’ block. ‘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 %’. Touch LED block:
5
Programming task: Chameleon
Challenge You need to program the robot to…. Use the ‘Color’ Sensor and the Touch LED only After you start the program, the Touch LED should become the same colour as the object you put underneath the ‘Color’ Sensor. When you put a different coloured object underneath, the Touch LED should show us the new colour. Before the students start the program, ask them to formulate the ‘algorithm’ in their own words. This should be something like: Forever check the colour underneath the sensor and make the Touch LED the same colour. (Note importance on ‘forever’)
6
Programming task: Chameleon
The students will start Modkit and assemble their car in the robot view (make sure the ports are set correctly). For this lesson we will only use the Drivetrain, ‘Color’ Sensor and Touch LED. The Chameleon program will use the 12 colour mode of the sensor.
7
Programming task: Chameleon
Start programing as usual from within the ‘Brain’ section. Explain to the students how the ‘work’ needs to be done by the Touch LED, so that’s where our algorithm will be. Avoid showing the whole program (next slide), ask students to try and complete. Guide students if needed.
8
Programming task: Chameleon
Here is the rest of the code. Ask the students to test the program with strips of brightly coloured paper (or objects). Is it always accurate?
9
Experiment: Black and White Values
In our next 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.mkv’ and download to a robot. (no need to explain or show this program). Hold differently coloured objects underneath the ‘color’ sensor and check what number it shows on the robot’s LCD screen. Try to use different whites and blacks under different lighting circumstances. As perfect black is 0, numbers close to 0 will still be black. Try to find a maximum value for which you think it is still a black object. (The value in the example program that follows is 15 but yours can be different)
10
Programming task: Drive on Black
Challenge You need to program the robot to…. At the start of our program the Touch LED to set to become white, the robot will wait for 1 second before doing anything else. After this, the robot should drive forward when it sees black underneath the ‘color’ sensor (or close to black) and stop when it no longer sees black. We will need to tell the robot what ‘black’ means using the data from our experiment. The robot TOUCH LED light should be green while driving forward and red when stopping.
11
Programming task: Drive on Black
Make sure the ‘color’ sensor is in greyscale mode.
12
Programming task: Drive on Black
We will use a variable called ‘black’ to inform the robot of our experimental data. Guide the students through 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’ 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.
13
Programming task: Drive on Black
In the Brain section we will define our variable ‘Black’. After the program is finished and has been tested, students should be invited to change this value and observe the changes in behaviour over different coloured pieces of paper. The rest of our program uses commands and constructions the students have been introduced to before. Students should try to complete the program on their own (possibly with some guidance). The next slide reveals the rest of the program (mainly in TOUCH LED and a tiny bit in the DRIVETRAIN).
14
Programming task: Drive on Black
After finishing the program, allow some time for students to try the program with different coloured pieces of paper. Let the students change the value of the black variable and observe the differences in behaviour.
15
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.