I'd Rather Be Building Robots

June 30, 2008

Motor Control with the Mindsensors PCF8574A

Filed under: Experiments, Sensors — Xander @ 09:20

//www.philohome.com/motors/motorcomp.htmThe Mindsensors PCF8574A board is not just suitable for making das Blinkenlights but also for controlling other ICs.  I recently thought of how I could use my old 9V motors with my NXT using a dual H-Bridge IC such as the SN754410.  This IC is pin compatible with the very popular L293D and has the same clamping diodes built-in.  It is, however, much beefier than the L293D and can handle much higher loads.

Click to enlargeIn this setup I am using two buttons to control the program on the NXT.  I have a direction button (SW2) and a disable/enable button (SW1).  The former controls the direction of the motor and the latter the braking of the motor.  When the direction button is pressed, the motor will toggle between left and right rotation.  When the disable/enable button is pressed, the motor is toggled off and on.  The current program is configured to stop the motor by allowing it to coast.  A simple programmatic change would enable dynamic braking.  If you are not looking to allow your motor to coast to a stop, you can forego the extra pin needed to toggle the EN pin on the H Bridge and add a 10K pull-up resistor to that port.  That would allow you to potentially connect two dual H-Bridge ICs and control 4 motors at once!  I’ve also tested this circuit with the new style 9V motors.  You have to be very careful with those, though.  According to some tests, they can pull up to 3.2A when stalled.  More information on the various Lego motors and their properties can be found here: LINK.

You can find the source for this program here: LINK.

I’ve made a short video demonstrating the setup.  This time I’ve even included a voice over!!

June 29, 2008

Thanks Maxim

Filed under: Experiments, Ramblings, Sensors — Xander @ 12:36

Maxim MAX127 12bit 4 chanel ADC About a week ago I ordered some product samples from Maxim.  I am not talking about the men’s magazine but the IC manufacturer.  Well, they got here yesterday so that’s pretty damned quick if you ask me.  I was keen to get some hard to obtain ICs for my robot projects.  I ordered 3 MAX127 12 bit 4 Channel ADCs, 3 DS1678 Real Time Event Recorders and 3 DS1307 Real Time Clocks.  Why would I want all of these devices? Well, they’re all equipped with an I2C interface.  I am very keen to learn more about this interface and how I can hook them up to my NXT to do my bidding.  I am not sure why I picked the Real Time Even Recorder, but I am sure I can figure something out with it.

The MAX127s are going to be great.  They are almost impossible to come by here in the Netherlands, especially for regular consumers such as myself.  These ones are in DIP format so I can easily play around with them on a breadboard without the need for some kind of adapter board.

I have another set of samples on their way to me.  They’re from Microchip and have a couple of nice memory chips and some other goodies.  I will be sure to post about them when they get here.

June 23, 2008

Expanding the NXT with the PCF8574A

Filed under: Experiments, Sensors — Xander @ 18:09

PCF8574A before assembly - photo taken from mindsensors.com The Mindstorms NXT is great, no doubt.  However, sometimes you’d like to be able connect non-Lego items to it.  The NXT’s ability to talk I2C, the industry standard protocol for interfacing electronic devices makes this an easy to achieve goal.  Since this was my first time hooking up anything non-Lego to my NXT, you can imagine my hesitation.  I procured one of the Mindsensors PCF8574A boards which comes complete with the chip, an NXT cable connector, the PC, various passive components (resistors, capacitors) and some pin headers.  Pretty much everything you need to hook the whole thing up and start adding some of your own components to it is there. 

PCF8574AWhen I first started experimenting with the IO board, I noticed that my LEDs would barely light up when one of the IO ports went up.  I guess the PCF8574A just isn’t very good at providing current.  However, it makes a good sink, so I just hooked up a 1K resistor to Vdd (5V, in this case).  Now when a pin goes low, the LED lights up very nicely.  4 LEDs in all were connected in this fashion to port 0-3.  I also hooked up a small microswitch with a pull-down resistor to port 7.

The program I wrote was mostly put together from other examples and helpful posts on the RobotC forums.  It switches the LEDs on in a Knight Rider-like fashion.  When the button is pressed, the direction is reversed.  You can watch the whole thing in the little video below.  The source code can be retrieved from here.

June 15, 2008

Determining Object Distance with Infrared

Filed under: Experiments, Robots, Sensors — Xander @ 11:25

Next Saturday (21 July 2008 ) I am giving a presentation on the Parallax Propeller microcontroller and I thought it would be a nice idea to demo some things with it.  I have a Propeller Education Kit (PEK) and a Propeller Proto Board (PPB), kindly donated to me by Parallax.  The PEK is awesome for learning how to use the Propeller as it comes complete with a veritable mountain of components, including the chip itself, of course and a very big breadboard.  The PPB is great because it allows you to hook it up to any monitor using the accessory kit that comes with a VGA and 2xPS2 connectors.

From my days with the BoE Bot I remembered a lesson that taught a way to gauge the distance to an object using an IR sensor and LED. On a microcontroller without an Analogue-to-Digital Converter (DAC) built in this would only allow the a simple “object detected” and “no object detected’ state.  That is not very useful in a real environment.  The IR detectors are quite tricky little things.  Most of them are sensitive only to a very limited wavelength of light, usually somewhere in the 950nm range.  However, in order for them to be less influenced by regular light, especially fluorescent light, they are made to be sensitive only to light that hits them at a certain frequency.  This frequency depends on the sensor make and model and usually is set to anywhere between 32KHz to 40KHz.

The frequency sweep method

bellcurve-tsop2236This bring us to the first method of object detection. Although the sensor is made to detect incoming IR signals at 36KHz, that does not mean it can’t detect signals at other frequencies. It can and will detect them, just not as well.  We can exploit this property by varying the frequency we make the LED flash at.  I used the TSOP2236 that is preset for, you guessed it, 36KHz.  As can be seen from the graph to the left, the response is not quite linear, but it’s as close as it’s going to get.  If we take 36KHz as our base frequency and sweep as high as 1.2 x base frequency then our top frequency will be 43.2KHz.  We will ignore everything on the left side of the bell curve.

Click to enlarge So how does it work?  A non-optimal frequency makes the sensor a little more short-sighted.  The less optimal the incoming signal is, the more short sighted the sensor will appear to be.  We take the frequency range between 36 and 43.2KHz and chop it up into 100Hz parts.  That gives us 73 possible readings.  Instead of writing a whole bunch of code myself, I took the code from the PEK bot project on the Parallax site and modified it a little to make it a bit more flexible.  imageI set up the circuit on the PEK and took readings from 5 to 30 cm in 5 cm intervals.  There are no absolute frequency values, just frequency index numbers.  In order to reduce the noise, I averaged 10 readings at each distance and repeated the experiment 3 times.  The graph is pretty much what I expected;  a somewhat non-linear response to the incoming frequency.  It is a nice way to be able to tell roughly how close an object appears to be, rather than the binary “object detected”/”no object detected”.  However, can we devise a better method?

 

Variable Resistance Method

Circuit discussed on Parallax Forums This method does not depend on sweeping the incoming frequency to make the sensor short sighted.  Instead we will merely reduce the amount of light the LED will emit at the base frequency.  This method was discussed at the Stamps In Class forums.  The project uses preset resistors set up in a parallel configuration, allowing for a wide variety of combinations resulting a large range of different resistances.  One of the readers of the post suggested using a digital pot meter, in other words a  DAC to vary the resistance.  I picked up one of these DACs, an MCP41010, that has a range of 0 to 10KOhm with an 8bit resolution, giving it 256 steps.  I picked it because it has an easy to use SPI interface.

Click to enlarge Programming the code for the pot meter wasn’t terribly difficult in hind-sight but this was the first time I had used SPI.  I managed to find some code that used SPI for some other device, I modified it to use the commands described in the MCP41010 datasheet.  I was pleasantly surprised how easy it was to get working.  To the right is the layout of the circuit I used.  The controller has been left out for clarity. The tests were done by starting the MCP41010 in its maximum setting and slowly decreasing the resistance in steps of 5.  I think going through each possible setting would’ve been overkill and this still gives us 52 steps.

image The results were, well, a little less than overwhelming, to be honest.  The curve is very similar to the previous one.  For the amount of extra circuitry and code you don’t get a whole lot more performance.  It was a fun experiment and perhaps there are some things you could do to improve this circuit.  If you have any suggestions, please leave a comment.

 

Testing methods

PEK board layoutThe experiments were done with both circuits on the same PEK at the same time.  This allowed me to test both circuits under the exact same circumstances.  I secured the breadboard in place with some tape and drew lines at 5 cm intervals from the front of the PEK.  I used a large non-IR transparent object (read: wooden box).  I made sure the object was perpendicular to the sensors at all times.  The button on the right side of the board is the trigger.  Each time it is pressed, the first sensor is tested 10 times followed by the second sensor.  This allows me to move the object without getting any readings.

Above right is a picture of the breadboard with everything on it.  I hope you enjoyed this article as much as I enjoyed doing the experiment.

You can find the code for this project here: LINK.

June 11, 2008

Pardon the mess, we’re redecorating

Filed under: Ramblings — Xander @ 16:46

I’m trying to sort out this blog and how it looks, so appearances may change over the next few days as I modify, tweak and rip bits out, only to replace them or re-add them 5 minutes later.

Stay tuned.

June 10, 2008

A-Maze-Ing

Filed under: A-Maze-Ing, Robots — Xander @ 21:33
Tags: , ,

My current project, well, the one I seem to be spending the most time on is a robot called A-Maze-Ing. It is based on a Lego Mindstorms NXT brick. This robot is, or rather, will be, a line-maze solving robot.

The first challenge in building this robot was its size. Rules dictate the robot should not exceed 15×15x15 cm at any time during the run. That might seem like a lot, but the brick’s size and the motors’ lengths make this quite a daunting task. It took quite a few iterations.

A-Maze-Ing-before A-Maze-Ing

slider-detailThe robot on the left (above) is one of the first models. It was badly designed as it turned out because the light sensors were packed too closely together. I would get false positive readings on the side sensors even when no crossing or T-junction was present. The second model on the right (above) is the current model. The sensors are placed as far apart as possible and the swivel wheel on the back of the early model has been removed completely. The robot now makes use of two round bricks that it slides on as shown in the picture on the right. As of this moment he robot can’t do much yet. So far I have programmed the state engine frame work and the ability for it to turn right when it detects a… right turn. The other parts of the state engine do nothing.

Here is a quick, very short video I made of A-Maze-Ing’s ability to detect a right turn and turn. It will try to place itself correctly on the line once the turning is done.

More videos will follow as I progress. The first goal is to make a robot that can solve a maze without loops using the simple follow-the-right-wall method. Next generations will be able to solve mazes with loops and ultimately calculate both the shortest AND quickest paths.

It’s been a long time since my last confession

Filed under: Ramblings, Robots — Xander @ 08:21

It seems it’s been years since I last blogged anything.  I used to run a blog at mightor.blogspot.com but I guess I ran out of ideas to post about.  This blog’s title is a good summation of what I think about when I am at work or doing something I’m not really enjoying.

I’ve been building robots for a little while now and am now the proud owner of no less than 4 robots, in various state of assembly.  I have two Lego Mindstorms NXT sets and two Parallax Propeller based robots.  I will be posting more details about those later.

This blog will serve as a journal as my robot building progresses over the next while.  There are some competitions coming soon and rest assured I will be posting about those as well.

Blog at WordPress.com.