raffe

Electric Giraffe Technology

Raffe-Tech has Moved
raffe
raffe_tech
This journal will no longer be updated, new articles will be posted directly to the Electric Giraffe's website:


Servo Driver / Current Sensor
raffe
raffe_tech
I've been designing a very simple new circuit to control the servos in the forthcoming new neck.

Each joint calls for a two channel servo driver, and I decided to add current sensing capability to this.  By continuously monitoring the current drawn by the motor, the circuit should be able detect the increase in current that occurs when the motor is stalled - because the neck has hit an obstruction or the mechanism has jammed - and shut down the servo drive before too much damage is done.

The circuit is split into three parts: Firstly, a current sensing resistor; second, a low-pass filter; thirdly, an amplifier.  The output from this is then fed into a standard CAN (Controller Area Network) circuit driven by a PIC chip.



The principle of measuring current with a current sense resistor is very simple: you put a low-value resistor in series with the power supply, and measure the voltage across it.  The resistor can be placed either at the power supply's positive terminal ("high-side"), or negative terminal ("low-side").  Using the low side is slightly simpler as one end of the resistor is grounded.  It has some disadvantages (the ground voltage level for the circuit being sensed is raised up by the voltage across the resistor, and it cannot measure if the load is shorted to ground), however those aren't a problem for this application.

The current flowing through the motor passes through the current sense resistor, developing a small voltage of V = IR.  I have estimated the maximum servo current to be 5A (this will be confirmed when I get the actual servo specifications).  With a resistance of 0.05 ohms, this will give a voltage range of 0 - 0.25V for a current of 0 - 5A.

The power rating of the resistor is important here.  Power is calculated as P = I2R, so at 5A this would give me a power rating of 5*5*0.05 = 1.25W.  This is the minimum wattage for the current sense resistor.

Before being amplified, the signal passes through a 7Hz low-pass RC filter.  This is simply a 220 ohm resistor and a 100uF capacitor arranged so as to block any high frequency noise that may be present on the sensor, for example voltage spikes caused by the servo motor's operation.  The motor will only need to be sampled a few times per second, so I chose 7Hz as the cut-off frequency for the filter to avoid any aliasing effects when sampling.  Aliasing occurs when signals are sampled more slowly than half their maximum frequency component, and causes the high frequencies to appear as if they were low frequency changes, giving you an erroneous result.

The next stage is a non-inverting amplifier.  An amplifier is necessary here because the chip's analogue to digital converter is not especially precise, so amplifying the signal from 0 - 0.25V into the range 0 - 2.5V allows me to use more of its range, giving a more precise current measurement.

Because the amplifier output needs to operate down to zero volts, I chose the LM358 dual operational amplifier.  This 8-pin IC contains two amplifiers with an output swing of 0V to Vcc -1.5V.  Normal amplifiers cannot drive their output to the power rails, so a "rail to rail" amplifier is needed for an application like this - however in this instance I only need to include the 0V rail, so the LM358 will do the job just fine.

The two feedback resistors are arranged to give me an amplifier gain of 10.

Finally, the signal passes through a 20 ohm resistor before being fed into the PIC chip's analogue to digital converter.  The 20 ohm resistor is recommended to ensure the amplifier remains stable when driving a capacitive load.

Oops
raffe
raffe_tech
This is what happens if you forget to restore your transformation matrix after doing a rotation in OpenGL - oops!
 
Tags:

Software Updates
raffe
raffe_tech
There are a couple of things that have been bothering me about the software.  First is the lack of multi-threading: the UI and the pattern generation are done in the same thread, meaning that if the pattern generation runs slowly (for example because of heavy processing doing beat detection or video processing), the UI might become sluggish.  The second is the rendering of the UI being done in Windows GDI.  I really pushed the GDI beyond what it was designed to do.

Even though neither of these things are a problem (the CPU is plenty powerful enough, and the UI functions perfectly) I still wanted to make the changes because, well, I'm a bit of a perfectionist.

I decided that it was finally time to bite the bullet.  I have split the frame generation off into its own thread so it can now be run on a separate core to the UI, keeping the UI nice and responsive.  The difficulty here was ensuring everything is synchronised and thread-safe, but a sprinkling of critical sections here and there have got it covered.

Replacing the rendering engine is a much harder prospect.  At the moment everything is written using Windows controls (they're owner drawn so that they have their own visual style, but they're still standard components.)  I'm going to use OpenGL for the rendering, and scrap all the Windows controls.  This means that I have to write from scratch all my own UI widgets like buttons, checkboxes, edit boxes, list views... the works.  It's a huge task.  I also have to do all my own message handling, creating the whole windowing framework, processing mouse and keyboard messages - everything.

I've been working on it for a few months now and it's starting to take shape.  I have implemented the basic OpenGL rendering engine, texture loading and drawing.  I've implemented a small number of the basic UI widgets: buttons, drop-down lists and scroll bars.  There is still a long long way to go, but I'm getting there.

New Sensor Boards
raffe
raffe_tech
The new sensor boards were completed in time for the 2011 Maker Faire:

 
This is the fourth iteration of the nose board, previous versions having been smashed by the lower jaw springing up into them.  Each petting zone (nose, eyes, and new for this year: under the chin) now has a frosted polycarbonate guard on top of it.  This serves three purposes: it provides a nice tactile surface for petting; it glows when lit by the new petting zone LEDs; and it protects the sensors from damage.  Previously we had simply used blobs of glue to protect the sensors, but it was ugly.  The new plates look great, are tough and durable, and also easy to remove if the circuit board needs to be accessed.

The new LEDs in the petting zones provide very helpful visual feedback.  When multiple people are petting the giraffe at once it's hard to know if your input is being registered or not because he's busy responding to someone else's input.  With the LEDs you get immediate feedback that your input is doing something, even if he can't respond to it immediately.  There was some debate over how many petting zones there should be in the nose.  Originally there were two, but last year Lindz expanded it to five.  I argued to reduce it back to two because people just cannot see the difference - they are already at sensory overload in a fair environment before they even get to the giraffe, and they just don't have the attention necessary to see details like that.  We decided to go for two zones, and I tried to differentiate them as much as possible by clearly grouping them with a large distance between them, and providing tactile feedback in the form of a ridge between the two groups.  Even so, most people would pet the whole nose at once and not try to trigger the two zones independently.

Something that came out of the faire is the need for an "interview mode" - a simple reactive mode that can be turned on during TV interviews to make sure he responds predictably and immediately while on camera.
The new status LEDs on the servo driver board were useful for keeping an eye on what he was doing, but it's possible that they could be expanded even more, perhaps into an LCD with a readout of his status.
Tags:

New Sensor Board
raffe
raffe_tech
The sensor/servo board mounted in the head has been split into two boards.  This has allowed the number of servo channels to be expanded to ten and the number of sensor channels (petting zones) to be expanded to twelve.  The prototype petting zones now have LEDs built into them so they react instantly when touched, providing people with immediate feedback to show that their petting is being registered by the Raffe.  Previously it could be difficult to tell because many people could be petting the Raffe at the same time, but of course it will only speak one sentence at once in reaction.


You are viewing raffe_tech