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

Datalogging with VEX V5

Elevate Your Teaching Game with Data Logging on the VEX V5 Platform with this Live Session. Aimed at educators who are no strangers to technology, this session explores the intricacies of capturing and analyzing data using Python and the VEX V5 robotics system. Master the art of real-time monitoring and problem-solving through actionable data. Watch now to journey into the frontier of 21st-century education.

(lively music)

Hi, welcome back to the VEX Classroom. It's my pleasure to be with you here today for our Live Session where we are going to be talking about Datalogging with our V5 robot. Now, I am really excited to share this information with you here today, because to be honest with you, this is one of my favorite subjects and things to do. Back when I was in the classroom a few years ago, I used to love doing datalogging with my students, because it was just such an interesting activity for them.

You know, data science is a big deal right now. There's a lot of things going on with data science. There's people talking about how data science should be a math credit in high school and data science should be taught to younger students so they're familiar with it. This is a great way to introduce data science in with robotics and contextualizing information for the students to give them a real-world application of what data science actually means and how they can use it.

But the reason I used to love doing datalogging in my classroom environment was that it gave my students information when they were trying to figure out the code and the program and at a higher level of the computational thinking that we want to be able to do with our robots. So this is an example of that. One of the biggest questions that we get all the time is, I'm trying to code with the optical sensor for V5, for example, and I want the robot to do something when it detects the color of an object. So maybe I drive into a green or when I see a certain colored object, I place it somewhere if I'm like doing a competition or something else along those lines.

And oftentimes, the sensor doesn't work or I perceive that it doesn't work as I intended to be able to do. So what do I then do? A lot of this comes back to the fact that you just don't have the necessary information to really understand what it is you're trying to do with the sensor and how you can then take that information and make your code that much smarter or that much better. That's what we're gonna talk about now with datalogging.

So instead of you trying to guess and trying to figure things out, we're gonna use an example real quick with these three game objects from this year's game to really kind of dive into what datalogging is and to understand it better. Now, all the code that I'm going to use, I'm going to put in the community. So don't worry about trying to copy down the code I have on here, I'm gonna put it in the community. If you have questions about it, you can obviously ask questions in the community. If you have more questions just about datalogging, ask those questions in the community.

We'll be doing another live session on datalogging, but this one will be on VEX IQ in the next month, but again, if you have questions about datalogging, you can ask those questions in the community. You can also request a one-on-one session, which we go over the code with you or talk about datalogging more generally, whatever it is that you need. But this is a really cool thing to do in your classroom or with your competition team to really take their coding kind of to the next level, to the next step.

So I'm gonna use the example of the optical sensor here during our live sessions. So let's just take a few minutes to talk about what the optical sensor is actually doing. Now, just to kind of get this out of the way, an optical sensor specifically does not detect a color. So what do I mean by that? So it does not see red. It does not see green. It does not see blue. What an optical sensor actually does is it's able to discern a hue value, okay?

Now how does it actually do that? Well, what an optical sensor does, it's actually reading the wavelength that's being reflected back to it, okay? So I have my optical sensor right here on my robot. So let's say it's pointed at this green object right here.

Thank you for joining us today. We hope you found this session informative and engaging. If you have any further questions or need additional support, please don't hesitate to reach out in the community or request a one-on-one session. We look forward to seeing you in our next live session on VEX IQ. Have a great day!

The optical sensor has an LED light inside of it. It's going to turn on, okay? The optical sensor can also detect brightness, which we'll see during our experiment. So it's gonna turn it on, and then when it turns it on, that's going to obviously eject some light. But it's also then, what it's going to do, it's going to emit that light as a wavelength. It's going to be bounced back and returned to the sensor. That's what the sensor is actually reading.

Now, this is all numbers and data, again, we were talking about data science earlier, with some mathematical calculations. What it's actually doing, it's converting that wavelength into a hue value. So what I mean by hue value, you see right here, this is a color wheel. So this is something that is used and the color wheel is from zero to 359. This is something used to represent hue values, actual colors, right? So you can see both zero and 359 is like around red, 60 is around yellow. Then we get into blues and purples and whatnot. But this is what the actual optical sensor is able to determine.

Now, go back to what I mentioned before. It's going to use the LED to emit a light and then it's the wavelength that's returned back to it. So ambient light, the light surrounding the sensor, obviously is going to have an impact on what is actually being returned to that sensor, okay? So the light conditions that your classroom is in is going to change the hue values that your robot is actually perceiving. That's very important, because again, the robot doesn't see red, it doesn't see blue. It sees those hue values and those hue values change with the ambient light that surrounds your sensor.

This again used to happen to me in my classroom all the time, whereas I would get different values in the morning when the sun was coming to my classroom. But as the sun moved in the afternoon, the thresholds will no longer work with my students, were coded and it had to change. You might have your optical sensor work perfectly in your specific classroom environment, but then when you go to a competition and there's different surrounding light, there's different ambient light, now the sensor does not work as intended. So what you have to be able to do is you have to be able to capture those hue values.

Now, you can capture hue values using your V5 brain. So it's just setting your V5 brain where you can actually go through and you could see the values. But what I have to do there, is I would manually move my robot and I can then see on my robot brain screen, the hue values changing. But that's not really analogous to what your robot is going to be doing with your classroom challenge or on your competition field. The robot's gonna be moving at different speed. It's gonna move at a different pace. It might be a different distance away from the object you're trying to detect. All these different things go into it.

So through datalogging, what you could do, is have your robot run in your classroom challenge, your competition field, whatever, collect the data, then you can actually see the data and you can actually see what your robot is seeing and then make choices from a coding perspective based upon that data that you are actually seeing. And again, you're not guessing or you're not trying to look over your robot as it's running as mine, I used to run this in my classroom. My students would follow the robot with a laptop that was tethered to the robot to actually see the values updating as the robot was running in our classroom challenge or on the field and of course, that was a little bit difficult for them because they're looking on their laptop. Sometimes they would trip. It would become a big thing.

So you can avoid all that by using the SD card, which I'm gonna show you here in a moment, to collect the information and then actually see what's going on.

You have to understand a little bit about how this optical sensor works. Now, all those things I talked about can be very abstract. This process of datalogging makes that abstract a lot more concrete and will help your students understand what your optical sensor is actually doing. The goal is for them to code with it effectively, and if the robot does something that's not intended, they can troubleshoot it effectively and have it work out.

What I'm gonna do to show off the datalogging here is have the robot move just like this, starting right here. The optical sensor is right here, and I'm gonna have it move. The optical sensor will get readings from these three objects here. Those readings, the data it collects, according to my code, which I'll show you here in a moment, are being formatted. After it collects the data and formats it, it's putting all that on an SD card. I'm gonna take the SD card out of my brain, put it in my computer, and then I'll be able to see the values. We'll do one other thing: we'll actually graph the values to give you a real representation of what this could look like. Then we'll talk about how you could apply this again in your classroom setting.

I already have the code downloaded onto the robot, so I'm gonna turn my V5 brain on. I have my SD card inside. If you're curious about things like what type of SD card to use for this, we have a knowledge base article, which I will also put in the community. You can reference it to see all the information you need about how to use the SD card with your V5 brain to do the datalogging. It's a great resource. It'll be in the community, along with the code, so you can see all that information.

I'm actually gonna start my project a little bit in front of my first game object here. Let me go and select my project. Now it's gonna slowly move forward and then stop, but it'll collect the data from all three of these different game objects. I'm gonna hit run now.

Music Cue

The LED light turns on. It runs and collects the data. You should've seen the LED light turn on. Now, what it's actually gauging is the wavelength returned back to it, bouncing off of these objects and returning it back, then mathematically converting that value into a hue. Let me shut off my project and stop it. Now I'm just gonna pop out my SD card right here. Usually, it takes me two or three tries to pop this out just because I don't have fingernails. There we go. I just popped that out, and now I'm gonna put it in my computer. Take my SD card and pop it in right there.

The first thing we're gonna look at, and I'm gonna pull it up on the computer right now, is actually VEXcode. I'm just gonna talk about this at a high level. I'll put the code in the community, so if you have questions about it, you can ask there. You can schedule a 1-on-1 session. There are a bunch of different options you can do, so don't feel like you have to grab this all now.

Now I'm using, as you can see here, the Python version of VEXcode. We're dealing with strings, and we're formatting tables. This is a great application to show why you'd want to transition your students eventually from blocks to text-based coding. This would be a very difficult project to do in blocks. In text, it's not that long of a project. It would be very cumbersome to do in blocks. This is a good example of why your students, once they progress to a certain level of coding, would want to go from blocks to text. In VEXcode, we have Switch to help with that particular transition. We're excited about that.

Music Cue

Thank you for your attention and interest in this project. If you have any questions or need further assistance, please feel free to reach out. We appreciate your dedication to learning and teaching with VEXcode.

So you can see up top here, the first thing I'm doing is importing the library so I can run the Python specifically. This first thing, lines 35 through 37, is basically telling me to format the SD card and to make sure that I have the SD card inside the program. That's what's going on down here. Check and make sure that the SD card is actually in the brain. If it wasn't in the brain, it would give me this little warning. They say, here it says, "Card missing."

Up here, I'm configuring my variables. Okay, so I'm naming the actual CSV file. I got a 40 millisecond delay in between the pulling. So I got a 40 millisecond delay between when I'm grabbing the value. I have a number of data entries. I'm creating a buffer of data so I can actually then write it to the SD card. This now I'm actually setting up the header file right there, as you can see here. Okay, so I'm actually going through and doing that. Checking for the insertion. And now I'm actually collecting the data, okay? So you can see here, now I'm actually going through and collecting the data and then down here with this, if else's conditional loop down here, what I'm doing there is I'm actually going through and assigning the color value according to the values that we get with the hues. That's all the information that we have up on there.

So now what I'm gonna do, is I'm gonna now take a look at the values right here that we got from collecting the data, okay? So I set this up so this would automatically open in VS Code just to kind of visualize it a little bit better for you so you could see different values. So you could see over here in the left, those are the time values. Remember, we had a 40 millisecond interval between our times, okay? Remember I said it's gonna do brightness, okay? So this is gonna detect brightness. So if it's a completely and totally black room and there's no other light in the room, it's gonna be not bright. It's gonna absorb all the LED light. But if it's bouncing off something, that's gonna be a little bit brighter and you can see a change here as I go through the different objects. I go down to eight, seven, then it goes back up again. You can see all that change. You can see the correspondence there also, okay? Then I have the brightness and then here I have the hue, right? So I have my different hue values here.

Now, look what's interesting about this, okay? So as I go through here, I get this non-value here, because it actually didn't detect anything. That probably means it was in between my game objects, but notice here, notice these values, I got yellow, I got yellow, I got yellow, 11, 12, 13, okay? I have yellow. Now what's crazy about that is I do not have a yellow object up here, okay? So why was it detecting yellow? Well, obviously as it moved between the blue and the green, that's kind of when it detected the yellow. Now that goes back to what I was talking about at the very beginning of the live session, in that if you're trying to have your robot detect a color and then do something when it detects a color, when it doesn't do what you intended, you're like, well what, it's on green? Why did it not detect green? Well, maybe it's on the curvature right here. Or maybe because the robot, how it was moving, the speed it was moving, it just conflated the blue and the green. Maybe you gotta slow it down a little bit, right? But you can see here it saw yellow. So in my program, if I wanted my robot to do something when it saw green, it's not detecting green. Remember, it's not detecting any color, it's detecting a hue and that hue value was actually equal to yellow.

Now imagine this, if I'm running this on my, and notice the cool thing about this again is at the time that it's running right here. So you can run your robot and you can, as your robot is running, you can imagine recording your robot run on a competition field, okay? And then you have a timer with it running.

So you can see where your robot's at according to a certain time on the competition field. And now I can see the actual colors, the hue, excuse me, I can see the hue and the brightness and the color that correspond with the robot when it's at that particular point.

What's really cool about this, and again this is why I love teaching it, is that instead of you trying to guess, "Well, why is my robot not detecting green? Or why is it not detecting red?" you can actually have the data to see what your sensor is actually detecting. This is a really good conversation you could have with your students. You could say, "Well, remember the optical sensor, it's not like us as humans. It doesn't see something and equate it as a particular word. Your sensor and your robot and your computer do not understand words. They understand numbers, okay? So what are the numbers that the sensor's actually computing? It's that hue value."

Remember, because the sensor is discerning the reflected wavelength, the ambient light has an impact on that, and also the curvature of the object, shadows that might be on it. All of that is having an impact on that hue value. But with datalogging, we can actually go through and see what those values are and draw a connection between that and where our robot is.

Let's just go and take a look at that again. You can see now I got blue, cyan. Okay, look how cool that is down here, 38, 39, and 40, the color cyan. Again, you know, there's no cyan here. We don't have a cyan game option here, but that is what your optical sensor, that's the hue value that it's actually reading on there and again, that's really valuable information that you can utilize with your students.

Now, if you wanna take this one step further, the next thing that you can do after this is you can actually take this value and you can graph it. So let's talk about that now, okay? So you see I have this table here, but I'm actually gonna use ChatGPT and the data analysis with ChatGPT. I already have my prompt written in here and I'll put the prompt in the community if you want that also.

Okay, but let me go ahead and put my data in there. Okay. And now I'm gonna go, I'm gonna ask ChatGPT to analyze the data. This is gonna take a second. As you can see here, it's analyzing, but you can see actually the Python code that it's using. It's gonna tell you what's actually going on here as it's going through and analyzing it for you. So it's going through, the data consists of four columns, blah, blah, blah. It's kind of giving you an update on what it's doing here.

Now you don't have to use, it's importing another Python library, you see it right here, you don't obviously have to use ChatGPT to visualize this data for you. But this is a really nice example again, when we talked about data science and data analysis at the very beginning, and there's my graph right there. Well, there's my graph right there.

So robot hue colors observed over time. Here you see at the very beginning. Remember I started my robot here, so it was not detecting the color at the very beginning. You could see that on the graph, right? So there it is at the very beginning now as it just started to see, go onto my first object here. You could see there and then you could see the different colors. Notice the scale is different. So our color wheel, we use zero to 359. This scale is going, that looks like at about 250 or 225 on there. So that's why the scale's a little bit different. You can change the scale when you visualize it, but now you can see the different values and here you can see the colors that actually are not represented with the objects I have.

Just a really, really cool visualization of what is that you're doing with the datalogging. Because I have the distance down here, I have the hue over here. You can use the distance on your field.

These are all different things that you can do to grab more information from your robot and from the sensor, and then programmatically make some very cool decisions with it. That's computational thinking. That's the goal that we're trying to get all of our students to achieve with their coding.

But again, the reason why I love doing this in my classroom was beyond just the cool factor of it, which I think is very cool. You never have to just settle for that answer from the students when they're like, "You know, my sensor doesn't work. My sensor's not working. I'm telling it, my code, my logic is correct. I'm telling it to do something, when it detects the color, it's on that color, it's not doing it, this is frustrating." Instead, you can go a little bit further down and deeper into it and actually take a look at what the sensor is doing.

So, understand what the sensor is doing and then understand how it's applied to the constraints you have in your classroom, the different lighting that you have, the different situations you might be in, and then be able to apply it. Now, obviously, you would not want to do this with a beginner, but abstraction transfer, that's really what it is that we're talking about with computational thinking.

Imagine you had your students go through and they used the sensor and VEXcode VR where you didn't have to worry about ambient light, okay? Now, after they get good at coding that, you want to apply it in a real-world setting. That's the transfer. That's what we're always trying to do in education. That's the computational thinking. Now you want to apply it in a real-world setting, it's going to be a little bit messier. You are able to apply your coding knowledge in a very "clean" environment. But now, can you take your knowledge out of that and transfer it into a little bit of a "messier" situation where now you have to deal with ambient light, you have to deal with where your robot is? Maybe the colors on the objects themselves are a little bit different than what you're used to. Whatever the particular constraints are, this is a wonderful way to be able to apply your knowledge and then be able to investigate what your robot is doing with datalogging to then adjust your code, whether you're using Python or whatever, as needed and as necessary.

And again, that's really what we're looking to do in any domain, an educational subject. Take what you learned and apply it in a new setting. That is transfer. This is a fantastic way to do that with robotics, combining VR with this, and this is a fantastic way to really go under the hood and investigate what it is that your sensor's actually doing. Then use that information to, again, make really good decisions about what your robot is doing programmatically.

So if you have more questions about datalogging, please feel free to ask in the community. There's a great knowledge base article, but we're going to be adding more. Datalogging is function nine, and we're going to be doing a lot more with it in the upcoming weeks and months. So stay tuned for that.

For right now, if you are a member of PD Plus, this gives you the opportunity to talk to us, talk to members of our software team, do a one-on-one session, and ask questions in the community to further your knowledge on datalogging so you can do some really cool experiments with your students. If you really want to dive into data science and you want to talk about potential experiments or projects you can run, let us know. We'd love to have that conversation with you. If you want to go over the code, let us know. We'd love to have that conversation with you.

These are all things that make you a member of PD+. You get access to us to learn these really cool concepts like datalogging and really take your students to the next level.

I hope you enjoyed the Live Session. If you have questions or comments, I'll chat with you in the community. I love datalogging, and hopefully, you got something out of this session that you can apply to your students and take their coding to the next level.

I'll see you in our next live session. We'll be talking about datalogging, but now with VEX IQ. I'll also see you in our VEX Professional Development Plus Community.

Talk soon, 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.