Chapter 4: Using a Simple Clawbot
Lesson 3: Coding the Claw
(upbeat music)
Hello and welcome to the VEX classroom. My name is Lauren, and in this video, we will be coding the claw. In the previous video, we went through our Simple Clawbot and manipulated the opening and closing of the claw using the drive program on the brain and the controller. In this video, I'm going to walk you through how to code the claw using VEXcode IQ to autonomously open and close the claw.
All right, so let's make sure that we have everything we need to get started. First things first, you're going to want to make sure that you have your Simple Clawbot and a charged battery. Secondly, you're going to want to make sure that you have a USB cable and a device that supports VEXcode IQ. Lastly, you're going to want some type of surface and an object to grab. Here, I have a two by three field with walls on two of the sides and a cube. If you don't have these items, you can tape off a very similar space. This is two feet by three feet, and if you do not have a cube, you can use another object of similar size and weight.
Okay, now that we have everything to get started, the first thing I want to show you is that in order for us to code the claw to autonomously open and close, we need to know what the degree measure is going to be for it being opened and closed. This information will be put into VEXcode IQ. First things first, we're going to look at the devices menu on the brain and see what the degree measure is for completely opened and closed. Let's take a look at that.
If you do not have your brain turned on already, go ahead and turn it on. I am going to make the screen a little bit bigger down there for you in the bottom right-hand corner of the screen so that you can see it. Now, let's head over to the devices menu. Go ahead and select devices. I'm going to navigate over to port four, which is the motor that controls the claw. I'm going to select the check mark to highlight that. Now, it's going to show us a bunch of information. I can see right now with the claw completely open, the velocity is obviously nothing because I'm not opening and closing it, but you can see it changes when I do open and close it.
Secondly, we're going to get the position in degrees and also in revolutions, as well as the current and the command. What I want to focus on right now is the position in degrees because that's the information we're going to need to put into VEXcode IQ. Now completely open, I'm at about zero degrees. It's 4.5 degrees right now, but approximately zero degrees, and we can see completely open is about zero or four. Completely closed is about 46, 45. Now, if I wanted to grab a cube, I'd go to zero degrees for it to be completely open or four degrees. Now, let's put the cube in to see what the claw has to close to in order to grab the cube. It looks like we're at about 15 degrees, okay? So, completely open is about zero. Completely closed is between 15 and 20 degrees, okay? So, again, completely open, around zero, three degrees here. In the cube, about 20, and then, completely closed, between 40 and 50 degrees it looks like, okay?
So, we have three different degree measures that we can identify right now. Completely open is about zero degrees. Completely closed around the cube is about 20 degrees, and completely shut is anywhere from 40 to 50 degrees, okay? All right, now that we have that information, we can actually take it and put it into VEXcode IQ. We've seen in previous videos what the device configuration is and why it's important. We need to make sure that we represent that claw motor in VEXcode IQ for us to have the blocks show up that we can use to code it. As we've seen previously, we have this plug icon in the top right. I can add devices manually that way if I wanted to.
Thank you for watching this video on coding the claw with VEXcode IQ. I hope you found it helpful and informative. If you have any questions or need further assistance, please feel free to reach out. Happy coding!
We also have templates. We've seen the drivetrain template before. Let's take a look at the Simple Clawbot template. So, I'll go to file, open examples, templates, and I can see right here the Simple Clawbot with the drivetrain two motor is the template that I want to select. So, I'm gonna select that and it's going to configure everything for me. I'm gonna get rid of this note. You can see now all the blocks that will control the motor are over here on the left-hand side. If I go up to that plug icon, you can see all of my motors there are represented.
All right, so let's take a look at what I want my robot to do. So, I have my cube here. I'm gonna start my robot back here. I want my robot to drive forward with the claw open, close around the cube, and then the robot will drive in reverse in order to go back to the starting position. Okay, so what are we gonna do? We're gonna drive forward, grab the cube, drive back in reverse. Okay, so the cube, the claw will remain open here, close around the cube and bring it backwards.
Okay, so let's take a look at what we will need in VEXcode in order to do that. Well, first things first, I'm gonna wanna go ahead and drive forward. Now, I wanna drive forward. Each of these is approximately 300 millimeters. So, I'm gonna drive forward for 600 millimeters. Now, my claw is already open, so I need to close the claw. Once I get up here, I need to close the claw. Now, how far do I need to close the claw? Well, we know claw open is about zero degrees, claw closed around the cube is approximately 20 degrees. So, I need to close the claw for approximately 20 degrees.
Now, let's take a look at the blocks that we would use in order to do that. The first spin block is very similar to the drive block. This is going to allow that motor to spin, essentially forever, in whatever direction that we choose because there is no specificity around parameters. So, it doesn't say spin for 90 degrees or three revolutions. All it says is spin indefinitely until otherwise we are told not to. The second one is very similar to the drive for block. This is going to spin the claw motor for either forward or reverse, or open or closed, whatever the parameter is set to for a specific measurement, either in degrees or turns, okay? So, this one, what is the difference between the first and the second? The second has specificity, a specific number of degrees or turns that the motor will spin for and then it will stop. The third is gonna be spin to position. This essentially removes the forward or reverse element of that second block. So, this one will get to 90 degrees in whatever the most efficient way possible is, either spinning in the forward motion or spinning in reverse. So, this one will get to that particular position again itself, either choosing forward reverse, whatever is going to be the most efficient. So, that is the difference between all three.
Now, I want to spin the claw motor closed for 90 degrees or whatever degree measure I need to choose. So, I'm gonna use this spin for block. Now, we already said that I need to close it for approximately 20 degrees, which is what we found from the devices screen. And then, I wanna drive and reverse back to the beginning.
All right, now that I have all of that, let's go ahead and download my project. So, I have that plugged in. My brain icon in the top right is green. I'm gonna select download. It's downloading. All right, let's go ahead and test this out. Okay, set my cube up. Remember to start with the claw open, and let's go ahead and run this project.
(machine gears turning)
All right, and it did exactly as we wanted it to do. Drove forward, grabbed the cube and then drove back in reverse. Now, let's see, what would we want to do if I wanted to do something very similar where I started with the claw closed?
Thank you for following along with this demonstration. If you have any questions or need further assistance, please feel free to reach out.
We need to open the claw, drive forward, close the claw, and then drive back in reverse, okay? Let's say that that is what we want to do. Okay, so again, what do we need to do? Very similar to what we just did, except I'm starting with the claw closed. So, I need to open the claw, drive forward, grab the cube, and then go back in reverse, okay?
So, go ahead and pause the video now, and go ahead and add the blocks that you need in your VEXcode IQ project in order to start with the claw closed. You're gonna have to open it, drive forward, grab the cube, and then go in reverse. So, go ahead and pause the video and add the blocks necessary in order to do that challenge.
So, let's take a look at our project. What do we need to add? Well, I have everything that I essentially need right now in order to drive in reverse with the cube in the claw. Okay, so drive forward, grab the cube, and then drive in reverse. But since I am starting with the claw closed, I need to open it. So, I am going to spin the claw motor open for, I'm gonna say 45 degrees, because we saw earlier that completely closed is between 40 and 50 degrees. So, in order for me to open it, I need to undo however many degree measures that was.
Okay, so the three degree measures that we saw were zero degrees for completely open, 20 degrees around a cube, and then between 40 and 50 degrees for completely closed. So, I need to spin it open since it's been spun closed for approximately 45 degrees. I need to spin it open that particular amount as well, okay? So, now, that I have this, it's gonna spin the claw open. It's gonna drive forward. It's going to close around the cube, and then I'm gonna drive back in reverse, okay?
So, let's go ahead and download this project and test it to see how well it works. All right. Okay, now that I have that, let's go ahead and test this. I'm gonna line everything up. I'm gonna start with my claw closed this time. Let's go ahead and test the project.
(machine gears turning)
All right, congratulations, you did it! We started with the claw closed. You successfully opened and closed the claw, and grabbed a cube, and you did all of that autonomously. So, again, congratulations, you did it. You coded the claw using VEXcode IQ to grab and move a cube.
Once again, just recapping everything. We are coding the claw autonomously using VEXcode IQ. We went into the devices screen that allowed us to get the approximate degree measures that we would need in order to open and close the claw, especially around an object, and we gathered all of that information in those measurements, and we used them in VEXcode IQ in order to code our claw to grab a cube and move it to a new location.
I hope that all of this was helpful. I will see you in the next chapter.
(upbeat music)
Hello and welcome to the VEX classroom. My name is Lauren, and in this video, we will be coding the claw. In the previous video, we went through our Simple Clawbot and manipulated the opening and closing of the claw using the drive program on the brain and the controller. In this video, I'm going to walk you through how to code the claw using VEXcode IQ to autonomously open and close the claw.
All right, so let's make sure that we have everything we need to get started. First things first, you're going to want to make sure that you have your Simple Clawbot and a charged battery. Secondly, you're going to want to make sure that you have a USB cable and a device that supports VEXcode IQ. Lastly, you're going to want some type of surface and an object to grab. Here, I have a two by three field with walls on two of the sides and a cube. If you don't have these items, you can tape off a very similar space. This is two feet by three feet, and if you do not have a cube, you can use another object of similar size and weight.
Okay, now that we have everything to get started, the first thing I want to show you is that in order for us to code the claw to autonomously open and close, we need to know what the degree measure is going to be for it being opened and closed. This information will be put into VEXcode IQ. First things first, we're going to look at the devices menu on the brain and see what the degree measure is for completely opened and closed. Let's take a look at that.
If you do not have your brain turned on already, go ahead and turn it on. I am going to make the screen a little bit bigger down there for you in the bottom right-hand corner of the screen so that you can see it. Now, let's head over to the devices menu. Go ahead and select devices. I'm going to navigate over to port four, which is the motor that controls the claw. I'm going to select the check mark to highlight that. Now, it's going to show us a bunch of information. I can see right now with the claw completely open, the velocity is obviously nothing because I'm not opening and closing it, but you can see it changes when I do open and close it.
Secondly, we're going to get the position in degrees and also in revolutions, as well as the current and the command. What I want to focus on right now is the position in degrees because that's the information we're going to need to put into VEXcode IQ. Now completely open, I'm at about zero degrees. It's 4.5 degrees right now, but approximately zero degrees, and we can see completely open is about zero or four. Completely closed is about 46, 45. Now, if I wanted to grab a cube, I'd go to zero degrees for it to be completely open or four degrees. Now, let's put the cube in to see what the claw has to close to in order to grab the cube. It looks like we're at about 15 degrees, okay? So, completely open is about zero. Completely closed is between 15 and 20 degrees, okay? So, again, completely open, around zero, three degrees here. In the cube, about 20, and then, completely closed, between 40 and 50 degrees it looks like, okay?
So, we have three different degree measures that we can identify right now. Completely open is about zero degrees. Completely closed around the cube is about 20 degrees, and completely shut is anywhere from 40 to 50 degrees, okay? All right, now that we have that information, we can actually take it and put it into VEXcode IQ. We've seen in previous videos what the device configuration is and why it's important. We need to make sure that we represent that claw motor in VEXcode IQ for us to have the blocks show up that we can use to code it. As we've seen previously, we have this plug icon in the top right. I can add devices manually that way if I wanted to.
Thank you for watching this video on coding the claw with VEXcode IQ. I hope you found it helpful and informative. If you have any questions or need further assistance, please feel free to reach out. Happy coding!
We also have templates. We've seen the drivetrain template before. Let's take a look at the Simple Clawbot template. So, I'll go to file, open examples, templates, and I can see right here the Simple Clawbot with the drivetrain two motor is the template that I want to select. So, I'm gonna select that and it's going to configure everything for me. I'm gonna get rid of this note. You can see now all the blocks that will control the motor are over here on the left-hand side. If I go up to that plug icon, you can see all of my motors there are represented.
All right, so let's take a look at what I want my robot to do. So, I have my cube here. I'm gonna start my robot back here. I want my robot to drive forward with the claw open, close around the cube, and then the robot will drive in reverse in order to go back to the starting position. Okay, so what are we gonna do? We're gonna drive forward, grab the cube, drive back in reverse. Okay, so the cube, the claw will remain open here, close around the cube and bring it backwards.
Okay, so let's take a look at what we will need in VEXcode in order to do that. Well, first things first, I'm gonna wanna go ahead and drive forward. Now, I wanna drive forward. Each of these is approximately 300 millimeters. So, I'm gonna drive forward for 600 millimeters. Now, my claw is already open, so I need to close the claw. Once I get up here, I need to close the claw. Now, how far do I need to close the claw? Well, we know claw open is about zero degrees, claw closed around the cube is approximately 20 degrees. So, I need to close the claw for approximately 20 degrees.
Now, let's take a look at the blocks that we would use in order to do that. The first spin block is very similar to the drive block. This is going to allow that motor to spin, essentially forever, in whatever direction that we choose because there is no specificity around parameters. So, it doesn't say spin for 90 degrees or three revolutions. All it says is spin indefinitely until otherwise we are told not to. The second one is very similar to the drive for block. This is going to spin the claw motor for either forward or reverse, or open or closed, whatever the parameter is set to for a specific measurement, either in degrees or turns, okay? So, this one, what is the difference between the first and the second? The second has specificity, a specific number of degrees or turns that the motor will spin for and then it will stop. The third is gonna be spin to position. This essentially removes the forward or reverse element of that second block. So, this one will get to 90 degrees in whatever the most efficient way possible is, either spinning in the forward motion or spinning in reverse. So, this one will get to that particular position again itself, either choosing forward reverse, whatever is going to be the most efficient. So, that is the difference between all three.
Now, I want to spin the claw motor closed for 90 degrees or whatever degree measure I need to choose. So, I'm gonna use this spin for block. Now, we already said that I need to close it for approximately 20 degrees, which is what we found from the devices screen. And then, I wanna drive and reverse back to the beginning.
All right, now that I have all of that, let's go ahead and download my project. So, I have that plugged in. My brain icon in the top right is green. I'm gonna select download. It's downloading. All right, let's go ahead and test this out. Okay, set my cube up. Remember to start with the claw open, and let's go ahead and run this project.
(machine gears turning)
All right, and it did exactly as we wanted it to do. Drove forward, grabbed the cube and then drove back in reverse. Now, let's see, what would we want to do if I wanted to do something very similar where I started with the claw closed?
Thank you for following along with this demonstration. If you have any questions or need further assistance, please feel free to reach out.
We need to open the claw, drive forward, close the claw, and then drive back in reverse, okay? Let's say that that is what we want to do. Okay, so again, what do we need to do? Very similar to what we just did, except I'm starting with the claw closed. So, I need to open the claw, drive forward, grab the cube, and then go back in reverse, okay?
So, go ahead and pause the video now, and go ahead and add the blocks that you need in your VEXcode IQ project in order to start with the claw closed. You're gonna have to open it, drive forward, grab the cube, and then go in reverse. So, go ahead and pause the video and add the blocks necessary in order to do that challenge.
So, let's take a look at our project. What do we need to add? Well, I have everything that I essentially need right now in order to drive in reverse with the cube in the claw. Okay, so drive forward, grab the cube, and then drive in reverse. But since I am starting with the claw closed, I need to open it. So, I am going to spin the claw motor open for, I'm gonna say 45 degrees, because we saw earlier that completely closed is between 40 and 50 degrees. So, in order for me to open it, I need to undo however many degree measures that was.
Okay, so the three degree measures that we saw were zero degrees for completely open, 20 degrees around a cube, and then between 40 and 50 degrees for completely closed. So, I need to spin it open since it's been spun closed for approximately 45 degrees. I need to spin it open that particular amount as well, okay? So, now, that I have this, it's gonna spin the claw open. It's gonna drive forward. It's going to close around the cube, and then I'm gonna drive back in reverse, okay?
So, let's go ahead and download this project and test it to see how well it works. All right. Okay, now that I have that, let's go ahead and test this. I'm gonna line everything up. I'm gonna start with my claw closed this time. Let's go ahead and test the project.
(machine gears turning)
All right, congratulations, you did it! We started with the claw closed. You successfully opened and closed the claw, and grabbed a cube, and you did all of that autonomously. So, again, congratulations, you did it. You coded the claw using VEXcode IQ to grab and move a cube.
Once again, just recapping everything. We are coding the claw autonomously using VEXcode IQ. We went into the devices screen that allowed us to get the approximate degree measures that we would need in order to open and close the claw, especially around an object, and we gathered all of that information in those measurements, and we used them in VEXcode IQ in order to code our claw to grab a cube and move it to a new location.
I hope that all of this was helpful. I will see you in the next chapter.
(upbeat music)
Learning Objectives
Learning Objectives Section
- Identify that the Devices screen can be used to view information about the motor including the position of the motor in degrees
- Identify the steps to open the Simple Clawbot (Drivetrain 2-motor) template in VEXcode IQ
- Identify how to use blocks in VEXcode IQ to spin the claw motor open and close for a set number of degrees or rotations
- Identify how to use information about the claw motor from the Devices screen in a VEXcode IQ project
- Use Drivetrain and motor commands to code a robot to move a VEX IQ Cube from one side of the Field to another
Lesson Materials
Materials Needed Section
- A VEX IQ (2nd generation) Kit A completed Simple Clawbot
- A charged Battery
- 6 VEX IQ Field Tiles
- 6 VEX IQ Field Walls
- An IQ Cube (color does not matter)
- Access to VEXcode IQ
Summary
Summary Section
This is the third video of the Introduction to VEX IQ (2nd gen) Training Course - Chapter 4. If you have not yet watched the second video, go back and watch Lesson 2: Controlling the Claw. In Lesson 3, you will learn how to open and close the claw autonomously using VEXcode IQ.
View the following resource related to the concepts covered in the video as you continue your learning.