Skip to main content
Skip to Main Content
Skip to main content
Navigation

Detecting a Color with the AI Vision Sensor

In this video, Audra helps you run your first project with the AI Vision Sensor! You will learn how to connect the AI Vision Sensor to VEXcode EXP, configure your first color signature, and then use that in a simple project to make a robot turn until the signature is detected. 

New to the AI Vision Sensor? Watch the Introducing the AI Vision Sensor video first. 
 

(bright upbeat music)

Hello and welcome back to the VEX Classroom. My name is Audra, and in this video, we are going to get up and running really quickly and easily with our AI Vision Sensor as we learn about Detecting a Color with the AI Vision Sensor. Over the course of this video, we're going to learn about how to connect the vision sensor directly to VEXcode, how to configure a color signature, and then we're gonna run a simple project in order to be able to use that color signature to make a decision with our robot. All right, let's get started.

The very first thing that we're going to need in order to do this is our USB-C cable. I have my USB-C cable already plugged into my computer, and now I'm gonna show you how to plug it into the sensor itself. If I turn my robot over, you can see my AI Vision Sensor is up here, and on the side, there are two ports. The one on the bottom is for the SMART cable to connect the sensor to the brain, and the one on the top is a USB-C port, and that's where I'm going to plug my USB-C cable. It's going to go directly into there right up at the top. You'll also notice that my EXP brain right now is turned off, and we wanna make sure that the brain is off for the whole configuration process.

Here I am in VEXcode EXP, and now I'm going to configure the AI Vision Sensor. The first few steps of this are just like how we would add any other device that we're going to use with our robot. We're gonna start by opening up the devices screen here and selecting Add a device. Then we'll choose from the list, the AI Vision Sensor, because that is the sensor we're working with. Next, just as we always do, we'll select the port that it's plugged into on the brain. In this case, my AI Vision Sensor is plugged into Port 1, so I'll select 1. Now we can see that there are a few more options for configuration.

In order to set these further options, we need to open the AI Vision utility. We're gonna select this Configure button in order to open that utility. Within the AI Vision Utility, I can see how my AI Vision Sensor is connected. On the left-hand side, the most obvious way to see that it's connected is that within this big snapshot window, I can see the entire frame and entire range of view of the AI Vision Sensor. I can see that I have my blue Buckyball on the table that I'm gonna use to set the color. In addition, above that, I have this little Connected dialog. One other thing I wanted to mention on this left-hand side is that at the bottom, we can see that the firmware is up-to-date, which is always something good to check whenever you're using a new device.

Now, in order to configure our first color, I need to set the color that I want the AI Vision Sensor to detect. In this case, I'm going to use the blue Buckyball here to do that. I'm gonna take this cursor and drag a box over the inside of that blue Buckyball, just like that. When I let go and I've selected that box, we can see over here on the right side, we now have this option to set the color. When I select Set Color, now that this is enabled, we can see that my color is showing up right over here, and now I can also name that color. Since I know that it's blue, I'm going to name it Blue. We can see now in our snapshot window that we have some data about this color appearing.

Over the course of these videos, you'll learn more about the data that is shown. Something that you'll notice is that as I move this blue ball around within the range of view of the sensor, you can see that it continues to identify this object as blue. If I added another blue object, like a blue ring, it would also pick that up as blue, right? Because we're not identifying the object, we're identifying this particular color.

So now we can see how the sensor picks up objects within that snapshot, within that range of view. In order to set this configuration, I'm gonna select Close here. Now we can see that I have blue as a configured color, and when I select Done, now that's saved, and I can use that configuration within my project.

Now that we're done with the configuration process, we can unplug the USB-C cable from the sensor. So now our robot is ready to use. I've already downloaded a simple project to my robot's brain in order to make it turn until the color blue is detected. Let's run that project to see it in action.

[Music Cue]

Now when I start it, we'll see the robot turn, and as soon as it detects that blue Buckyball, it stops moving. Let's take a look together at that project so we can read the code and figure out how we're using the AI Vision Sensor data to make a decision.

In this project, the very first thing you might have noticed is that the robot was moving pretty slowly, right? I've slowed down the turn velocity, and this helps to make sure that the sensor is getting the most accurate data possible. Inside this forever loop, we have the blocks that will make the robot turn until it detects blue. The first one you'll see here is taking a snapshot of blue.

In order to capture the data from the AI Vision Sensor, we need to essentially freeze that and take a snapshot of the data from the sensor. When we take a snapshot, we're essentially freezing that snapshot window that we saw in the utility to capture that data of that moment in time to be able to see if there is our configured color in that frame. The robot's then going to turn right, and if an object exists, what object? That color blue that we detected, right? We're trying to take a snapshot of blue.

If anywhere within that snapshot, blue is found, then this condition reports as true, and the robot will stop driving. If there's not blue found, the project will continue, and because it's in a forever loop, it will continue to turn right until such time as it sees blue. The other important thing to note here is that the Take Snapshot block is also located within the Forever loop. That means each time we iterate through that loop, we're taking another snapshot to capture what is in front of the sensor, and then using that new snapshot to determine if there's an object there, and whether or not we're going to turn right or stop driving.

Each time this project cycles through, we're taking a snapshot, then making a decision based on what is present in that snapshot. Let's take a look at this project and introduce a couple of other colors to test out its capabilities a bit more.

So now, what if there were, say, a red Buckyball also on the field? On my table here now, I'm adding a red Buckyball, and when I start this project again, we'll see that the robot should turn past the red Buckyball and it will stop when it detects blue. When it detected red, that condition reported as false, so the robot would continue going.

Now, because we have that in a forever loop, if I were to move the blue Buckyball and it were no longer being detected, the robot would continue to turn. If I pick up the blue Buckyball and move it over here, now we can see that the robot continues to turn until such time as it detects the blue Buckyball again. This would also be true if we introduced a different blue object, right? I have a blue ring, so if a blue ring were to come into the frame, since that is the same color blue, right, if I remove this blue Buckyball and had the blue ring, and we can see as I move the blue ring, the robot continues to follow it and detect that blue.

[Music Cue]

Thank you for following along with this demonstration. I hope you found it informative and helpful. If you have any questions or need further assistance, please feel free to reach out.

[Final Message]

Thank you for your time and attention. We look forward to seeing what you create with your AI Vision Sensor!

So there you can see it's really very quick and easy to get up and running with the AI Vision Sensor, and to start to use that data in a project to make a decision.

I hope this has given you some ideas for how you want to get started using the AI Vision Sensor in your setting, and I look so forward to seeing you back here in another video sometime soon.

(bright upbeat music)

Share

Like this video? Share it with others!

Additional Resources

Looking for more? Learn about Adjusting a Color Signature with this video.

Additional Resources

 

Want to learn about coding with the AI Vision Sensor in Python? Schedule a 1-on-1 or post in the VEX Professional Learning Community.