It's built from 2 servos, some glue, a load of balsa wood and a random long bolt I had. The bread board that has ping/motion sensors then gets taped on top. While it's not exactly beautiful and has quite a few issues, it does do the job. I get 2 axis of movement, so I can point the sensors in any direction and take a reading.
The code to make this work is very simple, and made even simpler by the Arduino libraries. In case you don't know, most servos are basically:
- A motor and gearbox
- A feedback system, so the servo knows what angle it is currently at
- An input to connect to the micro-controller so you can tell it what angle to use
Most of the time servos are designed to be given an angle to move to - i.e 'move to 60 degrees', although you do get continuous rotation ones that give speed control instead of angle. Either way, servos are really easy to hook up, as you can see from this circuit:
Here we have the basic setup - each servo is powered off a battery, and as always they share the same ground with the Arduino. The signal inputs for each servo are then plugged into IO pins. I'm thinking maybe there should be a resistor in between to minimize current draw from the Arduino, but I'll check that out with the Ammeter next time I'm using it.
To control a digital servo you simply send it a square wave - a PWM (pulse width modulation) signal. Fortunately the Arduino has built in support for PWM, and also comes with a handy 'servo library' that wraps up all the nasty bits, allowing you to write code like this:
#define servoAPin 3
#define servoBPin 9
sensorservo.write(90); //move sensor servo A to 90 degrees
sensorservo2.write(90); //move sensor servo B to 90 degrees
I'm guessing (although I haven't tried) that the pins you give to a servo controller need to be PWM pins, so the servo keeps getting a signal. That's a guess though - should probably try it out and see - maybe the servo doesn't need a continuous signal?
After a bit of fiddling I add a bit of code that goes through every possible angle, as though it's doing a sensor sweep and here's the result - if video broken it's here etc bla bla bla :)
Next, at each orientation I add the code to take PING distance reading and print the value out to serial. This gives me a raw list of numbers I can copy and paste into excel, yielding....
This is a sensor sweep repeating 3 times. The graph shows the distances that the PING sensor detected as it scanned from left to right across the room. Once the PC is doing the work I should be able to build up a 2D image using the 2 axis sensor platform - Yay!
Few basic conclusions I came up with from the prototype:
- Need to make sure the sensors (especially PING) aren't obscured at any orientation by the stand itself
- Dual axis is awesome and well worth it and also cool
- Ideally the sensors are fairly high up, so half of what you see isn't just the floor
- High potential for cuteness provided whatever is on the platform looks like eyes....
- The servos need to be as close together as possible, to avoid angular changes affecting the physical position of the sensor
That's it for now - hopefully building robot soon. In the mean time I'll probably get things working nice and remotely (i.e. so my PC can control everything) so I can write a bit of fancier code