Rich's Hints & Kinks

© 1996-2003 by Dr. Richard F. Drushel

version 6.7   21 August 2003

ABOUT Rich's Hints & Kinks

Rich's Hints & Kinks is a collection of useful information gleaned from many years of experience in running Autonomous Robotics at CWRU (LEGO 375/475 and its predecessor, LEGO 479). Rich's Hints & Kinks is not intended to replace student experimentation or stifle student creativity; rather, it is a helpful guide to some of the known pitfalls that have needlessly ambushed students in the past. Your mileage, of course, may vary.

Rich's Hints & Kinks is an evolving document. Perhaps you will discover some novel bit of wisdom which will be enshrined in these hallowed pages. Keep your eyes open!

Batteries Digital Camera Usage Light Sensors
Bend Sensors Egg Hunt Robot Testing Motor Current Sensors
Breakbeam Sensors Egg Hunt Team Strategies Push-Button Switches
Computer Boards Group Structure and Dynamics "Secret" Strategies
Computer Etiquette Incandescent Lamps and LEDs Sensor Fundamentals
Control Software I Interactive C (IC) Servo Motors
Control Software II Laboratory Etiquette Switch Sensors
DC Motors and Geartrains LEGO Constructions Warning About Hot-Swapping of Components
Design Notebooks LEGO Kits Warning about Power Failure and main()

BATTERIES

The single biggest problem with batteries results when people forget to turn the computer boards OFF when they're done with them, and they go dead. This wastes batteries and causes headaches for the staff because there aren't always fully-charged extras lying around to hand out. Whenever possible, use the bench power supply instead of the battery pack. There's enough capacitance on the computer board to keep the static RAM powered when switching between batteries and the bench supply, so you don't have to worry about losing any program stored in memory during the switch. However, don't leave the bench power supply plugged in when not in use; being a linear power supply, it draws current even with no load, and can overheat.

Another sure-fire way to drain the computer batteries quickly is to try to run motors without the motor battery pack plugged in (or with the 10 A fuse in the motor battery pack blown). The computer batteries can supply 100 mA maximum, and the motors will draw 1 A each (3 A or more when stalled). Even if you're not using the motors, it's a good idea to keep the motor battery pack plugged in when running off of the computer batteries-the motor batteries can supply some of the current, sparing the computer batteries.

If motors don't work but the motor driver chip status LEDs turn on correctly, the 10 A fuse is probably blown. Use a voltmeter to make sure you're getting +6 V or more at the connector (remember, the center of the plug is ground).

When motor or logic batteries become drained, give them to the staff for recharging. A freshly-charged motor battery pack will read about +7.0 V when warm right off of the charger, about +6.45 V after it cools to room temperature, and about +5.5 V when discharged to the point that it is unable to power a typical LEGO robot drive train. A freshly-charged computer battery pack is about +6.0 V, and about +5.5 V when too weak to power the board.

If you should happen to recharge your own motor batteries, never use the FAST setting, only the SLOW, and let the batteries charge overnight. Never leave the batteries on FAST charge overnight! The batteries will overheat and possibly rupture, spewing sulfuric acid all over. (This actually happened once; someone mistakenly thought the charger was on SLOW. Fortunately, no other equipment was harmed.)

Batteries are a limited resource which must be utilized with care. Don't waste them. You cannot replace them at the first sign of performance degradation. You will have to design your robots to function adequately over a wide range of battery voltages. A friction-free geartrain with adequate gear reduction will drain the motor batteries less than a binding geartrain with more speed than power. Also be sure to keep incandescent lamps turned off when not in active use.

BEND SENSORS

The bend sensors are potentially very useful to measure how close you are to another object (such as a wall or another robot). They are relatively fragile and should not be used as naked "whiskers", or in other situations where they are required to withstand large forces. Moreover, they are only sensitive to bending which occurs along the entire length of the sensor--a small overall bend and a sharp bend at only one point will give the same values. Consequently, bend sensors should always be protectively encased in some kind of LEGO structural element which bears the brunt of impacts, and which causes the sensor to bend uniformly along its length.

BREAKBEAM SENSORS

The breakbeam sensors are just an IR LED/phototransistor pair encased in a slotted plastic housing. When something gets into the slot, it breaks the IR beam and the signal from the phototransistor changes. They're used in floppy disk drives to sense disk presence, write-protect notches, etc. You can use them as motion limit detectors by having part of your mechanism move into the slot when it's in the correct position. This is especially useful for emulating a servo motor: a shaft rotates until a cam breaks the beam, at which point the motor is turned off.

The most common attempted use of the monolithic breakbeam sensors, however, is as a wheel stall sensor. Positioned over a non-drive pulley wheel, the sensor will send alternating on/off pulses as the spokes of the wheel pass through the slot. If the robot has stalled (i.e., the robot platform isn't moving; the drive wheels may or may not still be turning), the sensor will be constantly either on or off. Thus, changing signal means movement, constant signal means the robot is stuck.

While simple in principle, breakbeam stall sensors generally have been major headaches in practice. The geometry of the sensor mount has to be just right, and the software has to be very robust. I've seen teams invest tens of hours into stall sensors without success, after half a semester, when their time would have been better spent on nest detection or egg discrimination. Think very carefully before you embark on a motion control strategy which requires a breakbeam stall sensor.

A common oversight in the use of breakbeam sensors is that the emitter side has to be turned on before the value returned by the detector side has any meaning. Make sure that you have issued the appropriate led_out0(1) or led_out1(1) command to turn on the IR LED before concluding that the sensor is broken. This caveat also applies to wide-area breakbeams constructed with the discrete IR LEDs and IR phototransistors.

The breakbeam sensors are particularly sensitive to electromagnetic interference generated by both DC and servo motors. Both sensors and the sensor wires must be kept at least 6.0 cm away from any motors. Rotating motors generate pulses which cause the breakbeam to register inputs even if nothing is repeatedly breaking the beam, wreaking havoc with stall detection. Aluminum foil shielding may also be used for added protection to the lead wires, but no effective shielding has yet been found for the breakbeam sensor itself. Keep breakbeam sensors away from motors!

COMPUTER BOARDS

The computer boards often flake out, for a variety of reasons. Since the boards cost $300 each and we've drummed it into you that "you break it, you bought it", this inevitably inspires panic. Fortunately, every case so far has eventually been resolved successfully, without the need to scrap the board. Here are some common conditions:

COMPUTER ETIQUETTE

The lab computers and printer may not be the current top-of-the-line, but they are perfectly adequate for all course requirements. Fortunately, this tends to discourage people from installing games or other unauthorized software, or wasting time web-surfing or chatting on IRC :-)

CONTROL SOFTWARE I

Keeping your code modular is helpful, but being anal about structured programming is not. Remember, the most elegantly-designed and -written code is useless if it doesn't work. Similarly, code which does what it's supposed to can be as ugly as it wants to be. Do whatever works for you; this isn't ENGR 131.

This being said, here are some practical hints with proven success. Students with little programming experience are advised to take these "hints" as "well-nigh-obligatory", but even programming gurus can benefit from them.

CONTROL SOFTWARE II

DC MOTORS AND GEARTRAINS

The most important mechanical part of your robot is its drive train. It's the very first thing you have to build. Its controlling software is the very first thing you have to write and debug. Everything else is built around it. If it breaks, or if you get it wrong and have to change it late in the game, you'll have to tear your robot completely apart in order to get at it. Drive motor and geartrain problems are responsible for more robot performance failures than any other cause. It is disheartening to see a robot, with otherwise clever design and control software, sit twitching helplessly because its motors have popped loose, or creeping with screeches because high friction is grinding its gears into grey dust-- especially with the world watching at the Egg Hunt.

Here are some important design considerations:

As supplied, there are 4 bi-directional motor ports (0-3) on the main computer board, plus 4 additional uni-directional motor ports (4-5, in pairs of two, left and right) on the expansion board. A neat, non-destructive hack has been devised to convert the pairs of uni-directional ports into single bi-directional ports: Plug the 3-pin motor across the back 2 pins of the uni-directional ports in the pair. Then you can use motor(4,speed) and motor(5,speed) for -100 <= speed <= 100 to get bi-directional mode, just like motor ports 0-3.

DC motors emit electromagnetic interference which can be picked up as pulses by analog sensors, causing false sensor inputs. Keep sensors and sensor wires away from the motor casings. Aluminum foil may or may not work for shielding.

Another common cause of DC motor misbehavior is the piggybacked motor driver chips becoming unseated from their sockets. A check for this condition should be a standard part of motor debugging before you call for assistance from the instructor. Gently push a chip back in if it has worked loose.

Excessive current draw (due to poor geartrain design), in addition to causing the motor driver chips to overheat and enter emergency thermal shutdown, will blow the fuse link connecting the logic and motor battery supply busses. When this happens, the motor controlpulses (which are powered by the logic batteries) and the motor outputs no longer have the same electrical ground, so behavior of the motor driver chips becomes unpredictable. A command such as motor(0,100) might actually end up working like motor(0,50) or even motor(1,-25) depending upon other electrical loads on the computer board; the ground potential will float with load. The direction LEDs may flicker and both directions be lit at the same time. If the fuse link is blown, the servo motor will also be jittery and unpredictable (see SERVO MOTORS below). Your computer board must be repaired by the instructor, and you must redesign your geartrain to eliminate the excessive load.

DESIGN NOTEBOOKS

The required Design Notebooks are not mere busywork. They don't necessarily have to be pretty (neatness is highly desirable, though; if the instructors can't read it, they can't grade it), but they should be a complete record of everything you've done throughout the semester. Design ideas, experiments, sketches of prototypes, sensor calibrations, algorithms, behavior diagrams-- everything should be documented, and in a way that someone else could figure out what you'd done just by what was in the Notebook. Even though you may not have had a formal course in Engineering Drawing or Drafting, as future engineers and scientists, you are expected to be able to make clear sketches that are neatly and informatively labelled. Unless you have the necessary experience, don't waste your time trying for brownie points with laser printer pictures from AutoCAD or Adobe Illustrator.

The Design Notebooks are also supposed to be working documents, not something thrown together post hoc for the express purpose of having something to hand in at the end of the semester. Make entries as you go, and summarize your progress at the end of every class. Remember, your course grade does not depend in any way upon the performance of your robot in the Egg Hunt. Your Design Notebook is an important basis for the grade you receive in LEGO 375/475.

All illustrations (drawings or photographs) and graphs in your design notebook must be labelled. There must be appropriate discussion text accompanying each figure. A bunch of unlabelled, badly-focussed digital camera photos and garish Excel plots (with illogical axis tick spacing and huge fonts) is not a substitute for a design notebook, and will be graded accordingly. Digital graphics can be a convenience, but over-use comes at the expense of content. The instructors will not be fooled by webpage-style glitz.

It is also very bad form for one member of your group to spend an hour of class time shooting pictures and then print out 3 sets for each of you to stick into your design notebook. The person who took the pictures knows what they are supposed to show, but it's very likely that the rest of you won't, and this will be reflected in the quality of the labelling and discussion.

The Notebook itself should be 8.5 x 11 inch format. If you are keeping a traditional handwritten notebook, the standard graph-paper-paged chemlab-style notebook is by far the best. (Don't use carbon pages, though.) Spiral-bound composition notebooks (college-ruled pages) are not as sturdy for heavy use, but are still acceptable. If you are keeping a typewritten or "electronic" notebook, use a 3-ring binder and hole punch to organize printed pages. Pocket folders are undesirable because it's too easy to lose pages and get them out of order; also, the pockets aren't big enough for the number of papers you'll have by the end of the semester. Historically, students who have kept loose-leaf design notebooks have tended to fall behind in them quicker and have poorer information content than students who have kept traditional bound laboratory-style notebooks; so beware!

Design Notebooks will be returned to you at the end of the semester (after we've had a chance to read them carefully). During the course of the semester, your Design Notebooks will be periodically examined to insure that they're actually being kept up; those whose Notebooks are in arrears will be cajoled, then warned, and finally threatened with bad grades if they don't shape up :-) You should be proud of your Design Notebook, because by semester's end it will be a testament to lots of hard but hopefully satisfying work.

DIGITAL CAMERA USAGE

The lab's digital camera can simplify the task of documenting your mechanical designs, if used properly. Photos should be in focus, of suitable size to show what you're trying to show, and cropped of extraneous background. In addition, once firmly taped/glued/stapled into your design notebook, they should be suitably labelled. Scientific and engineering photos serve a different purpose than snapshots you take on vacation--the object is to convey mechanical design information clearly and concisely. Uncritical tourist-style photos are not an asset to your design notebook.

The digital camera currently in use in the lab has a number of limitations. It can hold only 90-odd photos maximum, and these must be transferred to a computer using a USB-based external flash memory card reader. Only half the computers in the lab currently have USB ports, so if you don't have USB at your workstation, you'll have to use the staff computer and then copy the files over the network back to your workstation for editing and printing.

These limitations conspire to make the digital camera a scarce resource in the lab, one that must be shared fairly with everyone. Don't spend too much class time waiting around for the digital camera. Even if you don't consider yourself a competent draftsman, you will find that, for most illustration purposes, clear hand sketches with good labelling are perfectly adequate to document most mechanical designs. Remember, the object of the illustrations is to convey information, not to be eye candy. If you want to do an extensive photo shoot, consider coming to an extra lab session, at which there will be far less demand for the camera.

To take photos, take off the lens cap and turn on the camera. After a brief warm-up, the lens will extend and the LCD status display on the top will appear. The back of the camera has a mode selector ring; turn this to CAPTURE. Look through the viewfinder and press the shutter. After a brief auto-focus pause, the camera will flash, and a preview of the photo will appear on the color LCD screen on the back. You'll also get a prompt to press a button under the color LCD screen to delete the photo if you don't like it. To save battery life, if you press the shutter only partway down, it will blank the color LCD screen; that screen takes a lot of power. The estimated remaining photo capacity appears on the top LCD status display; it will say FULL when you're at the limit. Note that a green LED next to the viewfinder will blink while the flash is recharging. As the batteries drain, it will take longer and longer to recharge the flash.

To review photos in the camera, turn the mode selector ring to REVIEW, and use the 4-way arrow disk to move around. You can delete unwanted photos by following the appropriate prompts.

To transfer photos to your desktop computer, a stand-alone USB reader for the camera's internal flash memory card must be used. First, make sure that the camera is turned off. Open the memory card compartment at the right front of the camera, lift the white card latch lever, and depress to eject the memory card. Insert the card into the card reader. It only goes in one way; don't force it! An icon for the memory card will appear on the Desktop. Double-click on the icon, then open the folder named DC220_01; photos will appear as files with the extension .JPG. Drag the photo files to the desired destination on the computer; they will be copied. When you're done, drag the files out of the DC220_01 folder into the Trash, then select Empty Trash from the Special menu. This removes the files from the flash memory card. Finally, drag the icon of the card itself into the Trash to unmount its filesystem. At this point, it's safe to remove the card from the reader. Re-insert the card into the camera (again, don't force it!), fold down the white latch lever, and close the door to the memory card compartment. Turn on the camera, and you're ready to take more pictures.

The "live viewfinder" mode using the LCD screen uses enormous amounts of battery power. Don't take photos this way unless you are using the external AC adapter.

EGG HUNT ROBOT TESTING

It's a trap to design/test your robot in isolation--remember, there will be 3 other robots out there with you in the arena. You'll run into them; they'll run into you; they'll move back and forth in front of the polarizing beacons and block your view; they'll knock eggs out of the open and up against the walls. While it's encouraging to see your robot work as designed in an uncluttered arena, this is no guarantee that it will do the same with 3 other robots around. Similarly, desktop tests of isolated nest detectors and egg discriminators are no guarantee that they will work when integrated with the rest of your robot. Simplicity and robustness of design are your best insurance policies against interference by other robots.

Ultimately, the only truly valid test of your robot is under actual game conditions--in the arena, with 3 other robots, black and pastel eggs, 2 polarizing beacons, and 10-minute rounds. Previously, in an attempt to prevent teams from wasting most of the semester on side-issues and then trying to complete their robots at the last minute, we instituted benchmark performance criteria, to be met by specified dates before the actual Egg Hunt. The idea was that, if all robots were required to show competence in key behaviors (nest-homing, egg collection and discrimination) well in advance of the Egg Hunt, the early maturity of the designs would insure better performance in the competition. Contrary to expectations, this did not happen. The reason is probably that something as complex as an Egg Hunt robot is not simply the sum of its parts. Additional features have costs, because they interact in unexpected ways with the existing design. For example, nest detection is not just the polarizing detector array; it's the drive train, the movement and obstacle avoidance software, the frame construction. A sensor head stuck on at the last moment is likely to be poorly-anchored and liable to fall off, or else require disassembly of already-working structures to make it fit (which runs the risk of not being able to get them working again). In short, it takes an entire robot to find a nest, and if the entire robot isn't designed with that in mind, it won't be able to do so robustly.

EGG HUNT TEAM STRATEGIES

Teams have many choices of Egg Hunt strategy. The following list, in order of increasing risk and unreliability, is not exhaustive, but it's pretty representative. Students are, of course, free to invent and explore strategies not listed here.

The key to a successful Egg Hunt strategy is reliability. I repeat, the key to a successful Egg Hunt strategy is reliability. I can't say it enough! Whatever your robots are supposed to do, they'd better do it 90% of the time, and do it well. Historically, however, the average reliability of individual robots (all strategies) has been about 50-70%. This translates into team reliabilities of 25-50%, meaning that, in the best-case scenario, your team has only a 50% chance that both your robots will function as designed for an entire 10-minute round. This is the strongest argument in favor of the dual independent pastel egg collector strategy. Other strategies which require robot specialization and/or cooperation have intrinsically lower reliabilities (they're more complex, harder to implement and debug), and leave the team without options if one of the robots malfunctions. With the hardware currently available in the course, there are no simple means of communication between robots (though we hope to change this soon); so planning strategies which require robots to reliably communicate is, for now, a waste of time.

My strong advice is to pick a simple strategy, one which you may find quite boring and uninteresting at first, and do it really well. In many of the past Egg Hunt rounds, a robot which could collect a single pastel egg and bring it home would have won that round for its team.

Ties and sudden-death overtime. Make sure that at least one of your team's robots is capable of grabbing a pastel egg and making a dash home in less than 3 minutes. This "overtime" behavior should be selectable by DIP switches and not require the loading of separate, special software at the last minute. Amazingly, we have had teams forget to plan for the eventuality of a tie, and end up in one! Nothing, however, is more ignominious than having a 0-0 tie after the round, a 0-0 tie after the tiebreaker, and finally having to decide the contest by a coin toss...

GROUP STRUCTURE AND DYNAMICS

Since LEGO 375/475 has no formal prerequisites, it potentially attracts students from a wide variety of backgrounds and experience. Historically, the majority have been computer engineering and computer science majors; but there have also been other engineering students (electrical, biomedical, mechanical), as well as physics, biology, mathematics, and even philosophy majors. No single student will have a pre-existing mastery of all the skills necessary to build a successful robot; thus, groups are selected by the instructors so that there is a balance of skills. At some point, you will have to learn skills that you didn't have before. The structured exercises during the first half of the semester are intended to make this learning process easier. By mid-semester, you and your groupmates should be ready to integrate everything into building a complete Egg Hunt robot.

Specialization is necessary in order to complete all the complex tasks within the limited time available; but over-specialization to the point that there is only one person who can do a particular task should be avoided. Whining that "we can't do anything because Susan is the only one who knows how the egg detector is supposed to work and she's not here tonight" will not be regarded with any sympathy by the staff. One of the best reasons for keeping well-documented code is that every group member (or team member) may have to work with it in your absence. Having a narrow focus leads to a great responsibility being placed upon individuals, which can be stressful and destructive if problems are encountered or the task is not progressing as well as hoped (or needed).

Every member of the group (or team) should have a say in what is done; but once a decision is made, everybody needs to abide by it. There is nothing more destructive to morale than second-guessing, whining, or even taking substantive contrary actions when nobody else is around (rewriting code, scrapping a constructed LEGO element without permission). You have to trust your colleagues if you want them to trust you. Make sure that you obtain consent from your groupmates (or, once Egg Hunt teams are formed, from your teammates) before making any alterations to code or mechanical design.

Respect the workspace of other groups, but remember, this isn't a top-secret Manhattan Project. Every student in the course is a colleague; you should learn from others and be willing to teach others what you've learned. This doesn't mean that you do all the hard work and give it away for the lazy to exploit. Be sporting about it--after all, your course grade does not depend upon your robot's performance. In the past, some groups (and teams) have been overly nosy and have engaged in intense "industrial espionage", scouting out the competition (during extra lab hours, when the competition isn't present). In retaliation, other groups have tried to be extremely secretive about their work, hiding their robots in opaque plastic bags, refusing to talk with other students, or even spreading disinformation about their strategies, capabilities, or progress. This behavior adds an "edge" to the course that I find uncomfortable and actually quite revolting. If it's allowed to continue, it only tempts someone to actually tamper with another robot (an action which gets you flunked from the course and in danger of expulsion from the University). Please, let us compete to win as best we can, but let us not become cut-throat about it.

In extreme cases of internal group or team dysfunction, the instructors reserve the right to reassign students in an attempt to solve the problem. We hope never to have to assert this right.

INCANDESCENT LAMPS AND LEDs

The computer board provides several output ports which can be used to drive incandescent lamps and LEDs. With the proper adapters, lamps can be plugged into either a motor port or one of the two led_outx ports on the expansion board. If plugged into a motor port, the intensity of the lamp can be varied by varying speed in the motor(n,speed) command. LEDs cannot run off of more than about 2.5 V without an additional load resistor.

Don't drive a breakbeam LED from a motor port! Even at the maximum speed of 100, the motor output is still pulsed, and the time constant of the LED is small enough that it can flicker on and off with these pulses. The response time of the phototransistor is also very fast, and it can detect the flickers. (They can even detect the 60 Hz flicker of fluorescent room lights.) Thus, you will get random false-positive detections of the breakbeam, and your Egg Hunt robot will keep thinking it has just gotten an egg, and drive you to distraction with its misbehavior. This caveat applies to both the discrete and monolithic breakbeam sensors.

Don't attempt to drive an incandescent lamp from the +5 V bus (middle pin) of an analog port! This +5 V bus is powered by the AA logic batteries, not the motor batteries, and the current draw is too great. This results in rapid (< 5 minutes) depletion of AA batteries. Don't be fooled by the fact that it seems to work just fine when the board is powered by the bench supply; this is only because the bench supply can supply 350 mA indefinitely.

Make sure that LEDs are plugged in with the correct polarity! Diodes conduct current in only one direction, so if you get + and - backwards, no light will come out. Please check polarity before complaining to the instructors that your LED doesn't work.

Besides their obvious use as indicators, the most common use of incandescent lamps and LEDs is for illumination sources involved in egg detection and color discrimination.

INTERACTIVE C (IC)

IC has some annoying kinks, but it's free and totally open and documented so we run with it. The most annoying feature of IC is that any C program you want to load has to either be in the same folder as IC itself, or inside the IC library folder. It will accept a fully-qualified pathname, but not use it :-( This means that every lab computer has to run its own copy of IC and that there's no way to set up a networked home directory for everybody in the course.

More than one bug has been found in the IC library code; there may be more. If you find a function which doesn't behave like its description, please let the staff know, and we'll try to fix it. Remember, though, as Kernighan and Ritchie (the inventors of the C programming language) have said, C is what your C compiler lets you get away with :-)

LABORATORY ETIQUETTE

The robot lab is a shared environment. The following points will help everyone to get along with a minimum of friction:

LEGO CONSTRUCTION

It is very important to learn how to exploit LEGO dimensions and form factors to build sturdy mechanical structures. Width and length (x-y plane) are specified in peg units (e.g. a 2 x 4 plate), while height (z-axis) is given in either plates or beams (3 plates = 1 beam in height). Unfortunately, the x-y and z units are not exactly the same (the distance between 2 adjacent pegs is not equal to the height of a beam). This means that a rectangular frame made by pinning 4 beams together (through the axle holes, using grey standard pins) cannot be exactly traversed by a column of plates. Also, LEGOmetrics are such that it isn't easy to use triangular braces to reinforce corners, except inexactly, by pinning beams across other beams. This is also unfortunate, because the triangle is the only shape which cannot change the angles between adjoining sides without changing the lengths of the sides; this is the source of the triangle's structural stability, and why it is used in bridges, etc.

Here are some basic LEGO construction tips:

LEGO KITS

When you get your kit, the parts are sorted into clear Zip-Loc bags and screw-top tubes. Keeping the parts sorted in their appropriate containers when not in use is a really good idea, especially for the little grey parts. It makes it easy to find the parts and easy to keep track of inventory. Remember, you have to return the kit in the same condition you received it.

The beams and bricks are distributed with like sizes stacked together in a stagger. Not only is it easier to count the pieces that way, it's easier to get them apart. For instance, trying to get a 1 x 2 plate off a stack with no stagger is difficult without strong fingernails or a jeweler's screwdriver.

LIGHT SENSORS

After DC motors and geartrains, light sensors are the second-biggest source of student headaches. Virtually all the difficulties are due to shielding problems and failure to take into account the wide variation between individual sensors of the same type. Consider the two functionally-relevant cases:

MOTOR CURRENT SENSORS

The computer board has a rudimentary motor current sensor for each of the bi-directional motors, motor_force(n). This can give a vague indication of a stalled motor (stalled motors draw high current). It has not proved especially accurate, since unstalled but heavily-loaded motors can also draw high current. Use it with caution.

PUSH-BUTTON SWITCHES

Push-button switches used for selection or software control (e.g., you want to wait for a keypress before starting some action) require debouncing software. A completed keypress consists of three consecutive states:

  1. no key pressed, waiting for you to press it;
  2. key pressed; and
  3. key released (i.e., no key pressed again).

Your software has to wait for these 3 consecutive states, especially (1) and (3). If you simply check for (2), you run the risk that, before you lift up your finger, the program will have run into code which is waiting for the next keypress, and misread the first as the second. Imagine typing on a keyboard with "instant typematic": a character is read repeatedly for as long as a key is pressed. Depending upon your typing speed, you'd get stuff that looked  llliiikkeee   tthhhhiiisss....   Debouncing the keys (waiting for complete press/release cycles) will do the trick.

"SECRET" STRATEGIES

Every semester, some teams are tempted to construct grandiose "secret" strategies, in the hopes that (1) they can surprise everyone else with something that they have no defense against, and (2) they can prevent anyone else from devising countermeasures against their robots. Inevitably, "secret" strategies fail because of the lack of field testing--if it's tested in public, it's not a secret any more. However, such under-tested robots are prone to catastrophic failure in the Egg Hunt.

The choice is yours. Personally, I think it's bad sportsmanship to keep secrets in this course--after all, your grade does not depend upon robot performance. Also, you're required to field contest-ready robots in two mock Egg Hunts, so you can't keep them secret anyway. However, "secret" strategies are not expressly prohibited. They are their own punishment...

SENSOR FUNDAMENTALS

While the sensors we give you are pre-assembled, plug-and-play, and often nicely packaged into convenient LEGO bricks, proper use of sensors is not trivial. In our experience, students tend to greatly underestimate the complexities inherent in sensors. Here are some pitfalls:

SERVO MOTORS

The servo motors come in a custom-modified package that gives you LEGO plates along 2 axes (for anchoring) and a LEGO gear (to plug directly into a LEGO geartrain). There are only a few sticky points about servo motors:

SWITCH SENSORS

The various contact switch sensors come pre-mounted into suitable LEGO bricks. Additional configurations can easily be made upon request, with the help of some hot glue; but the "standard" arrangements are suitable for most purposes. The switches are pretty sound mechanically and don't seem to be noisy. The spring action of the lever switches can't recoil hard enough to move a large LEGO bumper; you'll need a separate spring assembly in parallel.

Wherever possible, switches should be protected by other LEGO structural elements. A bumper made of LEGO beams can detect impacts over a greater area than a naked switch, and also diffuse the (often considerable) force of impact. Bare lever switches are particularly undesirable, as the lever can get snagged on other robots and ripped right off, destroying the switch and costing you some $$$.

Switches used in bumpers for collision detection may also require debouncing. Since it's not impossible for a switch to get stuck in the ON position, a debounce routine which returned an error condition if the switch didn't turn OFF after a certain period of time might be worth considering. Without this, a simple-minded collision daemon might put the robot into an infinite loop of avoidance, for as long as the switch was ON.

WARNING ABOUT HOT-SWAPPING OF COMPONENTS

Although it is sometimes tempting, never plug in or swap components while the computer board is turned on! Some items (like servo motors) will fry immediately if you plug them in backwards with the board energized. Turn off the power before plugging anything in, and double-check the polarities before you turn the power back on. Remember, you and your group are financially liable for damaged electrical equipment.

WARNING ABOUT POWER FAILURE AND main()

If you forget to turn off your computer board, it will run until the AA batteries fail. When the AA battery voltage falls too low, but not quite to the dead state, the board will spontaneously reset over and over (you'll hear it beeping). This reset is the same as pushing the Reset button, which means that main() will begin executing with each reset. Thus, if your main() code immediately runs go_forward() or some other movement routine, this routine will execute, and the robot will move. In this case, if you have left your robot out on the table, it will quite likely lurch itself right onto the floor, with catastrophic results.

As fail-safe insurance against forgetting to turn off the computer board, always make the first executable code in main() be a check for a keypress before beginning any movement. This way, if you do forget to turn off the computer board, and main() begins to execute with each power failure reset, the robot won't be able to move, because it will hang waiting for a keypress which it's not going to get.

Yes, one group actually did have its robot drive off the table and self-destruct due to leaving the power on after an extra session. The corpse was not discovered until the next day, but autopsy clearly showed the main power switch in the ON position, and the last main() code loaded did not wait for a user keypress before starting to move forward. This group was lucky in that the computer board was undamaged in the fall; the robot, however, was totally destroyed.


Back to the Autonomous Robotics Home Page