![]() |
|
|
|
|
|
|
|
|
|
Co-Processor Details |
|
|
|
The Co-Processor is a second processor used to lighten the
load on main processor. It is available
separately or with our boards.
|
|
<= Why use a Co-Processor anyway? If you just want your robot to wander around (or walk around if it is a walker), a Basic Stamp® only robot is fine. However, as soon as you have that, you will probably start to need more. You will want it to sense the surroundings and be able to react to them in intelligent ways. You may want to put overall goals, like light seeking or light avoidance, into the robot and see if it can succeed at them. This starts to add complexity to the simple programs you started with. A Co-Processor can simplify your programming effort as well as give you much greater capability from your current controller. In other words, it will let you add some really interesting things to your robots.! The discussions below cover where the BBDI Co-Processor can help and why it has the features it does. For the full details of how to program it, you can read our Co-Processor User Manual (rev 0.1 = 33 pp - PDF - 93 KB). An excellent techinque for robots is to use a "Finite State Machine" (FSM) style of programming. It allows you to get an appearance of doing more than one thing at once with a processor that is really only capable of doing one thing at a time. One place where FSM programming helps is in building in a "subsumption" style of control. Subsumption is a programming technique that is based on reflex types of reaction to sensor inputs. Essentially, if a higher priority stimulus is present, it takes control over the lower priority one. In other words, it is more important to react to bumping into something now rather than the fact that you are seeing something you might bump into later! An easy guide with further information on FSMs and Subsumption programming is here. In our work with a Basic Stamp 2 based runabout robot, we found that, by the time we got our subsumption engine with bumpers, IRPD vision, and random movements in it, the Stamp was just hanging on. That robot even had an simple IRPD co-processor. At different times during the development we had to use an oscilloscope to make sure the timing to the servos was correct. When, because we were out of processing power, we started having to do different parts of the processing on alternate cycles through the main loop, we decided to call "enough"! There was no place to go from there. This robot only had the two drive servos and was reasonable at running around. Playing a tune while moving, running a servo driven gripper and all the other things we had in mind were out. We felt the best way to solve this and allow the robot development to go forward was to completely unload some of the processing from the Stamp and then to add our timers for even better performance. That is where the Co-Processor comes in. While we were at it, we upgraded our controller board to the biggest, baddest, fastest Stamp Parallax makes. Now, let's cover the Co-Processor features one by one. <= Co-Processor to Processor Interface The Co-Processor only uses 3 I/O pins on the main processor - serial input, serial output, and timer expired. Timer expired is really optional. If you don't use the timers, you don't need to connect the timer expired pin. If you have a power supply that is noisy, a connection to the Co-Processor Reset line is a good idea too. Our 2p40 Controller Board has the co-processor interface on the AUX pins of the 2p40 main processor. Unlike the 24 pin processors which have only one set of 16 I/O, the 2p40 has two sets of 16 I/O pins. AUXIO is the second set. See the schematic (2 pp - PDF - 69 KB) for reference. On the 2p40 Controller, commands and data to the Co-Processor are on AUX 10, Data from the Co-Processor is on AUX 9, and the timer expired signal is AUX 11. Commands are a single byte with the MSB telling if it is a read or write type command. The lower 7 bits are a register address. Multiple channel registers are grouped such that the lowest 3 bits select the specific channel. On a write command, you send a second byte with the data. A single byte is read back on a read type command. Reset is an exception since it is a read type command (decimal 116) and is sent twice and has no data returned. Pin 21 of the Co-Processor selects between 2400 and 9600 baud. Grounding the pin selects 9600 baud. Pulled up to +5 is 2400 baud. The serial port should be set up for 8 bit, no parity, true mode. On our 2p40 Stamp processor at 2400 baud, this is a value of 1021. A BS2 would use 396 for the same baud rate and mode. Newer code examples have a 96 somewhere in the name and use 9600 baud. Values for other Stamps can be found in the Basic Stamp Programming Manual under the SERIN command. Delays between sending the two bytes for a write type command from a stamp are not needed as the Co-Processor can keep up. On read type commands where data is expected back, no commands should be placed between the SEROUT and SERIN commands. It is also a good idea to refrain from fancy formatting on the receive data to keep the turn around time on the Stamp quick enough to catch the data coming back from the Co-Processor. The Co-Processor interface on our controller board is on the AUX pins of the 2p40 on our controller. AUX is the second set of 16 I/O. In your program you can easily switch back and forth between sets - just make sure you have the AUXIO selected when talking to the Co-Processor on our controller board. AUX 10 is the Data to the Co-Processor. AUX 9 is the Data from the Co-Processor. AUX 11 is the Timer_Complete signal from the Co-Processor. AUXIO doesn't apply if you are using a 24 pin Stamp part to talk to the Co-Processor. The signal pin numbers may also be different on your board. On our 2p40 Controller Board we can use only 3 pins because we have the Brownout detection enabled and our power supplies are very solid. If you have a supply that can have voltage fluctuations while running, you should get the Co-Processor with brownout detection disabled. In that case we strongly recommend adding a separate reset wire to the Co-Processor as is shown in both our AppMod design schematic (1 pp - PDF - 47 KB), and our Co-Processor add-on board schematic (2 pp - PDF - 23 KB). A complete map of the instructions is in the Co-Processor Map (5 pp - PDF - 812 KB). <= Timers! It is easy to make a delay using a Basic Stamp®. The only problem is that the Stamp stops computing while the delay is happening. We felt timers are just too important a function to allow the main processor to shut down while timing. We added 8 timer channels to tick off 20 millisecond increments. With a timer, instead of the Stamp processing having to stop while running a PAUSE instruction, you can set a timer channel in the Co-Processor and periodically test a single Co-Processor pin to see if any of the timers have expired. Read a status byte to identify which timer(s) have just finished and reset the Co-Processor flags. This way you can keep running other functions in the Stamp 2p40 while the time passes. Check the timer expired pin more often to get better resolution on the timing. One of the timer channels (timer 0) can also retrigger itself automatically so uncertainties in your program getting back to restart it don't affect the long term timing accuracy. Here is some example timer code to see one way a timer can work for you. Herbert is an animatronic head project whose code also serves as a timer example. <= Bumpers Robots need to sense their surroundings. Bumpers are one good way of doing this. We have the 2 front bumper inputs connected to the Co-Processor. This saves 2 I/O pins on the Stamp. It is also required for the Co-Processor to run the robot's subsumption engine. For example code to read the bumpers into the Stamp, see the vision section below. <= The IR "Vision" system Actually this is not really vision in the sense of seeing details. Instead it is an InfraRed Proximity Detector (IRPD). Two IR LEDs take turns flashing at high speed and any reflections from the left/front or right/front are detected with a remote control type sensor. Putting out these high-speed (38KHz) pulses while testing other signals is not something a Stamp does well. A separate Co-Processor is better for this service. With our Co-Processor, the Stamp 2p40 can get the results of the IRPD sensing by simply reading a status register. Some other robots also use a simple Co-Processor to help with the IRPD system. If the operating frequency is changed, the sensitivity of the detector changes. In our Co-Processor, the frequency is programmable over a wide range. This can be used to adjust sensitivity to distance even while the robot is moving. Most other IRPD Co-Processors don't have this feature. Because of the wide range of 15.1 KHz to over 62 KHz (in 127 steps), you could use the Co-Processor with other sensors besides the 38KHz one we use. Example code of how the Stamp can read the bumpers and IRPD Vision is in botstatus_bsp.txt. <= Servo Controller with Ramping To drive a servo you send a 1 to 2 millisecond pulse every 20 milliseconds. You should send the pulses to every servo whether it is moving or not. It is not difficult to drive a servo with a Stamp, just issue a PULSEOUT instruction. Like during a PAUSE, while the pulse is going out, the Stamp can't do anything else so each servo takes 5 - 10% of the Stamp's capability. Getting the 20-millisecond refresh time correct is not always so easy. You have to know when you are done executing for 20 milliseconds so you can go back to re-send all the servo pulses. This can get complicated. The good news is that the Co-Processor will do this for you so the Stamp can keep running. The drive wheels only use 2 channels but we went ahead and added the ability to do 8 servo channels in the Co-Processor. This leaves up to 6 free channels for other servos. You may want to use them to scan some sonar sensors or drive a pan and tilt head for an on-board camera! Controlling the servos is easy. Send a byte using a SEROUT instruction to the Co-Processor to address the servo you want followed by a byte to give it the new desired servo position (0-255 steps of 4 uSec). Send 2 bytes - that's it! The addressed servo will now go directly to the new position. The Co-Processor will automatically continue to send the correct pulses every 20 milliseconds until you change it. Here is some example servo controller code to see how simple it can be to program servo controllers. We also provided for ramping the servos from position to position (on unmodified servos) or from speed to speed (on modified servos like the drive wheels). Ramping prevents the shock of abrupt position or speed changes that can cause wear and tear on your servos. It also eliminates a lot of calculation the Stamp would have to do while the changes are taking place. If you needed to ramp to speed or position on a servo controller without the ramping feature, you would have to use the Stamp to calculate all the intermediate positions. Only after reaching a steady speed or position could a non-ramping servo controller take over. Ramping can also be disabled if you choose. If you want the servo to use ramping to more slowly move to a new position (on unmodified servos) or turn slower (on modified servos), just send two more bytes, one to address the ramp rate register for the channel you want to set and one more to set the ramp-value (0-31). Each pass through the 20 millisecond loop will increment or decrement the servo value by ramp-value/4 until the desired position is reached. The ramp range goes from 0.66 seconds to over 20 seconds for full swing. Here is some example servo controller code with ramping. Herbert is an animatronic head project whose code also serves as a ramping servo example. A bit in the ramp register will change the step size to 8 uSec to allow you to drive servos with a range of control pulses from 0.5 -> 2.5 milliseconds. While in this mode, there are protection registers to limit the minimum and maximum pulsewidths allowed. This is a protection against your code calculating a pulse value that could hurt the servos. <= Reading Analog Signals Reading analog signals can be done with a Stamp but it isn't as clean a solution as using a real A/D (Analog to Digital) converter. Our Co-Processor includes 5 channels of 10-bit A/D. One channel is connected to the power supply so you can measure the state of the batteries but the other 4 are unused and available for your uses. Here is some further explanation on programming the A/D converters and tutorial and example A/D code. After looking at the tutorial, you might be interested in this datalogger program using our controller board with an attached PC as the display. It is given as a text file but it can be copied into the Stamp editor as a BS2p program. The A/D converter reads the input voltage with respect to its power supply voltage. If your power supply is not at 5 volts and as stable or as noise-free as the one on our controller boards, you might get peculiar readings because of the power supply. <= Robot Stuff - The Subsumption Engine We added an Expandable Subsumption Engine in the Co-Processor. Since all the necessary sensor inputs already go to the Co-Processor, the Co-Processor has everything it needs to completely run the robot chassis. To do that, you just initialize and enable it. This allows the full power of the 2p40 to be used for your application! The robot program in the Co-Processor can be tailored by sending parameters from the Stamp 2p40 or even disabled entirely if you want the Stamp 2p40 to have full control over the functions. The details on our Subsumption Engine and example code to start it running are on these links. <= Use our Co-Processor on your project? The Co-Processor is also available separately so you can add it to projects you design and build. Things like a smaller or larger robot, a Walker, an animatronic head - all these can use help from 10 bit A/D, IRPD control, Servo and I/O output pins, Bumper inputs, Timers, some even can use the Subsumption engine! No reason it won't work with a processor other than a stamp. You'll need RS-232 drivers and receivers to use it with a PC or other RS-232 device like a Palm. The Co-Processor is a preprogrammed 28 pin Microchip PIC® 16F87X designed to run with a 20 MHz clock. Get one for your next project. See here for a discussion on Brownout detection. The Co-Processor is available with or without. |
Blue Bell Design Inc. Post Office Box 446 Gwynedd Valley, PA 19437-0446 USA 215-643-7012 email us harry@bluebelldesign.com on the web www.bluebelldesign.com Basic Stamp® is a registered trademark of Parallax, Inc. The Microchip name, PIC, PICmicro, MPLAB are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. In-Circuit Serial Programming is a trademark of Microchip in the U.S.A. |