Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 40 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
40
Dung lượng
1,15 MB
Nội dung
174_LEGO_22 10/29/01 4:40 PM Page 440 Drawing and Writing Solutions in this chapter: ■ Creating a Logo Turtle ■ Creating a Tape Writer ■ Further Suggestions Chapter 23 441 174_LEGO_23 10/29/01 4:43 PM Page 441 442 Chapter 23 • Drawing and Writing Introduction Can a MINDSTORMS robot be made to draw or write? Sure. Believe it or not, that’s not even a very difficult thing to implement. In the following pages, we will show you two projects, the first mainly meant for drawing and the second for writing. Both of them require some additional parts, but both have wide mar- gins for modifications and allow for less demanding variants. Creating a Logo Turtle Many of you may already know that Logo is a programming language specifically targeted to education. Born in the late 60s at the Massachusetts Institute of Technology (MIT), Logo is derived from Lisp (with a lot fewer parentheses!) and features interactivity, modularity, and extensibility. More than a programming lan- guage, Logo is a learning tool which has gone through a number of changes and improvements over the years. The most known characteristic creation of Logo is the Tur t le, a symbolic turtle that moves across the computer screen according to the instruction it receives.With simple instructions like forward 10 the turtle moves straight ten units, and with right 90 it turns clockwise 90 degrees.The statements penup and pendown specify whether the turtle leaves a track behind it, thus producing drawings or rather just moving to a different location. Obviously the language includes many other commands, but these are enough to understand the princi- ples of the Turtle Graphics that made Logo so famous. What many people don’t know is that in its first version, the Logo program controlled a small robot that actually drew lines on the floor. In subsequent releases, the turtle became just a virtual animal on the screen. Our interest here, however, is in replicating its first robotic version. NOTE Dr. Seymour Papert was one of the early promoters of Logo, and designed the original Turtle. Under his guidance, the Epistemology and Learning Group at MIT devised the first programmable brick, whose con- cepts led to the development of the LEGO MINDSTORMS line. www.syngress.com 174_LEGO_23 10/29/01 4:43 PM Page 442 www.syngress.com Building the Turtle The idea is quite simple: Build a small robotic platform that’s able to go forward and backward, turn in place, and lower and raise a pen. Despite this apparent sim- plicity, if you want a turtle that works as expected, the task has many stringent requirements that must be adhered to. For instance: 1. The robot must go absolutely straight. 2. The pen must be exactly in the pivoting point of the robot, because it must stay in the same place on the floor while the robot turns (other- wise it would trace a curve). 3. You need a tracking system to measure both traveled distances and angles. If you remember the driving architectures described in Chapter 8, you already know the solution to the first point: Use a dual differential drive.The simple differential drive is suitable for this project only if you apply an active control to the wheels to be sure they travel exactly the same distance, while the synchro drive would work as well but at the price of greater complexity and not so evident change in orientation during action.Another advantage of the dual differential drive is that it requires a single encoder to comply with point 3: when the robot goes straight it measures the covered distance, when turning it measures the angle. OK, so we have requirements 1 and 3 covered, but there’s still the matter of the pen being the center of rotation, which is at the midpoint of the imaginary line that connects the wheels. Conceptually it sounds easy, but you have to build your robot with this point in mind. The original turtle—a differential drive—featured a transparent plastic dome to cover the gears.We provided our turtle with a triangular shape (Figure 23.1), because we wanted to mimic the screen turtle of some widespread Logo systems. Anyway, those V-shaped beams are definitely not necessary and you can shape your own turtle according to your wishes. Our differential drive does not use a caster wheel, because they tend to affect the direction of the robot slightly when resuming straight motion after a turn. With casters, the straight lines would have a short wiggly segment, so we pre- ferred to use a simple tile as the third supporting point.To keep the friction on the floor to a minimum, we placed the RCX suspended behind the drive wheels, like a sort of counterweight, bringing the COG of the robot very close to the drive axles and thus most of the weight upon the drive wheels. Drawing and Writing • Chapter 23 443 174_LEGO_23 10/29/01 4:43 PM Page 443 444 Chapter 23 • Drawing and Writing There’s another advantage to having the RCX pointing upwards:This maxi- mizes the possibilities of communications between the tower and the robot, using the ceiling of the room as a mirror for the infrared (IR) rays (see the sidebar, “What’s Infrared Communication?”). Let’s start exploring the dual differential drive chassis that drives the robot (Figure 23.2).The gearing is more compact than those shown in Chapter 8, but it works exactly the same way: One motor makes the differential gears and the wheels rotate in sync, while the other rotates them in the opposite direction.You can notice the rotation sensor coupled to the right wheel.The dark gray 16t gear right in the middle of the photo is an idler gear which connects the other two 16t gears; its center hole is not cross-shaped and thus it doesn’t couple with the long joined axle that crosses the base of the robot. www.syngress.com Figure 23.1 The Logo Turtle 174_LEGO_23 10/29/01 4:43 PM Page 444 Drawing and Writing • Chapter 23 445 www.syngress.com What’s Infrared Communication? Infrared (IR) light is of the same nature as visible light, but its frequency is below that perceivable by the human eye. Provided the intensity is high enough, we usually feel IR radiation as heat. For most properties, IR light is really identical to visible light: It gets reflected, refracted, diffused, or shielded by different kinds of bodies. When you want your robot to stay in communication with the tower, they must “see” each other all the time. This is not always easy when the robot moves and changes orientation, but for indoor situations, you can take advantage of the ceiling, as described, to reflect the IR beams downward. In most cases, placing the RCX with the tower facing upwards works very well and solves the problem. Bricks & Chips… Figure 23.2 The Turtle Dual Differential Drive Platform (Top View) 174_LEGO_23 10/29/01 4:43 PM Page 445 446 Chapter 23 • Drawing and Writing Looking at the bottom, you can see the front skid plate. (Figure 23.3). Using a technique described in Chapter 11, we placed a rubber band to make the mechanism bi-stable, so that when the pen is down it tends to stay down, and vice versa (Figure 23.4). The pen is a non-LEGO part, a common marker with its body wrapped in adhesive tape so as to make it fit tightly into the 2 x 2 studs squared hole reserved for the purpose. It stays there with nothing but friction. The pen control mechanism is a swinging assembly operated by a third motor (Figure 23.5). Now the turtle is ready. Place a large piece of paper on the floor, uncap the pen and adjust its height so it touches the paper gently when in it is in the down position (Figure 23.6).We strongly discourage you from writing directly on the floor.We’re sure somebody won’t like it! www.syngress.com Figure 23.3 The Turtle Dual Differential Drive Platform (Bottom View) 174_LEGO_23 10/29/01 4:43 PM Page 446 Drawing and Writing • Chapter 23 447 www.syngress.com Figure 23.4 Side View of the Turtle Pen Mechanism Figure 23.5 Turtle Top View 174_LEGO_23 10/29/01 4:43 PM Page 447 448 Chapter 23 • Drawing and Writing Programming the Turtle The first task in programming the Turtle is to create the primitives that control the basic actions. Let’s start with the easiest ones: the penup and pendown com- mands.A short impulse to the pen motor does the trick—nothing more is required. If you want to avoid lowering the pen again when it’s already down, in case of repeated pendown commands, you can monitor the status with a vari- able. In the NQC example that follows, we defined two constants UP and DOWN to make the code clearer; in fact, the instruction pen=DOWN is much more self-explanatory than its equivalent pen=0. #define DOWN 0 #define UP 1 #define PEN_TIME 15 int pen; sub pendown() { if (pen==UP) www.syngress.com Figure 23.6 Side View of the Turtle Ready for Operation 174_LEGO_23 10/29/01 4:43 PM Page 448 Drawing and Writing • Chapter 23 449 { OnFwd(OUT_B); Wait(PEN_TIME); Off(OUT_B); pen=DOWN; } } The constant PEN_TIME will be typically something like 15 or 20 hun- dredths of a second.The penup routine is obviously identical except for the direction of the motor and the values the pen variable is tested and assigned. The forward and back commands, meanwhile, are not very difficult to implement, but require that you dig into the physical properties of your robot. You must discover what distance it covers for any increment of the rotation sensor.The model is the same as that explained in Chapter 13 when we discussed dead reckoning, but here it is simplified by the fact that the wheels always travel at the same speed.The equation was: F = (D x π) / (G x R) where D is the diameter of the wheel, R the resolution of the rotation sensor, and G the gear ratio between the sensor and the wheel.We used a wheel with a nominal diameter of 5 cm.The resolution of the rotation sensor is 16 counts per turn, and is geared 1:3 with the wheel—thus our formula becomes: F = 5 x 3.1416 / (3 x 16) ≈ 0.327 cm This means that every time the sensor counts one unit, the wheel covers about 0.327 cm.What actually interests you is how many ticks you should count to cover a required distance, so the formula becomes: Count = Distance / F If you have to manage the calculation with whole numbers, be sure to express the formula in your code in order to keep maximum precision. Dividing for 0.327 is like multiplying by 3.06, from which the following code: count = (dist * 306) / 100; This is the theory.The actual robot will probably require some in-the-field tuning, because the distance covered by the wheels is affected by other factors: The weight compresses the tires and reduces their diameter.There might be some www.syngress.com 174_LEGO_23 10/29/01 4:43 PM Page 449 [...]... 23.15 Close-Up of the Pen Figure 23.16 The Writer’s Writing Top Taken Apart www.syngress.com 174 _LEGO_ 23 10/29/01 4:44 PM Page 461 Drawing and Writing • Chapter 23 Figure 23.17 Writer Front View Bricks & Chips… Washing LEGO Parts LEGO bricks are, generally speaking, not very difficult to clean You can remove small ink spots using a cotton ball soaked in some alcohol For large-scale cleaning, hand-wash your... Flight s Designing the Simulator Project s Building the Hardware s Programming the Simulator s Operating the Simulator s Downsizing the Project s Upsizing the Project 467 174 _LEGO_ 24 468 10/29/01 5:15 PM Page 468 Chapter 24 • Simulating Flight Introduction LEGO robots cannot fly.This is a fact you have to accept—there’s no way to build any kind of pure -LEGO self-powered flying machine.The project described... a glimpse at how robots can learn by example, too; a feature used in many real life robots, including industrial robots In a case where you want your robot to perform handwriting, you can guide the movements of the robotic arm to copy the shape of any written character; the robot “remembers” your movements, and then is able to replicate them and write by itself www.syngress.com 174 _LEGO_ 24 10/29/01... simpler, even the Tape Writer showed some construction tips It is a Cartesian system not too different from those used in the robots www.syngress.com 465 174 _LEGO_ 23 466 10/29/01 4:44 PM Page 466 Chapter 23 • Drawing and Writing of previous chapters (the Maze Solver and the Tic-Tac-Toe machine), but it does demonstrate once more that by reevaluating the terms of a problem, you can find an easier solution... end up washing a few LEGO parts! The top is completely covered with tiles (Figure 23.16).The irregular surface covered with studs wouldn’t work In case you don’t have tiles, or not enough of them, cover the plates with a smooth, thin support, like a glossy cardboard, an aluminum or plastic sheet or anything else similar that comes to mind.You can also build a top out of standard LEGO bricks laid on... tiles The writing surface is an independent part linked to the main body through short rubber bands (Figure 23.17).Those bands pull the surface up against the pen and against the wheels of the feeding mechanism www.syngress.com 174 _LEGO_ 23 10/29/01 4:44 PM Page 459 Drawing and Writing • Chapter 23 Figure 23.14 The Writer’s Pen Assembly www.syngress.com 459 174 _LEGO_ 23 460 10/29/01 4:44 PM Page 460 Chapter... In this chapter, we make an exception—we are going to recommend a www.syngress.com 453 174 _LEGO_ 23 454 10/29/01 4:43 PM Page 454 Chapter 23 • Drawing and Writing particular language, because we feel that the Logo Turtle project would benefit from a lot of interactivity A product specifically designed to marry LEGO to Logo does exist, it’s the DACTA Control Lab Learning Environment But it’s been designed... your best choice for an interactive system, but this particular case is appropriate for the simple standard messaging scheme, too, being that you can send any single-bit ASCII character in a message What to Write We had the idea of making this robot an Automatic Haiku Writer, but the truth is that you can make it write whatever you want In the last part of the chapter, we will give you some hints about... form is a three-line verse where each line is composed respectively of five, seven, and five syllables It usually contains a reference (even indirectly) to time, and is broken into two parts, like an introduction and a theme, or an action and its consequence Here’s our own example of a haiku contemplating the theme of this book (we ask your forgiveness in advance!): www.syngress.com 174 _LEGO_ 23 10/29/01... challenging part of this project is the storing of the data collected during the learning process.You have basically two options: using a language that allows large memory structures like arrays (legOS, leJOS, pbForth), or doing the dirty work on the PC, leaving all the “intelligence” and data there and using the RCX as merely an executor Summary In this chapter, we explored some techniques described in Part . programmable brick, whose con- cepts led to the development of the LEGO MINDSTORMS line. www.syngress.com 174 _LEGO_ 23 10/29/01 4:43 PM Page 442 www.syngress.com Building the Turtle The idea. placed a rubber band to make the mechanism bi-stable, so that when the pen is down it tends to stay down, and vice versa (Figure 23.4). The pen is a non -LEGO part, a common marker with its body wrapped. diameter close to that of the LEGO flex tubing.This simplified our lives a lot (Figure 23.15). Make sure you don’t damage the refill, otherwise you’ll end up washing a few LEGO parts! The top is completely