Sunday, 21 September 2014

Progress without actually doing much

Tonight we managed to get a new vacuum head laser cut. It was only a small job, but seemed to take ages to get just right.

Since the last one had problems with a single elastic band being too tight, and two bands being too slack, the new design incorporates an adjustable height mechanism. This way, we can add just enough tension in the bands to act like springs, to get the vacuum pen to return, without overwhelming the puny little 9g servo we're using.


Straight off the laser cutter, and straight onto our cnc pick-n-place machine. Now, by slackening off the top nuts, we can adjust the height of the top piece by rotating the nuts (screwing them either up or down the M3 bolt connected to the bottom piece) immediately beneath it. This worked surprisingly well.


We also adjusted the size of the holes in these pieces - dropping them from 10mm to 9.4mm. We measured the barrel of the pen with some digital calipers and it reported that the width was around 9.4mm (they were only cheap calipers, and tended to vary between 9.35mm and 9.48mm along the length of the pen!)

With the new, tigher-fit holes, the pieces lock around the pen barrel using just the friction between the mdf and the pen (is this what is often called an interference fit?). Anyway, the result is quite pleasing - as the servo arm lifts, the entire pen lifts also. When the servo arm goes down, the pen snaps back into exactly the same place, every time.

This did get us thinking about how it would actually work in operation.
So far, we've not given much thought about rotating pieces when placing them on the PCB. In fact, since this machine was only every designed to be semi-automated (it will pick up a piece and place it over the correct place on the board, then wait for an operator to confirm the position is correct - jogging the head up/down/left/right if necessary - then hitting a button to actually drop the piece down) we thought that simply rotating the pen by hand would suffice to begin with.

But now things have got a bit tricky.
When the pen was a very loose fit in our pen-raising mechanism, this would work fine. But with a tight, snug fit, it's not really possible to rotate the pen at all now - as it would require the attached elastic-band-and-servo assembly to be rotated also.

The obvious answer is, of course, to ensure that the component to be placed is facing the correct way around before the pen picks it up. Which in turn means that our automated parts feeder - which worked so well in earlier trials - is effectively redundant. So we're actually making progress by removing parts of the machine. This is the kind of progress we like - improve things by simplifying them!

It's not unreasonable (although it feels like a bit of a cop-out) to have the vacuum head simply move to a "ready" location, and present it with a component (already turned around to the correct orientation) before switching on the vacuum pump, to draw the piece onto the travelling head.

How the component is prepared can be developed as a separate, independent part of the project. To begin with, we could even just place the component on a piece of board and move it - by hand - into position, under the head, before starting the pump-on-head-up-move-to-position-wait-head-down routine. In future, we could develop a "component preparation" module for the pick-n-place machine, which would automatically wind the next component from the reel, and rotate the component (rather than rotating the head) ready to be picked up.

But for now, we can actually make further progress with our machine by taking that bit out and worrying about it later.

In fact, were it not so late, we'd probably be ready to give the machine it's first test run: we've got x/y axis moving nicely now, the entire pen moves up and down with the servo, the vacuum pump can be triggered manually when required, and the components can be presented to the head, rather than have them pulled out of an automatically fed tape.

The firmware needs a bit of revision (it's currently using a function-blocking serial-poll method of getting data, which is just plain shonky) but that's all that's really stopping us from giving it a spin. So maybe tomorrow night we'll get the firmware updated and perhaps after that look at building a nice application to run it from a desktop computer.

Hardware based, interrupt-driven serial/uart data parsing here we come.............

Friday, 19 September 2014

Vacuum head fail

It's been a little while since we managed to do any work on our CNC pick-n-place system. With real life and work and the Scottish Referendum getting in the way (ok, maybe not the referendum) there's not been much activity on this little project for over a week.

And - given we've got some screens prepared for printing multiple copies of our board game PCB - it's time this was finished so we can start using it to populate circuit boards with SMT components!

So far we've got our x/y axis moving and an SMT parts feeder running. Now we just need to connect up our vacuum pen and lift it up and down, and we're ready to try the whole thing out!

For our z-axis (pen up/pen down) we're planning on using a servo. This worked well for us on our CNC drilling machine of a few years back, but it's going to need a little modification. For the drill, we wanted to force the head of the drill beyond the surface of the piece being cut (so that the drill would in fact drill a hole in the piece). For our pick-n-place, we want to put our SMT component on the top of the board, but not try to ram it all the way through!

Because we don't know at this stage exactly how thick each of our components is likely to be (IC chips are likely to be thicker than 1206 resistors for example) we can't be sure, beforehand, how far down we want to drive our servo, to place the piece on the board. What we were looking for is a spring-loaded system, so that we can raise the pen/head up, but when released, it returns (downwards) under spring tension. When the component is on the surface of the PCB, the spring can't ram the piece any further down into the board.

This simple modification should mean that we can easily accommodate SMT components of varying thickness.

Of course, being cheap, and looking for an easy win, we replaced springs with elastic bands, mounted the servo onto a pen-holder, and dropped the vacuum pen into place:


When the servo is activated, it lifts the pen upwards, against the tension in the elastic bands. When the servo goes the other way, it does not drive the pen downwards - it simply moves out of the way, and allows the elastic bands (springs) to pull the pen back to the surface. If the tip of the pen plus the component it is holding is resting on the PCB surface, the elastic bands can't actively drive the pen tip any further downwards (potentially damaging the tip of the pen).


Despite it being a historic night for British Democracy (the Scottish/UK referendum was taking place) a few of us turned up at BuildBrighton last night and tried the vacuum head assembly on the actual CNC frame.


The results were less than impressive.
It turns out that the tension in the elastic is too great for the servo to overcome. So when trying to drive the head upwards, you can hear the little 9g servo straining - but there is no movement.
Remove the elastic bands, and it can flip the pen holder attachment up easily (though without the bands to offer some resistance, the pen sometimes jumps out of the holder!)

We tried using two rubber bands (making them longer, and thus putting less strain on the servo). This worked, but two bands tied together were simply too "floppy". So we've decided to try making an adjustable height mechanism on the pen holder. By adjusting the height of piece that the elastic bands connect to, we should be able to adjust the amount of tension in the bands (and thus, make it easier/more difficult for the servo to lift the head).

We also need to change the way we drive the servo, in our firmware.
At present, the servo does not "lock" into place. We issue our 20ms pulses to get the servo to move into position, only long enough for the servo to move into place. During this time, the firmware does nothing else. This means that once the servo is in position, it is not longer being actively driven into place (and can be moved, by hand - or by the tension in the elastic bands - into a new position). We don't want to use a timer on the PIC to re-issue the servo position every 20ms, as this might interfere with our (non-buffered) serial read instructions, and result in garbled data.

So we're going to create a dedicated driver board, just for our servo. It will be a cheap PIC based board, with it's own dedicated timer, driving the servo to a new position every 20mS. This will cause the servo to lock into place, and will also mean we don't have to worry about running everything off one chip, and worry about interrupt routines colliding and potential data loss.

Last night felt light a we'd failed in a lot of respects. But, given that we came away with a whole load of ideas on how to get the head working, it was actually quite a productive night. That doesn't quite seem right - getting something done on a Thursday evening... Maybe we can convince the Scottish Parliament to hold a referendum every Thursday, and see if it makes our other Thursday nights a bit more productive too!



Sunday, 7 September 2014

More pick-n-place feeder testing

Our earlier trial for a feeder worked ok. But was a bit wonky at times. The tape could easily jump off the sprocket, and as the motor span, the tape wouldn't necessarily advance properly.

So this afternoon, it was down to the Nerd Unit to carve out some new designs!
We stuck with the same principles - it seemed to work, after all - and just made a few slight changes to improve performance.

Firstly, we reduced the number of teeth down to 20. This reduced the overall size of the cog, which we weren't thrilled about - but it did mean that the mounting bolts for the motor were no longer in danger of catching on the teeth/tape as it passed through.


The height of the channel that the tape travelled through was reduced from 3mm to 1.3mm, so that the tape would  be pushed closer to the teeth of the cog as it rotated (and it had nowhere to move to, veritcally, so reducing the chance of it skipping off the teeth).
We also removed part of the top of the feeder, so that we could push the sides of the device closer together, but still gain access to the surface-mount component (in this case a 1206 resistor).


A small shim was placed in the top channel of the feeder, to reduce the amount of room the tape had to move left-to-right.



Now the tape couldn't move left-to-right, nor up-and-down as the sprocket rotated, it was time to try the new design out....


The result was a much smoother, more accurate tape advance feeder. The teeth engaged with the tape every time, and the tape advanced with no slipping or missed feeds. Except....

We forgot that with our smaller sprocket, with fewer teeth, we needed fewer steps to make the tape advance by the 4mm between each component. A quick bit of maths told us:

The stepper requires 4096 steps for a full revolution (according to the datasheet) but we're using single-stepping, not half-stepping, so this is 2048.

2048 / 20 = 102.4 steps per 4mm distance.
After a few tries, we got it almost right. But every now and again, the tape would advance too far. Even allowing for the rounding error (we would make the motor move 102 steps twice, then 103 steps every third time) the tape wasn't advancing quite correctly.

We soon discovered that our stepper motor wasn't quite performing according to the datasheet. Maybe it's because we're driving it directly from a 12v supply (the same as the steppers on the x-y chassis) but 2048 steps seemed to take the motor just beyond one complete revolution.

We coloured one of the cog teeth (so we could see where it started, and where it ended up) and made the motor spin 2048 steps. After a number of trials, the coloured tooth definitely appeared to be further round that from where it originally started.

With a bit of Steve-coding (trying different numbers until something appears to work properly) we discovered that 2036 was the more likely value to get a true single revolution. Now 2036/20 is 101.8 - which means that some times we should be using the value 102 and sometimes 101. For a small number of components (up to, say, 100) the difference is probably negligible. But over time, that cumulative error could make the alignment of the components and the picking head go all to cock.


We'll hack in some nasty Stevecode to get around it for now. And maybe a more permanent solution might be some simple jog buttons on the feeder - so after we've filled one board with it's resistors, we can jog the feeder forwards/backwards to get it exactly in position before starting the next run?

Given the quality of the components we're using, we're not going to worry about getting it exactly right - our stepper motor is supposed to have 2048 steps per revolution, but it's more like 2036. There's also quite a bit of backlash in the gears (it shouldn't be an issue if you're only ever driving forwards, but gives an indication about the build quality of the motor). We're also using an mdf container, which may, or may not, create additional friction between the tape and the sides of the feeder, which the cheap, low-quality motor has to overcome.

Rather than fix the problem properly, with decent quality components and an aluminium milled body for the feeder, we'll just acknowledge the potential problem, and provide a means of correcting any cumulative errors quickly and easily (a method which may still be necessary, even with expensive, top of the range parts too!)

More pick-n-place testing: feed roller

There was a bit of debate about how to do the tape feeding mechanism - and whether we should even have one at all. At first we were going to have a manual tape advance (i.e. you placed the tape on the base of the machine and after each component had been taken out, simply pulled it by hand to get it into position, ready for the next time). But this was deemed a bit lame.

So then we thought about having pinch rollers - simply feed one end of the tape into a mangle-like pair of rollers, and drive the bottom roller a set number of revolutions, in order to move the tape forward. This seemed like a great idea, except if the tape is not fed exactly straight into the rollers, by the time five or six components have been dispensed, the tape could have wandered laterally across the rollers.

So, the more complex, tractor-feed device was designed and cut from mdf.


We found a website which demonstrated the "standard" measurements for SMT tape reels. Apparently, there was a standard, but it got complicated adhering to it, with all the different tape and component sizes, so it was abandoned. But most SMT component manufacturers still use the most commonly used pitch widths and hole spacings, so we stuck with those.


We created a simple gear, with 24 teeth (it seemed sensible to go with a multiple of 8 for some reason and 16 created a very small gear) and set the tooth pitch at 4mm. Because the gear has to fit inside holes not more than 1.5mm across, we had to adjust the image in Inkscape a little bit, and cut the final gear, not from 3mm mdf, but from 0.8mm birch.


A crude test, but it looks promising - the strip of 1206 resistors fit perfectly around our feed wheel.
The idea is to have the tape enter and exit from the same side of the feeder, so we built a simple track around which the tape would bend.


The other side of the feeder is then clamped in place, holding the tape between the "runners" built into the frame. At present we have only washers and bolts to set the spacing between the two sides, but it seems to work well enough.


One of our trust 28BYJ-48 super-cheap motors will provide the driving force. These motors, from memory, have a large number of steps per revolution (internal gearing means it's something crazy like 2048 or 4096 steps per revolution!). Since we're always driving in the same direction, we don't have to worry so much about backlash, like we did when we used these motors on our super-cheap cnc-drill.

Here's our SMT parts feeder during the very first trial run


The spacing isn't quite right for the tape - our slot is much wider than the tape, allowing it to "wander" and not quite line up with the teeth on the gear. But for a first test, it's very encouraging.

Here's the feeder advancing by approx. 4mm per command.
Since our tape has a single resistor placed between every hole, we know that they are exactly 4mm apart. Other components and other tape manufacturers may vary, so we need to allow the number of steps to advance to the next part to be variable, as well as to cater for different tape widths.


Thanks to the 28BYJ motor, advancing to the next part in the reel is actually very quiet. Not something we were even considering, but it's a pleasant surprise!


MDF framed pick-n-place moving

Last week, we hacked together an mdf-based pick-n-place frame. Actually, it's just a bog standard x/y cnc axis, but it's going to form the basis of our pick-n-place machine, so that's what we're calling it. We hooked up our stepper motors to some L298N based (dual H-bridge) driver boards and using a bit of investigation, worked out the required coil-activation sequence (by putting power onto each of the IN1, IN2, IN3 and IN4 pins on the board, in sequence, until the motor rotated smoothly without jumping).



Once we had our coil-activation sequence (in our case, it was IN2, IN3, IN1, IN4, to get smooth, single-step rotation) we simply cobbled together some firmware which would accept serial data, and activate the stepper motors.

Our principle of moving is simple:
The PIC microcontroller (we went with a massive 16F877A because a) we had loads hanging around and b) they have loads of i/o pins, which gives us scope for expanding and using limit switches, parts feeder and so on, without having to expand the mcu) accepts serial data in the format -

zero byte (start of message marker)
command byte (value of 0x01 tells it what follows is position data)
parameter data (changes depending on the command byte sent).

When we send a command byte of 0x01 (positional data) the mcu simply compares the incoming data (the destination co-ordinates) with the currently stored x/y/z data. If the destination value is different to the current value, for each of the axes, the mcu drives the stepper motor one step closer to the destination value (updating the x/y/z position values along the way).

While any of the x/y/z destination values are different to the actual x/y/z positions, the mcu displays a "busy" indicator (for our example, we use a red LED). When the controller sees all axes are in their appropriate destination positions, it lights a "ready" indicator (a green LED) and sends a single byte (0xFF) back to the controller - like a "clear to send" indicator.

The video below shows the CNC being tested with the serial-based firmware



During the video you can see the command sequence
00 01 02 00 02 00 00 00 being entered

This tells the mcu:
00 - start of message
01 - position command
02 00 - set the x axis to 512 (the two byte value represents a 16-bit integer)
02 00 - set the y axis to 512
00 00 - do not move the z axis (we don't actually have one attached yet)

When the data is sent you can see both axes move at the same time.
As they are both increasing one step at a time, they both move together.
It is possible to update just the position of one axis - in this example, we changed the value of the y-axis and the x-axis remained in it's unchanged position (we also got the wrong steppers connected to the x/y pins: we tend to think of the bed as the y-axis and the gantry as x, since we normally position the cnc with the gantry going "across" our viewpoint, but seeing them the other way around is equally valid, depending on where you consider your x-axis).

At the end of the video, you can see the y-axis crash into the end of the gantry, and hear the belt slipping. This was a mistake in the data entered - we set the y-axis to 0x2000 instead of 0x0200 (in decimal, that's the difference between telling it to move 8,192 steps, and 512 steps!). The video ends just as we pulled the 12V supply from the motor controllers, to avoid damaging or stretching the belt.

We're only using single stepping (activating the coils in a simple 2,3,1,4 sequence) rather than microstepping. Whether or not this gives us the accuracy for placing components we need remains to be seen - 512 steps seems to move the carriage quite a distance (though we could go from 4 single steps into 8 micro-steps, using the "inbetween positions, by activating two coils together, to give better accuracy if it's needed).

From testing though, it looks like the next job is to add some limit switches on the end stops!



Monday, 1 September 2014

28mm terrain buildings in FreeCAD

Having spent a few hours getting familiar with FreeCAD, we decided to create something actually useful: some exploded diagrams of how to construct our 28mm wild west buildings. Having taken out the mistakes we found during assembly, we just need to finalise the designs - add in a few more tabs, to make construction just that little bit more intuitive - and we can create 3D models of all our buildings.

Starting with the simplest (and before we added in extra locating tabs, d'oh) we managed to put together a reasonable 3D model of our "bank" building


A few components got accidentally deleted, as we battled with ungrouping "compound parts" (simply delete the overarching compound and the component parts become individual again) but the end result was quite impressive, for our first real venture into creating 3D models (rather than just re-positioning models created by someone else).

So now we just need to decide where to add in the extra locating tabs, and we're ready to produce some step-by-step assembly guides - complete with 3D exploded diagrams!

FreeCAD for assembling 3d laser cut shapes designed in 2d in Inkscape

During the construction of our cnc frame (for a pick-n-place machine) we had a number of revelations. The first being that we're actually not that great at realising 2D drawn designs in 3D!
All too often, we'd line parts up and realise they were out by about 3mm - usually the thickness of a piece of mdf, where we'd forgotten to allow for abutting edges or to compensate where one piece meets another.

Rather than go to the trouble of cutting and assembling (and later, trying to fudge, fix, and eventually throw away) pieces, only for them to end up in the bin, it'd be far easier - in the long run - to assemble everything virtually, on the screen.

Steve does this a lot, using 3DS Max. We looked at that a few years ago, but it has far too many buttons for us! What we needed was something simple to use. Google Sketchup is great for layout out shapes into a 3d design - we'd already done this quite a bit with our spaceship terrain a few months back - but it doesn't have the ability to import and extrude your own CAD drawings; everything has to be created from scratch in Ketchup, which is a bit of a chore.

You can import your own drawings in Sketchup, but it requires a Pro licence - costing about £500. So we need something simple, and cheap, to create our 3D master pieces.

OpenSCAD is a popular 3D package used by a lot of nerds and geeks and is great for creating shapes using a programmatic approach, for boolean operations, additions and subtractions and the like. It can import flat svg files and extrude them, to create 3D models from 2D cad files. The only issue with this is programmatically placing each shape gets complicated, very quickly!


So we need something easy, cheap, able to import svg (or other vector formats) and with a simple interface for moving the pieces around.

Luckily FreeCAD ticks all the boxes! Of course, like starting out with all new applications, the interface takes a bit of getting used to, but it's actually really easy to turn a 2D CAD drawing into a 3D representation of the project. To start off, simply import the SVG of the CAD drawing


Now, make sure the drop down menu is set to "Parts" (for parts editing). Without doing this, half of the toolbars either disappear, or are greyed out. With all of the CAD drawing selected, hit the "extrude" button (a box with an up-arrow against it) and enter the height 3mm. The CAD drawing will magically become a 3D image!

Even if the CAD drawing has "removed parts" from planes (e.g. a drill hole cut into a rectangle) these don't come through in FreeCAD. The shapes exist, but they need to be removed, using a boolean operator. Luckily this is easy enough. Select the part you want to keep, then - holding down the control key (not shift, as is common in most applications for selecting two or more parts) - select the part to be removed


Hit the boolean subtract button, and the selected piece is cut out of the main shape. It's a simple enough job, just a little time-consuming if you've got loads of tabs and slots to cut out.

With all the slots and tabs cut out, we're ready to start assembling. Having only Sketchup as a comparison, in which we had to install an edge-align tool as it doesn't have one as standard, we've no idea if how FreeCAD works is typical, but it's certainly intuitive enough to get going really quickly.

Start off by selecting a piece - the first piece selected will remain in place. Then, with the control key held, select a second piece. The second piece will be moved to join the first, stationary piece. With both pieces selected, use the Edit -> Alignment menu option


There is no toolbar for this, nor is it available in a pop-up menu, so you must use the Edit menu. This opens the alignment screen(s).


Now it's a case of stretching your head around which parts will be touching, once the second piece has been moving into its final position (strangely, the second/moveable piece appears on the left of split screen).
In this case, we want our end piece to stand up at 90 degrees to the base. Rather than mess about rotating pieces, you simply select enough points to allow the application to work out the required rotation.

In the example above, we've selected two points, which will line up the tabs on the vertical piece, with the slots in the base. But we need to provide at least one more point, to align the bottom edge of the vertical piece with the bottom edge of the base.

You can align faces, edges or vertices (corners). By selecting a vertex, you're often actually aligning two edges at once, so we tend to stick with vertices where possible - though sometimes it's handy to be able to say "this edge should run along this edge" or "this face should be touching this face" to help get the rotation correct.

After successfully aligning a few pieces, our 3D design is starting to take shape


And finally, we get to the whole point of learning how to use a completely new CAD package, and the reason behind spending hours longer in the design process - it's cock-ups like the one below we're looking to eliminate by assembling everything on screen before sending our designs to the laser cutter


We've done the classic trick of offsetting our tabs by 3mm (the thickness of the mdf) and forgetting to adjust it in other parts of the drawing. This actual mistake cost us two sheets of mdf. Not much in terms of materials costs (it would have been a lot more if we were using acrylic!) but a lot in terms of time and effort (especially since we wasted about half an hour trying to bodge/fix it, instead of just cutting a fresh piece!).

3D CAD is a great way not only to visualise the final project, but also a really useful way of ensuring everything lines up properly before even going anywhere near a laser cutter (or cnc router, if that's what you're using). This is especially useful if you're going to be using slightly more expensive construction materials.

But one of the great things that 3D CAD allows us to produce is a set of assembly instructions. So in the true spirit of sharing designs and ideas, we can now easily share instructions on how to assemble the pieces, with anyone daft enough to download our plans and use them in the first place!