Sunday, 29 July 2012

An IR Synthesizer

I had a dream about theremins the other day (those things that make noises in response to you moving your hands) and pondered how to build one, or something similar, or just something that makes noise. Having pondered how to build one, I thought of some stuff and had absolutely no choice but to try it out :)

My initial plan was to use 1 or more IR range finders to measure the distance of an object from a sensor, then use that distance (or some function of it) to choose a pitch. An Arduino then generates a wave and pumps it out through a speaker, so the very simple circuit would be along the lines of this:

Simple circuit for Arduino to drive a speaker using IR sensor readings

In case you're wondering, that little speaker circuit is genuinely all you need to generate noise from an Arduino - a little 80ohm speaker plus a small resistor and you can send it a wave (potentially using the handy 'tone' command) to generate a noise. However this has some major floors:

  • It's fairly quiet, as you're powering the speaker off the Arduino
  • You can only really generate square waves, as the GPIO pins are either on or off
  • Again, due to the binary nature of the GPIO pins you can't digitally control volume
Anyhoo, it quickly became apparent that this wouldn't do the job. Initially I had a blast at building an R2R ladder digital-to-analog converter (excellent web page on them here), which would allow the Arduino to output a 10 bit binary value, which is then converted to a voltage and pumped into the speaker. Unfortunately once this was working the signal was so weak that it couldn't drive the speaker. Fortunately, I then remembered my Speak Jet chip from this earlier post.

The Speak Jet is a speech synthesis chip, which internally uses a 5 channel synthesizer to produce phoneoms. However you can take direct control over the synth if you prefer, which is exactly what I decided to do. So first step is to expand the circuit to this one:



I haven't shown the whole speak jet setup (which you can peruse at your leisure from earlier posts), but it's basically the speak jet chip plus a *20 gain audio amplifier built with an LM386 op amp. A bit of wiring later and....


That bread board is the speak jet and op amp squeezed into a neat little circuit that I'll probably never dismantle again. Although it looks a little complex, it's mostly just the right organisation of capacitors and resistors to build a simple audio amplifier from an LM386 as specified in their manual. In addition to the circuitry, you can see the oscilliscope attached to the speaker output, with the wave being generated on it.

With a little bit of code to read values from the sensor, convert them into a frequency range and then send over serial to the speak jet (which I might post at some point), I end up with this ear bleeding monstrosity:


If you had headphones on when you played that then I am sorry.

Anyhoo, it makes noise but isn't particularly useful. A real instrument does more than make noise - it is controllable, so the user can choose when it should make noise. I decide the key to this instrument is to add a push button to 'strum' the note. So with a small tweak to the circuitry:


I now have a push switch in there, and update the code so it sends volume commands to the speak jet in addition to pitch commands. When the user is holding down the push switch the note is played at full volume, and after releasing it the note decays for half a second. In addition, the pitch can only change when the button is down, allowing the user to bend the note as they play it. Unfortunately my musical abilities are limited to the listening side of things, so I grab Mark.A from his work and hand him a plank of wood and a push button:


And there you have it! An Infra Red Synthesizer :)

-Chris




Monday, 23 July 2012

Table update

Not done too much more on the table, but I've put together a few photos and a video to show it.

First up, here's the video, build in OpenSCad of the components falling into place and then rotating the table central section:


It gets the idea across pretty well. Once the key switch is activated and the push button is hit, that central section will spin round 180 degrees to flip from poker to coffee mode, or visa versa.

Now these are the actual components I have so far:


Note the plastic connector that attaches the motor to the steel axle. After wondering how to do this for ages, it suddenly occurred to me I could just design them in a CAD package and print them off on my 3D printer. The connectors have correctly sized holes in at each end, so all that's left is to sand off the axle a bit (so it has a rough surface), then glue it in with high torque super glue or epoxy resin.

All I'm missing now are some springs to fit into the solenoid, a battery and the key switch.

So as I said, we've actually done a bit of work as well - one table lid coming up:


That central section is the bit that'll have glass on one side, and felt on the other.

And finally, a sneak preview of my design for telescopic legs (which won't be in version 1):


Ultimately this is a home made rotary linear actuator, which uses a threaded rod attached to a motor to push a bolt forwards or backwards, translating rotary movement into linear movement. Whether or not I end up using this for the table, it's a nice design for a powerful and accurate home made actuator, which typically cost quite a bit to buy pre-made.


Sunday, 22 July 2012

Auto Poker Table

For a long while I've wanted to create a poker table (cos I play poker), however my small flat doesn't have room for one. As a result, I decided to create a coffee table that could transform into a poker table... electronically of course. Originally I was going to get cooler and add an entirely pointless auto-levelling telescopic leg setup as well, but I'm gonna leave that till later or it'll take ages!

I started from this basic design, which is based around the idea of a rotating midsection controlled by 2 motors at each end:


On John's advice we decide to build the table out of marine ply wood - a very high quality and strong material, ideal for projects like this. It turns out you can only by 2.4mx1.2m sheets, so I grab one that is 18mm thick and another that is 12mm thick, which comes to quite a lot of money, but what the hell - this is a piece of furniture so needs to be beautiful as well as functional!

Anyhoo, once the basic idea is down on paper, the actual mechanism needs designing. After some pondering I came down to:
  • 2 miniature high torque geared DC motors to turn the central section
  • 4 solenoids placed along the sides of the table that retract when the lid turns, then pop back out to lock it in place
  • 4 microswitches placed along the sides of the table to detect when it is in the correct position
  • An Arduino Nano to drive it all
  • A rechargeable battery stashed in one of the legs
  • A pair of switches (one of which is a key switch) to trigger a revolution.
The pair of switches is quite crucial, as the last thing we want is accidental table turning. Hence I'll have 1 switch that you must turn on with a key, before hitting a push button to actually trigger the turn. Once this has happened, the key switch must be de-activated before another turn can occur. I'm also tempted to set it up so the push button must be pressed within 30s of the key switch being activated. Super careful basically. I don't want my dinner suddenly flipped upside down accidentally!

So, with this in mind, I switch to a CAD program to model it. First up, a view of the actual table:


As you can see, it looks like a fairly classic 2 shelve design, the real difference being that the glass central section can spin round to reveal a felt lined surface, ideal for poker.

These next 2 images show some of the intended components:

Components embedded in table

Components raised out of the table so you can see them.

You can see the key parts here - a solenoid and microswitch to make up the detect/lock mechanism, and a motor with a long axle to turn the central section.

The few remaining bits to work out are:

  • Where to put the battery? I'm thinking a rechargable battery embedded in one of the legs would be ideal. I'd rather not have a mains cable trailing to my table the whole time :)
  • Should the table talk? It only seems logical for the table to say 'table taking form of poker' when you press the button....
  • Will it actually work?

We've started actually building now, so next post I'll add some pictures of the components and the wood work itself. I'm also planning to blow a load of money on some nice new power tools, so I'll probably post pictures of them too.


-Chris

Thursday, 28 June 2012

3D Printer!

I have a 3d printer! To be more precise, it's a UP! Plus 3D printer, and I got it a few weeks ago but didn't get around to writing about it. Some specs are here on the cool components web site (where I bought it), although the developers are at http://pp3dp.com/. Here's a nice picture I found:

UP Plus 3D Printer

It was incredibly easy to setup. You basically assemble a few bits with a screw driver (provided), install software and plug it in! First time you use it you'll need to calibrate which would be a fairly simple process, except the software has changed since the manual was written which added a small amount of confusion. Either way, it took less than an hour to set up so I was happy.

Now, the software has it's up sides and down sides. A few good points:

  • It takes the extremely simple stl file format, which comes as standard in most 3d packages, and is easy to write code for as well.
  • Very robust - I've thrown millions of polygons at it and it's never crashed
  • Relatively fast. Obviously give it a few million polygons and it runs at 1fps, but its generally good enough just for positioning your model
  • It automatically adds scaffolding to support your model as it's built, allowing you to create models with overhangs

So in general it does what it says on the tin. However it's not exactly a miracle of UI design. Getting the settings right for a given model does involve a little bit of guesswork, but after a few attempts you can generally get it right first time.

Here's a few models I printed in my experiments to see what it could do:

Statue Of David

Some bits and bobs I printed

These images show a few fun tests:
  • A wine glass with an incredibly thin stork, to see how skinny it could print
  • The oval has text on (which says Chris)
  • The plastic square on the motor is modelled to perfectly fit to the axle. I did this on the basis that if I can print a perfect fitting square, I can print a perfect fitting wheel :)
  • A statue of david (top) because my friend broke his
The best of all though is a chain! This nifty model was printed as a single object. Mark modelled it in 3D Studio with the small gaps needed between each chain link. The software automatically places scaffolding to allow it to print, you wait a few hours and... well best shown with a video:


Going forwards I'm going to create MmBot 2's chassis and framework using the printer. First though, I needed to find a decent bit of CAD software, and found it very frustrating. Too many massively complex uber tools or simpler but ropey applications. So I decided to create my own small CSG tool designed for creating pieces of robot, which I'll probably write about next time.

Saturday, 9 June 2012

Git Open Source

Very very quick post here - I've finally got around to setting up source control for mmbot. All is open source and stored up on git hub here:

https://github.com/wibble82/mmbot

It currently contains most of my Arduino code so far, and the beginnings of the design for the new chassis using OpenSCad. Feel free to grab what you need, along with the general statement of 'I take no responsibility for what you do with the code even if it blows up a computer or nuclear power station or whatever' :).

-Chris

Saturday, 26 May 2012

It's all hooked up!

I've been slacking a little bit on keeping this blog up to date, but still progressing robot wise. My latest report is that I finally wired up the final components to MmBot - the Sabre Tooth 2x5 motor controller, and 2 quadrature encoders I have been building. Together they allow me to control MmBot's speed and direction quite accurately, and as result I will be able to reliably issue commands such as 'turn 90 degrees' or 'go forwards 3.5 metres'. First up though, here's MmBot in all her completeness:


And another one from above:


All parts are now attached and wired up. That's:
  • 2 Infra red range finders (front left/right)
  • 2 LinkSprite JPEG colour cameras (the eyes)
  • 1 Infra red motion detector (the nose)
  • 1 Ultra sound range finder (on top of head)
  • 2 quadrature encoders, each containing 2 infra red reflectivity sensors (next to the wheels)
  • 1 Blue smirf blue tooth modem
  • 1 Sabre tooth 2x5 motor controller
  • 2 18V DC geared motors
  • 1 Arduino Mega
The only bits missing are the interactive bits, which I may or may not add to this version of MmBot. These would be:
  • 1 speak jet voice/sound synthesizer (tested but not connected to MmBot)
  • 1 voice recognition chip
  • 2 led matrices
  • Speaker
  • Any extra leds I want to stick on!
While it'd be nice to get the interactive bits on as well, the circuitry is becoming a bit messy and I don't need it to achieve my initial goal of wandering around the office, identifying people or points of interest and looking cute. Plus my Raspberry Pi finally has a delivery date (3 weeks), and the cooler interactive stuff will be much easier and more powerful once it's hooked up.

The main thing I got working today though was the quadrature encoder and motor controller. This first fairly boring video shows the motor controller in action, gradually swinging the motors between full reverse and full forwards:



Next, things get a little more interesting. I start by asking both motors to go at 75% power and plonk MmBot down on the floor. Now you might hope that she would go in a straight line - after all I'm sending the same power to each motor. Unfortunately even in the best of scenarios motors aren't perfectly matched, and if you then introduce things like friction or wobbly wheels resulting from my supreme workmanship MmBot drives around in circles.

Not to worry though - that's why I built my encoders in the first place. These devices allow me to measure the actual speed the wheels are turning at. For MmBot to travel in a straight line both wheels need to turn at the same rate, so all I need to do is write some code which:
  • Supplies a fixed amount of power to left wheel (say 75%)
  • Initially supply the same amount of power to the right wheel
  • If the right wheel is going slower than the left wheel, supply it with more power
  • If the right wheel is going faster than the left wheel, supply it with less power
Sounds very simple, and it is in fact fairly simple. The only problem with this feedback type code is that the results aren't instantaneous - supplying more power to a wheel will allow it to reach a higher speed, but it takes time to have an effect. You have to be careful that your code accounts for this, or you'll find yourself constantly over compensating, and will end up driving all over the place!

You've seen my earlier code to read from the quadrature encoders, and other code to trigger sabre tooth motor controllers. this tiny bit of new code in the loop achieves speed control:

      //check where left encoder has got to relative to right encoder
      if(left_encoder_pos < right_encoder_pos)
      {
        //left is behind right, so we need to increase right motor speed
        motor_right_speed = min(255,motor_right_speed+1);
        MotorSerial.write(20);
        MotorSerial.write(motor_right_speed);    
        
        //and reset encoder positions (to avoid constant over compensation)
        left_encoder_pos = 0;
        right_encoder_pos = 0;
      }
      else if(left_encoder_pos > right_encoder_pos)
      {
        //left is ahead of right, so need to decrease right motor speed
        motor_right_speed = max(128,motor_right_speed-1);
        MotorSerial.write(20);
        MotorSerial.write(motor_right_speed);         

        //and reset encoder positions (to avoid constant over compensation)
        left_encoder_pos = 0;
        right_encoder_pos = 0;
      }

I wire up some switches on MmBot to turn on/off motors, and enable/disable speed control. This video shows the difference. Disclaimer: this is one of the worst filmed videos in the world, and my video editing abilities range from 0 to 0. I clearly need a tripod, a good camera and a lot of practice with AfterFx. Check out the start bit and the end bit, and pretend you never saw the middle bit.



And that's that! MmBot V1 is pretty much hardware complete. I'm in 2 minds now - I could go on and try to get some better code in there - take some steps towards autonomy. On the other hand, I now have a raspberry Pi in the post. Needs a bit of thought :)

-Chris

Sabre Tooth Motor Controller

I've got quadrature encoders working to measure speed and they're now attached to MmBot (although not wired to the arduino yet). Next I need to replace my very basic home made motor controller with the nice Sabre Tooth one I have. In a much earlier post I had a first blast at this but it turned out I had the Sabre Tooth RC. Fortunately, my standard Sabre Tooth 2x5 has now arrived which supports serial communication, and here it is:

Sabre Tooth 2x5 Motor Controller
It's a neat little piece of kit. On the left you can see the motor power connection, with the motor connectors top and bottom. On the right is GND and Vcc coming from Arduino, plus a white signal cable. This controller can run in lots of different modes which are configured with the switches at the bottom.

After a bit of experimentation I find the right setup for a simple serial connection at 9600 baud rate. In this mode you send the motor a value from 1 to 127 to control motor A (1=full reverse, 64=stop,127=full forwards), and 128 to 255 to control motor B in a similar fashion.  In addition, sending a 0 instantly stops both motors.

To get things going, here's the first basic circuit I build:

Circuit diagram of Arduino connected to Sabre Tooth
It's a pretty simple setup. On the left I have the Sabre Tooth connected to a 12V battery, a 12V DC motor , and (instead of another motor) the oscilliscope. On the right you can see the Arduino wired up, with GPIO3 going to the signal 1 connector. Signal 2 is not needed for serial communication. With this setup I can control the actual motor by sending values from 1 to 127, and I can monitor the signals that get sent to a motor by sending values from 128 to 255.

So that's the circuit, here it is built:

Arduino connected to Sabre Tooth, controlling a 12V DC motor.
All pretty simple so far, and now for some equally simple code:


#include <SoftwareSerial.h>

SoftwareSerial MotorSerial(3,2);

void setup()  
{
  MotorSerial.begin(9600);

  Serial.begin(9600);
  Serial.println("Hello"); 
}

void loop()
{
  //gradually take motors from full stop to full reverse
  for(int i = 64; i >= 1; i--)
  {
    MotorSerial.write(i);
    MotorSerial.write(i+128);
    delay(100);
  }
  
  //take motors from full reverse, back to stop and then to full forwards
  for(int i = 1; i <= 127; i++)
  {
    MotorSerial.write(i);
    MotorSerial.write(i+128);
    delay(100);
  }
  
  //take motors back down to full stop
  for(int i = 127; i >= 64; i--)
  {
    MotorSerial.write(i);
    MotorSerial.write(i+128);
    delay(100);
  }
}

In the setup function I simply initialize a software serial connection, which is transmitting via GPIO 3 at 9600 baud. The main loop simply sends different values to the motors to slowly get to full speed in one direction,  then gradually go to full speed in the other direction, and eventually come back to a stop.

And finally, a video of it in action:


All good. Massive thumbs up to Dimension Engineering - this piece of kit isn't just really powerful - it's really easy to use. Not the cheapest of controlellers, but I'd highly recommend it if you're willing to spend a few pounds.