Datalogging with VEX IQ
Learn all about Data Logging in the VEX IQ Universe in this Live Session. This session delves into the art and science of data logging using the VEX IQ platform. Whether you're a beginner or have prior experience, this video will equip you with the tools and techniques to incorporate data logging and data science into your teaching. Don't miss this chance to elevate your educational toolkit. Watch today and step into a future where data and education merge seamlessly.
(lively music)
Hi, welcome to our Live Session, where today, it's my pleasure to talk to you about data logging with VEX IQ. I'm Jason McKenna, VP of Global Educational Strategy here at VEX Robotics, and I can't wait to talk to you about data logging, because honestly, this was one of the things I did in my classroom that I enjoyed the most. I used to love doing data logging. This was back before data science was actually a thing, so I might have been a little bit ahead of my time in my classroom when I was doing it. This is something I really loved doing with my students because it was an opportunity for them to collect data, take a look at the data, and then use that data to make informed decisions about what they were actually trying to code with their robot.
At the very beginning, when students are just getting started with coding, kind of guessing and checking their way through a solution is a great technique to utilize. It shows that students are resilient, engaged, and iterative with their approach to coding and computer science. However, as you progress, you want your students to take a more sophisticated approach to what they're doing with computer science and their robot, and data logging is a great example of this.
This is a great time to be doing this live session, as it is Computer Science Education Week. If you are in the middle of Computer Science Education Week right now, please don't forget that you can go to hoc.vex.com, where we have a lot of different activities to engage your students. We have activities with physical robots, like VEX IQ, and activities with our virtual robot. There's a teacher's guide for each of those activities, as well as a student activity page. We have very cool features, like leaderboards, where you can check out how your students rank against others in the world with different VR playgrounds. All of the VR playgrounds are free during this month of December, so even if you have the free account for VEXcode VR, you can play the virtual skills game or Maze Solver Plus. Some of our more exotic playgrounds are available for you to check out for the month of December, in honor of Computer Science Education Week.
I hope you're having a wonderful Computer Science Education Week. If you're looking for an activity to do later this week, or later this month, what I'm about to show you with data logging is a really fun thing to utilize with your students in the classroom. This would obviously not be a beginning activity. I want to show you a Python program here in a moment, which will not be something you want to do with beginning students. However, as your students progress throughout VEXcode and with VEX IQ, if you're a competition team, for example, or if your students have been coding with VEXcode IQ for a while, this is a wonderful activity to incorporate data science and higher levels of computational thinking in your classroom.
When we talk about data logging with VEX IQ, what do we mean? What are we actually talking about? Well, the word kinda says it itself. We are logging data, collecting data, and then we want to be able to use that data to make informed decisions about what our robot is doing on the competition field or in our classroom, and then we can adjust our code accordingly.
Now, to contextualize this for you, to truly make it hit home, I'm going to be using the optical sensor on the VEX IQ robot to really, again, contextualize this for you. Anytime you code with sensors, one of the biggest questions we always get in our support, from customers and teachers like you, is, "My sensor is not working as I expect it to work. I think the logic in the code is right, the logic in my program is correct, but the robot, the sensor is not performing as I expect. So when it sees blue, for example, it's supposed to turn right, or it's supposed to stop," or whatever those particular things are, "but the robot is not doing that. Why? Why is that?"
Now, oftentimes, when we get that question, the reason why you're asking us that question is because that decision-making that the robot is doing is in a black box. What I mean by that is our assumption from our code is that when the robot sees blue, or specifically, when the optical sensor sees blue, the robot is supposed to do something, it's supposed to stop, it's supposed to turn, whatever, but it's not doing that. But we don't actually know what the sensor is seeing. We don't know the input that our code is actually receiving from the sensor. That's what I mean by a black box, it's a mystery to us. As a result of that, we don't know what to do. We can try different parameters, we can try different commands, and that oftentimes leads to frustration, because again, we feel like our logic is correct from a coding perspective, but the robot is not performing as it should perform. Is my sensor wrong, or is there something wrong with my robot? Then I'll update VEXcode. So you kinda go through all these different things to try to figure out what the problem is, again, because it's a black box.
Now, what data logging does, it allows you, like in the Wizard of Oz, to peek behind the curtain, right? (chuckles) It allows you to take the cover off so you can actually see what's inside of that box, so you can actually see what's going on there, and that's what I'm gonna illustrate for you here today, in this live session. You can use the data, that's what we mean by removing the black box, giving you the opportunity to see, or shining a light on the black box, whatever metaphor you wanna use, but you can actually use the data to understand what the sensor is seeing and understand what the sensor is doing, so now you can make informed decisions about what you want your robot to do when it reaches a certain point in the competition field, (coughs) excuse me, or if you're solving a classroom challenge.
Now, just a reminder, if you're watching this, you're a PD+ subscriber and you're watching this, and if you have to step away or if you have to leave early, do not worry, you can always watch the recording later. Our team here will have this up on the site in no time at all, so don't forget that. Also, if you have any questions about anything that you see during the course of this live session, please, you can ask that question in the community. Either myself or a member of our software team will be more than happy to answer that particular question for you. All the code you're gonna see during the course of this lab session, I will share in the community. That way, you have an opportunity to use it and utilize it on your own. And again, if you're looking for a fun activity to do this week, for Computer Science Education Week, and your students are a bit more advanced coders, this would be a great one for you to be able to do.
So to start talking about this, to start talking about data logging and data science VEX IQ, let's first talk about the optical sensor, okay, right here on my VEX IQ robot, and what it's actually doing.
Now, the first thing you have to understand with the optical sensor is that your optical sensor actually does not see a color. It does not see blue, it does not see green, it does not see red, okay? We see things around in our environment with our eyes, and we associate colors with that, obviously. That's how we communicate, are those colors. Well, our robots and our sensors are not quite that sophisticated.
How the optical sensor actually works... First of all, when I run this project, you're gonna see an LED light turn on that's gonna illuminate the surroundings or what's directly in front of the optical sensor. Then what it does, the sensor actually does, it emits a light, okay? So a light comes out of the optical sensor, and then it's gonna bounce off of these objects that I have in front of it, these cubes that I have right here, or if you are going to a wall, or whatever, it's going to bounce, it's gonna send the wavelength to that object, and then because it's gonna, because that object is there, the wavelength is gonna bounce back to the actual sensor.
Using math, then, what the sensor then actually does is it derives a hue value. So what the optical sensor is actually determining is not a color, not, you know, blue, green, red. Instead, it's determining a hue value. So let's go to the computer, and I can actually show you the hue value of the robot. So there's our hue value for VEX right there. You can see right up here at red, about zero is red, then we get into our greens over here, and our blues around the value of 240. So this is what your robot is, this is what your sensor is actually deriving, based upon what is going on in the wavelength that's returned to it.
Now, where this gets a little bit tricky is that ambient light that you have in your classroom is going to affect that wavelength, that wavelength that's being bounced back to your robot, to your sensor. If you have a lot of light in your room, you're gonna get certain values. If your room is darker, you're gonna get less values. This used to happen to me when I taught all the time, okay? Because of where my room was, in the morning, we got a lot of sunlight, okay, in the windows in the room. So we got a lot of sunlight in the morning, so therefore, the ambient light in the room was a lot different when I was teaching 2 or 3 o'clock in the afternoon, because now, the sun was no longer there, right, so now the amount of ambient light I had in the room was completely and totally different, so as a result of that, if I had code that I was using in period one, I'd have my code up on the board, I'd have certain values in there, I would talk about this with the students, they would run the project during period one, and (claps loudly) everything worked fantastic, everything worked great.
Then I'd go do that same exact project in period seven, the ambient light is different, and my code would not run the same. The sensor would no longer see blue, and (chuckling) that would obviously cause me to be very frustrated, because this exact same project worked this morning, why is it no longer working now? Now, you could carry that example further. Your robot works on your competition field at your school, but when you go to a different school, on their competition field, the robot, the sensors are no longer working the exact same way, again, because the ambient light, the environment is much different, okay, so as a result of that, if we can use data science and data logging to basically cut down on that.
So to review, what your optical sensor is actually doing, it does not read a color, it does not see the blue cube and say blue, it does not see the green cube and see green. Instead, what it does, it emits a light, okay, the LED light. When it emits that light, it's setting off a wavelength, okay, light travels in waves, so it's gonna send out a wavelength.
Thank you for your attention and interest in understanding how optical sensors work. I hope this explanation has been helpful and informative. If you have any questions, feel free to ask.
When it detects an object, when that wavelength hits an object, it's then going to return back to the sensor. The qualities of that wavelength are then mathematically processed by your sensor, which takes that wavelength and derives a hue value from it. This is represented by the color wheel that we have right here. Once it derives that hue value, VEXcode can programmatically identify the color. It could say blue, green, or whatever it is. However, if it's not "detecting blue," that's because the ambient light is giving a different hue value, so it's not detecting blue as a result, okay?
Hopefully, that all makes sense. If it doesn't, and if it's a little bit fuzzy to you, please ask the question in the community. We're more than happy to get back in touch with you and answer all those questions that you may have.
Don't forget, if you really want to dive deep into data logging, schedule a one-on-one session with us. Schedule a one-on-one session with me or someone from the software team. We can go through potential lessons and activities you can do. We're going to have all kinds of fun talking about data logging in a one-on-one session, so I want to encourage you to do that also.
Now, in order to be able to do the data logging, you need an SD card. That is where the data is actually going to be written. The data is going to go on the SD card, and I'm going to demo this all for you here in a minute. The data is going to be written on the SD card, which we will then put in our computer, and that's how we're going to actually derive our information.
I do want to show you a knowledge-based article that we have that walks through this entire process. This is "Data logging with the VEX Brain/Sensors, the Python version." This is for VEX IQ. As I just mentioned, you're going to write the data to a CSV file on an SD card, so you want to make sure that you actually have an SD card to do this successfully. Hardware required includes a VEX Brain, an SD card, and the necessary sensors. The article goes through the different sensors you can use and the code you'll need. It's a helpful walkthrough of all the different code that you need.
Here we're showing you where to actually put the SD card in the brain. We're showing you how to do that, and there's a note on how to actually format that SD card. When you run the project, it's going to write the data to a CSV file on the SD card. The article goes through that process with the code. There's our whole project, and now we're going to open the file for data analysis. It's a wonderful knowledge-based article that you can reference as you're going through this to data logging with VEX IQ.
I already have my project loaded onto my brain, so I'm going to turn my brain on my VEX IQ robot and go to my project. My program's right there. I have the IQ data logging project ready. Now, what's going to happen here when I run the project is, first of all, you're going to see the LED light turn on. This is why it's actually started a little bit in front of the cube, and then it's going to drive slowly forward so that the sensor can read all three of these cubes.
Thank you for your attention, and I hope this information has been helpful. If you have any further questions, please feel free to reach out. We look forward to assisting you with your projects and helping you make the most of your VEX IQ experience.
So the robot's just gonna drive from here to here, and then what we're gonna do programmatically via Python is collect all the information from the optical sensor and then write it onto the SD card. So let me go ahead and run the project, okay?
(instruments clicking)
Here we go. It's going slow, obviously, you can see there. All right, and now we're done, okay, and went through and ran the project, so let me go ahead and stop it now. Now, before I pop the SD card out and put it in the microcomputer, let's go ahead and take a look at the code real quick in VEXcode. So let me go ahead and pull up VEXcode IQ. I'll just move this real quick for you, so you can see it a little bit better once I do pull it up.
All right, so again, I'll go ahead and put this project in the community so you have it, but here at the very beginning, as you can see here, the first thing that it does is it ensures that we actually have the SD card inside of the brain right here. If it doesn't, it's gonna print this message that says "Card is missing." So the very first thing that we're gonna do is make sure our card is actually in there, okay?
After we do that, we're gonna reset the timer on the brain, and now we're gonna collect the data, okay? So now what we're actually going through here, this is where we're gonna collect the data and we're going to write the data actually onto our SD card. This is what we're doing in this part of our code right here. Then after we do that, we have the conditional block to match the sensor's color output to the color name. So again, okay, the sensor itself does not see red, or blue, or green, anything else like that. Instead, what it's saying is if the data buffer is this particular value, then we're gonna assign that value as black, as white, as red, or whatever those particular things are, okay?
All right, so now we're gonna go through here, and then this, as you can see down here, now we're actually going to turn on the LED, and we're gonna set the power to 100, the light on it, and now we're gonna drive forward at a speed of 350. As you can see, our velocity of 15 right here, and we're gonna drive forward 350 millimeters, okay? So not a really overly complex program, but this is a nice Python program that we have right here.
This is a great example of students being able to do something in text that would be much more cumbersome to do in blocks. So we talk a lot about transitioning students from blocks to text-based programming. Blocks is without a doubt the best way for novice coders to get started, no matter what the age. So if you have a 4th-grade student or if you have a student that's in 11th grade, no matter what, if that student is just getting started coding, the best avenue for them to learn the basics of coding and computational thinking is in blocks.
But again, as your students progress, as they get a little bit better at coding, they get a little bit better at computational thinking, text-based is a wonderful way for them to go, but we wanna contextualize it for the students. We don't wanna just tell the students, "Okay, we're gonna do text-based coding," just to do it, but instead, we want to contextualize it so that, "Here's a problem that we wanna solve, we wanna be able to use our sensors effectively, we wanna be able to see inside that black box. How do we solve that problem? We can use text-based coding to do it."
That's a much more authentic way to introduce text-based coding to your students as opposed to just saying, "Okay, we could have done this project in blocks, but now we're just gonna do it in text," and your kids might be, "Well, why? I'd just rather use blocks to enable to do it." This would be a much more difficult project to do in blocks as you see here in text, so it really helps authenticate for the students why they are actually going from blocks to text-based coding.
And also, don't forget, if you have students transitioning from blocks to text-based coding, we do have switch blocks to allow them to do that. If you have questions about that, you can ask in the community.
So let me go ahead and pop out the SD card now, okay? It normally takes me about two or three tries to do this just because I do not have fingernails. Hey, it took only my third try, I got it there. Now, I'm going to put my SD card into my computer, right here, so there we go, it's in.
Let me now go to my computer view. I'm going to close VEXcode, minimize that, okay. I can go to my computer view now, and you can see VEX came up in the upper right-hand corner up here. There it is, right there. So now I'm going to double-click on it, okay, and now I have this data log file, the CSV file that we've been talking about. Let me go ahead and open that up now.
Okay, so now you can see the different values that the robot saw as we went through here, okay? I think it was 100 total. Yep, 100 entries total, that was the array that we had set up, but notice here, that's going to start off with green as I start. Now, you'll notice that green is not my first cube that I had here, so why is it seeing green? Because if you remember, I started the robot right here, so it did not bounce off of this blue cube initially. Instead, it bounced off whatever's on the opposite wall over here, which, of course, you can't see, but what was returned back was that green value, okay?
So let's go back to our computer. As I scroll down here, now I actually get the blue. Now, I got this color cyan in between, I hope I'm pronouncing that correctly, I'm not up on my colors, but you'll see here, that's the transition here between right about here, before it started the blue, right? And now I can see on my computer, now it's actually getting that blue hue value. So I'm going to go from blue, there's cyan again, the transition from, now, instead of from green to blue, now, I'm going from blue to green, okay? And now I'm going from green, to nothing, to yellow.
Now, this is what I love. Yellow, why is it... There's no yellow cube in front of me here. Why is it getting yellow? Again, as it went through, it did not detect that's probably right about here, when I got the none value, but as it was going from nothing to red, that's where it got the yellow value of it. So this, I love it, this is fantastic.
If you wanted your robot to see red and then do something, and depending upon the timing that you have with your robot, your robot, when it "saw red," did not stop, did not turn, whatever it wanted you to be able to do, and this causes the frustration, maybe amongst you, but probably definitely amongst your students. "Mr. McKenna, what is going on? My sensor is on red, on the red cube, it's supposed to see red and stop, but it's still continuing to run. What is happening here?"
Well, now we can pull behind the curtain, we can peek behind the curtain, and we can actually see, well, your robot's not seeing red, it's actually seeing yellow. How cool is that? So again, this can then, you can have that conversation with your students, this is a wonderful learning opportunity about what your robot is actually seeing. It is not seeing a color, it's seeing a hue value. That's the circle I showed you before. It's seeing a hue value, and because it's seeing the hue value, when the sensor begins to see the red, that transition, because the entire sensor is not on the cube, that's why you're actually seeing yellow. What a wonderful learning opportunity for your students right there. Same thing with the cyan. That's why it's not seeing the specific color on the cube, it's that transition.
Wonderful learning opportunity for the students to teach them that the robot is doing exactly what you are coding it to do, right? The robot's doing exactly what you're coding it to do, but the sensor values that we are getting are not what we're expecting to get. Why is that? Now you can use data logging to investigate that and to make your code that much better.
To go back to the example I talked about earlier, depending upon the time of day, the different ambient light, if I shut off one or two lights here in our classroom, you also might get different values that you see here, and as a result of that, that could mess up what you potentially want your code to do, okay? So all kinds of fun stuff that we can derive from this. You see the red, red, red, and then finally get the none value, and that's when I'm at the end of my project. But wonderful things that we can do here with our code that we could see.
Now, the other thing that we can do, again, it's Computer Science Education Week, so let's talk a little bit about artificial intelligence, AI. So let me go ahead and minimize this. Now I can go to ChatGPT, and you can see I have a prompt here in ChatGPT: Can you analyze this data from the robot driving 350 millimeters and mapping the colors that it sees over that period? Note, the hue is the third column of the spreadsheet, that's what I just had up a second ago, and time is the first column. That can be used to extrapolate for distance traveled.
So now let me go ahead and add the CSV file. There it is, right there. I can open that up. There it is. Now I can run my data analysis in ChatGPT. ChatGPT is gonna load it, it's gonna tell me what it's doing here, okay? It's analyzing that. I'm just gonna open that up so you can see it. There you go. There's all my Python that it's using right there to analyze it, okay? All right, okay, it's talking to me some more. We're gonna calculate the robot's speed, map the values against the distance, okay? There we go, some more there. It's calculating the distance covered at each time point.
Now, this is important, because again, if we had our robot doing something at a certain time, now it's gonna create a plot to visualize how the hue changes over the distance. If we had our robot doing something according to a distance of where it was out on a competition field, now we can see, based upon the graph that ChatGPT has created for me right now, what the robot sees at a particular distance when the robot is traveling. Hey, there's my graph. Look how cool that is, right? There's my distance at the bottom and there's the hue value, and so now, as a result of this, I can see what my robot sees, depending upon where it is according to the distance, all right?
So I can see when my... If I had the distance actually mapped out here, okay, in millimeters, I can see, okay, when my robot is here, I can see what the hue value is, and now I can make a determination of what I want my robot to do, because I know exactly the hue value that it's getting. Or right here, it's actually detecting, or actually, right here, it's detecting yellow not red, right? So that's what we just talked about a moment ago. And now I can use the data analysis with artificial intelligence to actually see what my robot sees at a specific distance. How cool is that?
So again, you're talking about... It's Computer Science Education Week, we're talking about artificial intelligence, we're talking about coding, look at all this cool stuff that we were able to apply here in an authentic real-world situation with our robot to really be able to contextualize and teach in an authentic fun, engaging way, data science, artificial intelligence, using data to make informed decisions, computational thinking, all of that rolled up together in a wonderful way for your students with physical computing with their VEX IQ robot.
Again, if your students are a little bit more advanced in coding, I'm jealous of you if you're doing this in your classroom from Hour of Coding. I used to love to teach this in my classroom because, you know, this is what we all get out of bed for, as teachers, is that aha moment from our students, like, "Oh, (claps loudly) that's why my robot's not stopping," or "Oh, that's why my robot's doing that." Those are the things that we love in the classroom, and that's what you're gonna get when you're able to introduce data into your coding through something like this, okay?
So hopefully, you'll be able to take something from this live session and apply it back into your classroom session with data logging. But if you need more information, you wanna explore some things further, don't be afraid to schedule a one-on-one session with myself or someone from the education team. We would love to talk with you about how you can use data logging authentically in your class, with your students. We can brainstorm some ideas for activities and lessons together, then you can share that activity and lesson and be an all-star in our VEX professional learning community.
So thank you very much for joining me at this webinar today. Keep an eye on the community while we add in this code in there. Enjoy Computer Science Education Week, and I'll see you again soon, in 2024, for our next batch of lab sessions.
Thank you very much.
(lively music)
Hi, welcome to our Live Session, where today, it's my pleasure to talk to you about data logging with VEX IQ. I'm Jason McKenna, VP of Global Educational Strategy here at VEX Robotics, and I can't wait to talk to you about data logging, because honestly, this was one of the things I did in my classroom that I enjoyed the most. I used to love doing data logging. This was back before data science was actually a thing, so I might have been a little bit ahead of my time in my classroom when I was doing it. This is something I really loved doing with my students because it was an opportunity for them to collect data, take a look at the data, and then use that data to make informed decisions about what they were actually trying to code with their robot.
At the very beginning, when students are just getting started with coding, kind of guessing and checking their way through a solution is a great technique to utilize. It shows that students are resilient, engaged, and iterative with their approach to coding and computer science. However, as you progress, you want your students to take a more sophisticated approach to what they're doing with computer science and their robot, and data logging is a great example of this.
This is a great time to be doing this live session, as it is Computer Science Education Week. If you are in the middle of Computer Science Education Week right now, please don't forget that you can go to hoc.vex.com, where we have a lot of different activities to engage your students. We have activities with physical robots, like VEX IQ, and activities with our virtual robot. There's a teacher's guide for each of those activities, as well as a student activity page. We have very cool features, like leaderboards, where you can check out how your students rank against others in the world with different VR playgrounds. All of the VR playgrounds are free during this month of December, so even if you have the free account for VEXcode VR, you can play the virtual skills game or Maze Solver Plus. Some of our more exotic playgrounds are available for you to check out for the month of December, in honor of Computer Science Education Week.
I hope you're having a wonderful Computer Science Education Week. If you're looking for an activity to do later this week, or later this month, what I'm about to show you with data logging is a really fun thing to utilize with your students in the classroom. This would obviously not be a beginning activity. I want to show you a Python program here in a moment, which will not be something you want to do with beginning students. However, as your students progress throughout VEXcode and with VEX IQ, if you're a competition team, for example, or if your students have been coding with VEXcode IQ for a while, this is a wonderful activity to incorporate data science and higher levels of computational thinking in your classroom.
When we talk about data logging with VEX IQ, what do we mean? What are we actually talking about? Well, the word kinda says it itself. We are logging data, collecting data, and then we want to be able to use that data to make informed decisions about what our robot is doing on the competition field or in our classroom, and then we can adjust our code accordingly.
Now, to contextualize this for you, to truly make it hit home, I'm going to be using the optical sensor on the VEX IQ robot to really, again, contextualize this for you. Anytime you code with sensors, one of the biggest questions we always get in our support, from customers and teachers like you, is, "My sensor is not working as I expect it to work. I think the logic in the code is right, the logic in my program is correct, but the robot, the sensor is not performing as I expect. So when it sees blue, for example, it's supposed to turn right, or it's supposed to stop," or whatever those particular things are, "but the robot is not doing that. Why? Why is that?"
Now, oftentimes, when we get that question, the reason why you're asking us that question is because that decision-making that the robot is doing is in a black box. What I mean by that is our assumption from our code is that when the robot sees blue, or specifically, when the optical sensor sees blue, the robot is supposed to do something, it's supposed to stop, it's supposed to turn, whatever, but it's not doing that. But we don't actually know what the sensor is seeing. We don't know the input that our code is actually receiving from the sensor. That's what I mean by a black box, it's a mystery to us. As a result of that, we don't know what to do. We can try different parameters, we can try different commands, and that oftentimes leads to frustration, because again, we feel like our logic is correct from a coding perspective, but the robot is not performing as it should perform. Is my sensor wrong, or is there something wrong with my robot? Then I'll update VEXcode. So you kinda go through all these different things to try to figure out what the problem is, again, because it's a black box.
Now, what data logging does, it allows you, like in the Wizard of Oz, to peek behind the curtain, right? (chuckles) It allows you to take the cover off so you can actually see what's inside of that box, so you can actually see what's going on there, and that's what I'm gonna illustrate for you here today, in this live session. You can use the data, that's what we mean by removing the black box, giving you the opportunity to see, or shining a light on the black box, whatever metaphor you wanna use, but you can actually use the data to understand what the sensor is seeing and understand what the sensor is doing, so now you can make informed decisions about what you want your robot to do when it reaches a certain point in the competition field, (coughs) excuse me, or if you're solving a classroom challenge.
Now, just a reminder, if you're watching this, you're a PD+ subscriber and you're watching this, and if you have to step away or if you have to leave early, do not worry, you can always watch the recording later. Our team here will have this up on the site in no time at all, so don't forget that. Also, if you have any questions about anything that you see during the course of this live session, please, you can ask that question in the community. Either myself or a member of our software team will be more than happy to answer that particular question for you. All the code you're gonna see during the course of this lab session, I will share in the community. That way, you have an opportunity to use it and utilize it on your own. And again, if you're looking for a fun activity to do this week, for Computer Science Education Week, and your students are a bit more advanced coders, this would be a great one for you to be able to do.
So to start talking about this, to start talking about data logging and data science VEX IQ, let's first talk about the optical sensor, okay, right here on my VEX IQ robot, and what it's actually doing.
Now, the first thing you have to understand with the optical sensor is that your optical sensor actually does not see a color. It does not see blue, it does not see green, it does not see red, okay? We see things around in our environment with our eyes, and we associate colors with that, obviously. That's how we communicate, are those colors. Well, our robots and our sensors are not quite that sophisticated.
How the optical sensor actually works... First of all, when I run this project, you're gonna see an LED light turn on that's gonna illuminate the surroundings or what's directly in front of the optical sensor. Then what it does, the sensor actually does, it emits a light, okay? So a light comes out of the optical sensor, and then it's gonna bounce off of these objects that I have in front of it, these cubes that I have right here, or if you are going to a wall, or whatever, it's going to bounce, it's gonna send the wavelength to that object, and then because it's gonna, because that object is there, the wavelength is gonna bounce back to the actual sensor.
Using math, then, what the sensor then actually does is it derives a hue value. So what the optical sensor is actually determining is not a color, not, you know, blue, green, red. Instead, it's determining a hue value. So let's go to the computer, and I can actually show you the hue value of the robot. So there's our hue value for VEX right there. You can see right up here at red, about zero is red, then we get into our greens over here, and our blues around the value of 240. So this is what your robot is, this is what your sensor is actually deriving, based upon what is going on in the wavelength that's returned to it.
Now, where this gets a little bit tricky is that ambient light that you have in your classroom is going to affect that wavelength, that wavelength that's being bounced back to your robot, to your sensor. If you have a lot of light in your room, you're gonna get certain values. If your room is darker, you're gonna get less values. This used to happen to me when I taught all the time, okay? Because of where my room was, in the morning, we got a lot of sunlight, okay, in the windows in the room. So we got a lot of sunlight in the morning, so therefore, the ambient light in the room was a lot different when I was teaching 2 or 3 o'clock in the afternoon, because now, the sun was no longer there, right, so now the amount of ambient light I had in the room was completely and totally different, so as a result of that, if I had code that I was using in period one, I'd have my code up on the board, I'd have certain values in there, I would talk about this with the students, they would run the project during period one, and (claps loudly) everything worked fantastic, everything worked great.
Then I'd go do that same exact project in period seven, the ambient light is different, and my code would not run the same. The sensor would no longer see blue, and (chuckling) that would obviously cause me to be very frustrated, because this exact same project worked this morning, why is it no longer working now? Now, you could carry that example further. Your robot works on your competition field at your school, but when you go to a different school, on their competition field, the robot, the sensors are no longer working the exact same way, again, because the ambient light, the environment is much different, okay, so as a result of that, if we can use data science and data logging to basically cut down on that.
So to review, what your optical sensor is actually doing, it does not read a color, it does not see the blue cube and say blue, it does not see the green cube and see green. Instead, what it does, it emits a light, okay, the LED light. When it emits that light, it's setting off a wavelength, okay, light travels in waves, so it's gonna send out a wavelength.
Thank you for your attention and interest in understanding how optical sensors work. I hope this explanation has been helpful and informative. If you have any questions, feel free to ask.
When it detects an object, when that wavelength hits an object, it's then going to return back to the sensor. The qualities of that wavelength are then mathematically processed by your sensor, which takes that wavelength and derives a hue value from it. This is represented by the color wheel that we have right here. Once it derives that hue value, VEXcode can programmatically identify the color. It could say blue, green, or whatever it is. However, if it's not "detecting blue," that's because the ambient light is giving a different hue value, so it's not detecting blue as a result, okay?
Hopefully, that all makes sense. If it doesn't, and if it's a little bit fuzzy to you, please ask the question in the community. We're more than happy to get back in touch with you and answer all those questions that you may have.
Don't forget, if you really want to dive deep into data logging, schedule a one-on-one session with us. Schedule a one-on-one session with me or someone from the software team. We can go through potential lessons and activities you can do. We're going to have all kinds of fun talking about data logging in a one-on-one session, so I want to encourage you to do that also.
Now, in order to be able to do the data logging, you need an SD card. That is where the data is actually going to be written. The data is going to go on the SD card, and I'm going to demo this all for you here in a minute. The data is going to be written on the SD card, which we will then put in our computer, and that's how we're going to actually derive our information.
I do want to show you a knowledge-based article that we have that walks through this entire process. This is "Data logging with the VEX Brain/Sensors, the Python version." This is for VEX IQ. As I just mentioned, you're going to write the data to a CSV file on an SD card, so you want to make sure that you actually have an SD card to do this successfully. Hardware required includes a VEX Brain, an SD card, and the necessary sensors. The article goes through the different sensors you can use and the code you'll need. It's a helpful walkthrough of all the different code that you need.
Here we're showing you where to actually put the SD card in the brain. We're showing you how to do that, and there's a note on how to actually format that SD card. When you run the project, it's going to write the data to a CSV file on the SD card. The article goes through that process with the code. There's our whole project, and now we're going to open the file for data analysis. It's a wonderful knowledge-based article that you can reference as you're going through this to data logging with VEX IQ.
I already have my project loaded onto my brain, so I'm going to turn my brain on my VEX IQ robot and go to my project. My program's right there. I have the IQ data logging project ready. Now, what's going to happen here when I run the project is, first of all, you're going to see the LED light turn on. This is why it's actually started a little bit in front of the cube, and then it's going to drive slowly forward so that the sensor can read all three of these cubes.
Thank you for your attention, and I hope this information has been helpful. If you have any further questions, please feel free to reach out. We look forward to assisting you with your projects and helping you make the most of your VEX IQ experience.
So the robot's just gonna drive from here to here, and then what we're gonna do programmatically via Python is collect all the information from the optical sensor and then write it onto the SD card. So let me go ahead and run the project, okay?
(instruments clicking)
Here we go. It's going slow, obviously, you can see there. All right, and now we're done, okay, and went through and ran the project, so let me go ahead and stop it now. Now, before I pop the SD card out and put it in the microcomputer, let's go ahead and take a look at the code real quick in VEXcode. So let me go ahead and pull up VEXcode IQ. I'll just move this real quick for you, so you can see it a little bit better once I do pull it up.
All right, so again, I'll go ahead and put this project in the community so you have it, but here at the very beginning, as you can see here, the first thing that it does is it ensures that we actually have the SD card inside of the brain right here. If it doesn't, it's gonna print this message that says "Card is missing." So the very first thing that we're gonna do is make sure our card is actually in there, okay?
After we do that, we're gonna reset the timer on the brain, and now we're gonna collect the data, okay? So now what we're actually going through here, this is where we're gonna collect the data and we're going to write the data actually onto our SD card. This is what we're doing in this part of our code right here. Then after we do that, we have the conditional block to match the sensor's color output to the color name. So again, okay, the sensor itself does not see red, or blue, or green, anything else like that. Instead, what it's saying is if the data buffer is this particular value, then we're gonna assign that value as black, as white, as red, or whatever those particular things are, okay?
All right, so now we're gonna go through here, and then this, as you can see down here, now we're actually going to turn on the LED, and we're gonna set the power to 100, the light on it, and now we're gonna drive forward at a speed of 350. As you can see, our velocity of 15 right here, and we're gonna drive forward 350 millimeters, okay? So not a really overly complex program, but this is a nice Python program that we have right here.
This is a great example of students being able to do something in text that would be much more cumbersome to do in blocks. So we talk a lot about transitioning students from blocks to text-based programming. Blocks is without a doubt the best way for novice coders to get started, no matter what the age. So if you have a 4th-grade student or if you have a student that's in 11th grade, no matter what, if that student is just getting started coding, the best avenue for them to learn the basics of coding and computational thinking is in blocks.
But again, as your students progress, as they get a little bit better at coding, they get a little bit better at computational thinking, text-based is a wonderful way for them to go, but we wanna contextualize it for the students. We don't wanna just tell the students, "Okay, we're gonna do text-based coding," just to do it, but instead, we want to contextualize it so that, "Here's a problem that we wanna solve, we wanna be able to use our sensors effectively, we wanna be able to see inside that black box. How do we solve that problem? We can use text-based coding to do it."
That's a much more authentic way to introduce text-based coding to your students as opposed to just saying, "Okay, we could have done this project in blocks, but now we're just gonna do it in text," and your kids might be, "Well, why? I'd just rather use blocks to enable to do it." This would be a much more difficult project to do in blocks as you see here in text, so it really helps authenticate for the students why they are actually going from blocks to text-based coding.
And also, don't forget, if you have students transitioning from blocks to text-based coding, we do have switch blocks to allow them to do that. If you have questions about that, you can ask in the community.
So let me go ahead and pop out the SD card now, okay? It normally takes me about two or three tries to do this just because I do not have fingernails. Hey, it took only my third try, I got it there. Now, I'm going to put my SD card into my computer, right here, so there we go, it's in.
Let me now go to my computer view. I'm going to close VEXcode, minimize that, okay. I can go to my computer view now, and you can see VEX came up in the upper right-hand corner up here. There it is, right there. So now I'm going to double-click on it, okay, and now I have this data log file, the CSV file that we've been talking about. Let me go ahead and open that up now.
Okay, so now you can see the different values that the robot saw as we went through here, okay? I think it was 100 total. Yep, 100 entries total, that was the array that we had set up, but notice here, that's going to start off with green as I start. Now, you'll notice that green is not my first cube that I had here, so why is it seeing green? Because if you remember, I started the robot right here, so it did not bounce off of this blue cube initially. Instead, it bounced off whatever's on the opposite wall over here, which, of course, you can't see, but what was returned back was that green value, okay?
So let's go back to our computer. As I scroll down here, now I actually get the blue. Now, I got this color cyan in between, I hope I'm pronouncing that correctly, I'm not up on my colors, but you'll see here, that's the transition here between right about here, before it started the blue, right? And now I can see on my computer, now it's actually getting that blue hue value. So I'm going to go from blue, there's cyan again, the transition from, now, instead of from green to blue, now, I'm going from blue to green, okay? And now I'm going from green, to nothing, to yellow.
Now, this is what I love. Yellow, why is it... There's no yellow cube in front of me here. Why is it getting yellow? Again, as it went through, it did not detect that's probably right about here, when I got the none value, but as it was going from nothing to red, that's where it got the yellow value of it. So this, I love it, this is fantastic.
If you wanted your robot to see red and then do something, and depending upon the timing that you have with your robot, your robot, when it "saw red," did not stop, did not turn, whatever it wanted you to be able to do, and this causes the frustration, maybe amongst you, but probably definitely amongst your students. "Mr. McKenna, what is going on? My sensor is on red, on the red cube, it's supposed to see red and stop, but it's still continuing to run. What is happening here?"
Well, now we can pull behind the curtain, we can peek behind the curtain, and we can actually see, well, your robot's not seeing red, it's actually seeing yellow. How cool is that? So again, this can then, you can have that conversation with your students, this is a wonderful learning opportunity about what your robot is actually seeing. It is not seeing a color, it's seeing a hue value. That's the circle I showed you before. It's seeing a hue value, and because it's seeing the hue value, when the sensor begins to see the red, that transition, because the entire sensor is not on the cube, that's why you're actually seeing yellow. What a wonderful learning opportunity for your students right there. Same thing with the cyan. That's why it's not seeing the specific color on the cube, it's that transition.
Wonderful learning opportunity for the students to teach them that the robot is doing exactly what you are coding it to do, right? The robot's doing exactly what you're coding it to do, but the sensor values that we are getting are not what we're expecting to get. Why is that? Now you can use data logging to investigate that and to make your code that much better.
To go back to the example I talked about earlier, depending upon the time of day, the different ambient light, if I shut off one or two lights here in our classroom, you also might get different values that you see here, and as a result of that, that could mess up what you potentially want your code to do, okay? So all kinds of fun stuff that we can derive from this. You see the red, red, red, and then finally get the none value, and that's when I'm at the end of my project. But wonderful things that we can do here with our code that we could see.
Now, the other thing that we can do, again, it's Computer Science Education Week, so let's talk a little bit about artificial intelligence, AI. So let me go ahead and minimize this. Now I can go to ChatGPT, and you can see I have a prompt here in ChatGPT: Can you analyze this data from the robot driving 350 millimeters and mapping the colors that it sees over that period? Note, the hue is the third column of the spreadsheet, that's what I just had up a second ago, and time is the first column. That can be used to extrapolate for distance traveled.
So now let me go ahead and add the CSV file. There it is, right there. I can open that up. There it is. Now I can run my data analysis in ChatGPT. ChatGPT is gonna load it, it's gonna tell me what it's doing here, okay? It's analyzing that. I'm just gonna open that up so you can see it. There you go. There's all my Python that it's using right there to analyze it, okay? All right, okay, it's talking to me some more. We're gonna calculate the robot's speed, map the values against the distance, okay? There we go, some more there. It's calculating the distance covered at each time point.
Now, this is important, because again, if we had our robot doing something at a certain time, now it's gonna create a plot to visualize how the hue changes over the distance. If we had our robot doing something according to a distance of where it was out on a competition field, now we can see, based upon the graph that ChatGPT has created for me right now, what the robot sees at a particular distance when the robot is traveling. Hey, there's my graph. Look how cool that is, right? There's my distance at the bottom and there's the hue value, and so now, as a result of this, I can see what my robot sees, depending upon where it is according to the distance, all right?
So I can see when my... If I had the distance actually mapped out here, okay, in millimeters, I can see, okay, when my robot is here, I can see what the hue value is, and now I can make a determination of what I want my robot to do, because I know exactly the hue value that it's getting. Or right here, it's actually detecting, or actually, right here, it's detecting yellow not red, right? So that's what we just talked about a moment ago. And now I can use the data analysis with artificial intelligence to actually see what my robot sees at a specific distance. How cool is that?
So again, you're talking about... It's Computer Science Education Week, we're talking about artificial intelligence, we're talking about coding, look at all this cool stuff that we were able to apply here in an authentic real-world situation with our robot to really be able to contextualize and teach in an authentic fun, engaging way, data science, artificial intelligence, using data to make informed decisions, computational thinking, all of that rolled up together in a wonderful way for your students with physical computing with their VEX IQ robot.
Again, if your students are a little bit more advanced in coding, I'm jealous of you if you're doing this in your classroom from Hour of Coding. I used to love to teach this in my classroom because, you know, this is what we all get out of bed for, as teachers, is that aha moment from our students, like, "Oh, (claps loudly) that's why my robot's not stopping," or "Oh, that's why my robot's doing that." Those are the things that we love in the classroom, and that's what you're gonna get when you're able to introduce data into your coding through something like this, okay?
So hopefully, you'll be able to take something from this live session and apply it back into your classroom session with data logging. But if you need more information, you wanna explore some things further, don't be afraid to schedule a one-on-one session with myself or someone from the education team. We would love to talk with you about how you can use data logging authentically in your class, with your students. We can brainstorm some ideas for activities and lessons together, then you can share that activity and lesson and be an all-star in our VEX professional learning community.
So thank you very much for joining me at this webinar today. Keep an eye on the community while we add in this code in there. Enjoy Computer Science Education Week, and I'll see you again soon, in 2024, for our next batch of lab sessions.
Thank you very much.
(lively music)
Share
Like this video? Share it with others!
Additional Resources
Like this video? Discuss it in the VEX Professional Learning Community.