[ Pobierz całość w formacie PDF ]
.The grabber arm is operated by a single motor.The other motor powers thedrivetrain, which moves the robot forward or spins it in place.Figure 5-1 shows a picture of this remarkable robot.Figure 5-1.Minerva, a mechanical masterpieceWhen you run Minerva's program, she drives straight forward.When the light sensor (mounted on the end of the grabber arm)sees something dark, Minerva stops driving.She uses the arm to try to pick up whatever the light sensor saw.83Then she turns around and drives back to her starting point.She puts down whatever she's carrying, turns around and is readyto start again.Building InstructionsIf there's one lesson to be learned from Minerva, it is that mechanical design is hard.I had to build this robot five times to get itright.And I don't mean I moved a few pieces around I actually disassembled and rebuilt the robot that many times.Thedrivetrain alone took four tries before I got it right."Directional Transmission and DrivetrainThe long gray piece in Step 1 swivels freely on the shaft." Minerva uses almost all of the gears that come with RIS 1.Unfortunately, RIS 1.5 comes with fewer gears (five 12t gearsinstead of eight).To get the extra gears you'll need for Minerva, you can order the #5229 Gears & Differentials parts pack fromthe LEGO Shop At Home Service, (800) 453 4652.Cost is $4.50 including shipping.84The 8u shaft in Step 2 is loose and may fall out.It will be anchored in the next step.The 6u beam, like the long gray piece fromStep 1, swivels freely on its shaft.85Make sure the bump on the long pin is up against the 4u beam.Before you put all of Step 7 together, make sure the swiveling parts from Steps 1 and 2 are pointing up, as shown.868788Step 11 is tricky.You'll need to slide the 8u shaft into the structure, adding bushings and gears as you go.The swiveling piecesfrom Steps 1 and 2 are now anchored.89Step 14 is similar to Step 11; take a deep breath and go slowly.90Grabber ArmIn Step 17, the half-bushings go between the center block and the cams (pear-shaped pieces).9192Make sure that the two sides are at the same angle.They should mirror each other.9394Structural Support95Idler Wheel9697Drive MotorWhile you're putting the motor in, hold on to the worm gear so it doesn't slip off.98Grabber Arm Motor99100RCXAttach the RCX on both sides as shown.101WiringFirst, attach the left motor, which powers the arm, to output A.Then use a wire brick to attach the right motor (the drive motor)to output C.102Attach the light sensor to the front of the arm.The wire attaches to Minerva's side as shown.Next, use a wire brick to attach the touch sensor to the light sensor wire.Then use a longer wire brick to attach both wires toinput 3.103ProgrammingMinerva's basic program is straightforward:find something to pick upbring it back to the starting pointThe program assumes that the objects to pick up will be dark and that the surface Minerva is driving on is light.To return tothe starting point, Minerva measures how long it has to drive forward to pick something up.Then it turns around and drivesback for the same amount of time.Here's a slightly exploded version of Minerva's program:drive forward until the light sensor sees something darkpick it up with the grabberturn arounddrive back to the starting pointdrop whatever's in the grabberI've written Minerva's program in NQC (see Chapter 4, Not Quite C).You could create a program in RCX Code (theenvironment that comes with RIS), but you wouldn't be able to implement some key features.In particular, Minerva's ability todrive back just as far as she drove forward is crucial.There's no way to do this in RCX Code.Minerva's program also doessome sensor calibration that would also be impossible in RCX Code.Here's the whole program:#define TURNAROUND_TIME 425int i;task main() {// Arm limit sensor and grabber light sensor.SetSensor(SENSOR_3, SENSOR_LIGHT);SetPower(OUT_A + OUT_C, OUT_FULL);calibrate() ;i = 0;while (i Module menu itemto create a new code module.In the window that appears, type the following to create a new subroutine:Sub HelloSpiritTo call functions in Spirit.ocx, you need to reference the control by name.The dummy form you created isDummySpiritForm.It contains a Spirit.ocx control called Spiritl.The full name of the control, then, isDummySpiritForm.Spirit1.Fill out the body of the HelloSpirit subroutine as follows:Sub HelloSpirit ()DummySpiritForm.Spiritl.InitCommDummySpiritForm.Spiritl.PlaySystemSound 0DummySpiritForm.Spiritl.CloseCommEnd SubTo run this simple subroutine, make sure your RCX is on.Then click on the play button in the toolbar.If all goes well, youshould hear your RCX play a simple beep.It's little cumbersome to always refer to the full name of the Spirit.ocx control.A simpler syntax, using With, looks like this:Sub HelloSpiritII ()With DummySpiritForm.Spirit1.InitComm.PlaySystemSound 0.CloseCommEnd WithEnd Sub163Immediate and Delayed GratificationThe functions in Spirit.ocx can be immediate, delayed, or both.An immediate function executes as soon as you call it.Delayedfunctions can be placed inside a program and executed later.For example, Onis both an immediate and delayed function.Youcan call it to turn on some outputs immediately, or you can call it to add it to a program that will be executed later.The following subroutine plays a little song using the PlayTone function in its immediate mode:Sub Charge()With DummySpiritForm.Spirit1.InitComm.PlayTone 392, 10.PlayTone 523, 10.PlayTone 659, 10.PlayTone 784, 20.PlayTone 659, 10.PlayTone 784, 20.CloseCommEnd WithEnd SubInstead of executing things on the RCX immediately, you can store them for later.The following subroutine redefines Program5 on the RCX to play the same song:Sub ChargeProgram()With DummySpiritForm.Spirit1.InitComm.SelectPrgm 4
[ Pobierz całość w formacie PDF ]