LEGO Mindstorms Class: Lesson 7
Building a Motorized (claw) Attachment:
In the last challenge you created a passive (fixed in place) attachment, and used it to get your robot to pick up and retrieve several objects in its path. You used the motion of the robot to help it pick up the objects. In today's lesson, we are going to build a motorized (claw) attachment, and use it to accomplish a task. We will also learn how to use LEGO Mindstorms "My Blocks" to simplify our programming.
Exercise 1: Build a "Claw-Bot"
Because we need to be able to attach a motorized claw to our robot, we're going to build a whole new robot, with room underneath for a motorized attachment. Follow the steps below to build your robot:
Step 1: Add "hooks" to the brick.
Step 2: Build attachments to the motors, and add the tires.
Step 3: Build a rear crossbar to hold the motors in the right place.
3(d) ← This picture missing pieces from previous picture.
Step 4: Build the front crossbar.
Step 5: Attach the front crossbar to the motors.
Step 6: Build the caster wheel for the rear crossbar.
Step 7: Attach the wheel and some vertical struts to the rear crossbar.
Step 8: Attach the Mindstorm Brick to the frame.
Step 9: Build and attach the claw.
9(b) 9(c) 9(d)
Step 10: Attach the claw underneath the front crossbar, and attach wires to the motors. Remember the "B" and "C" motors drive the wheels, and the "A" motor powers the claw:
That's it! You've created "Claw Bot"!
Exercise 2 - Moving the Claw: Figure out how to get the claw to open and close. Remember, to rotate a single motor, you'll want to use the "Move" block. Can you figure out how to get the robot to drive to an object, grab it with the claw, and roll back to you? Write a program called "grabobject.rbt" to accomplish this. Your instructors will provide an object for the "Claw Bot" to grab.
Exercise 3 - Open the Claw all the Way, no Matter Where it Starts: It can be difficult to open the claw just the right amount to grab something, so we're going write a program that will fully open the claw, no matter how opened or closed it is when it starts out, and then stop Motor "A" just when the claw is fully open. Before we write our program, we're going to attach a bar to the motorized part of the claw, that will stop the claw from opening too wide. Add the piece circled in the picture below to your claw:
Notice that this "stopper" piece will hit the robot if the claw tries to open too far. Now we need to figure out how to get motor "A" to open the claw until the extra piece we added hits the robot, and then stop Motor "A" from running . We'll use the rotation sensor to do this. The trick we will use is to run motor "A", and keep checking the rotation sensor, which tells us how much motor "A" has moved. When the value from the rotation sensor stops changing, that means that motor "A" has stopped turning, because our stopper piece has hit something.
First, create a program called "openclaw.rbt".
Exercise 4 - Put the Program in a "My Block": If there is a program, or part of a program that you may want to re-use, the NXT Environment lets you put it into a special block, called a "My Block". Then, if you want to re-use the code, you don't have to copy all of the steps into your new program, you just have to copy the "My Block". Let's try it.
Figure 1 - The "Icon Builder" Dialog Box Figure 2 - The "My Block Builder" Dialog Box
Now your new block will show up on the "Custom" Block menu that you can reach from the tabs at the bottom of the menu pane on the left side of the NXT Programming environment: . Create a new program (with any name), and click the rightmost tab (the two blue lines) on the menu pane. Click the top icon to select the "Fully Open Claw" that you created and insert it in your program. Write a program that uses this custom "Fully Open Claw" to open the claw, drive to and pick up an item.
If you ever want to edit your custom "My Blocks" you can select the "My Block" in any program you are using, and choose "Edit Selected My Block" from the "Edit" menu. Editing the code in this window will automatically change the "My Block" in any program that uses it. This is a useful tool if you would like to re-use code in multiple programs without having to re-type it each time.