Tuesday, 8 November 2011

my coding thing

If you are on G+ and like coding, then the DataOrientedDesign page is the page to follow for data-oriented design things.

Monday, 31 October 2011

CNC again

After what seems a very long time, I now have to get to work writing more software.

I fixed an RC aeroplane brushless motor to the CNC, and Dremelled the shaft into a cutting bit.

I feel a bit naughty doing it, but now I can get started on the final stage of the development. All steam ahead to better software and firmware.

Okay, firmware done, now to tackle the path command stuff. I really want to build a simple UI for the setup stage. So it's easier to move the cutting head around, and get it ready to run its pattern... luckily I've been doing a bit of Tkinter work that should do the trick.

Wednesday, 17 August 2011

In case you're wondering

CNC project has stalled due to no money to buy bits. I need some parts to make the drill. The dremel is too noisy and I want to be able to turn the drill on and off via the arduino, so I'm going with good quality DC motors and trying to figure out how to mount the milling bits onto them.

In the mean time, I've been working on a new book and a new computer language. The book is about how to program giving practical examples of how to develop using the data-oriented programming paradigm. The idea is that that book will help people get a good grasp of how to do it by example, and will read and understand the sections on why OO code tends to be a lot slower and harder to debug.
The language is an incarnation of this premise too. It strips away most of the language features that allow object oriented programming and restricts the programmer into coding ready for parallelism and GPU acceleration (FPGA is planned too).

If I wasn't working on those, I would be writing simulation software for the CNC using polyvox so I could test out all the cuts ahead of time. But seeing as I don't really know for sure what is happening there until I fix the cutting head, I have let it stay patient while I get on with other things.

Sunday, 24 July 2011

Milling about

Since the backlash compensation went in I've had a lot of toothach. I'm not blaming the machine, no, I'm blaming the dentist. The toothache stopped me from doing what I wanted with the project as I've been trying to code the necessary file convertor to drive the machine via an SVG. Reading an SVG in, then recognising the parts of the path element, then figuring out the best way to handle the relative vs absolute coordinate stuff mid-stream (that struck me as quite odd), would normally be all in a day's work for me, but with my head being addled from the pain I only managed to get it completed on Friday night.

Here is the SVG2Path.py and path.py I am using right now




With said new code in place, I managed to get the machine to draw (pretty accurately) direct from a file.

So, new code in hand I decided it was time to do some real cutting. I added a mount for the dremel, added a clamp to the bed, clamped in some
of the left over perspex from the build, and attempted my first CNC engraving job.


First attempt wasn't too bad, there is quite a bit
of slop as the engraving head was dragged quite quickly across the work so there are some diagonals on the word, but it was nice to see it actually cutting. I've now added a tooling movement rate to the script so it moves slower when it thinks it's cutting.


















I tested some aluminium next, but the engraving head was useless at cutting it. This just kept aggravating me until I noticed I did have a milling
bit, a small, ball headed milling bit. So, first thing I did was set up the same run again, but when I did I found the dremel wanted to dive into the work. I didn't understand until
after I'd had to emergency stop the whole operation as
the dremel almost went through the 1.5mm aluminium when it picked up and put down again. It turns out that the battery pack I'd been using to power the steppers had finally got to the point where it could no longer power the Z axis stepper well enough to enable it to lift the heavy dremel out of the work. Of course, these are steppers, so they don't know they have failed, so when it was told to head back down into the work, it duly complied and dug down even further.



I wonder how difficult it would be to add an encoder to each of the axes just to see if I can catch this kind of error quicker. Anyway, for now, I'm just going to wait until I can afford to buy a barrel socket and plug it into an AC adaptor, and also, because of how noisy it is, I'm going to try to find an alternative to the dremel. I have a couple of 24V motors out of a printer which, when tested merely with their already attached drive gears, can cut aluminium. How to add a chuck to these, that's another question.




Wednesday, 20 July 2011

Whoops, posted this in the wrong blog.

(This was posted a while back on my non-CNC blog)

Firstly, update on what I've done:

I soldered myself a stripboard with the h-bridges. I hadn't really thought about how I was going to do it until I reached the point of doing it, so was taken aback when I noticed that my initial plan to mount the ICs in series across the board would have involved a lot of awkward wiring to make it possible to remove the ICs when I move up to a 5 axis. I had a think about it and went totally the other way with the layout, moved the IC sockets to the top of the board (strip lines going across the board from side to side) and just had the signal entering on the left and power lines out on the right. This configuration meant I only had to jump between the tracks the number of times I had to convert from signal to IC and from IC to power (plus a few for power+ and signal+) only 24 wires to solder. Easier to layout too.

Once I had the board ready, I started making sure that the arduino code was up to scratch to drive the three independent steppers. First test was just to pump the same signal to all three, which found a couple of loose connections quickly fixed, and a major issue with forgetting to drill out the tracks between the signal in and power out. I'm glad nothing exploded, but I guess the signal never got anywhere because the stepper was sinking the signal line so it never reached the h-bridge's threshold. Better luck than judgement though.

The first thing I noticed was that the new machine was an order of magnitude more accurate. I made some test scripts with circles as I'd found that normally circles are really hard to do well if your machine is not set up right. There are two reasons for this, a circle relies on very small changes in velocity, and especially around the axes, there is a good chance of any backlash effect being amplified by the very slow motion of the non-dominant motive axis. Also, any code that has to deal with speed control is going to deal with a very small small and a max speed at the same time, stretching the driver's accuracy to the limit.

The new machine does have backlash, about 0.25mm, so I coded up some backlash compensation into my arduino. Basically, this just runs the steppers at full speed in the direction of the motion until it takes up the slack if it detects that there would be any slack to take up before continuing with the real command to move the axes. This seems to work quite well, and you can see it in the video as the sudden spin when an axis slows right down and has to take up the slack before heading slowly in the other direction.

I had a bit of trouble getting the arduino to reliably call back once it had finished working. Sometimes the arduino doesn't call home to say it's finished, and that leaves the script dangling, waiting to issue the next command. I know it's not the arduino stalling as the keyboard exception in my python script (hit Ctrl-C to break the sequence) makes the arduino force the axes to head home if anything goes wrong. So, I made the script have a timeout on waiting for the callback. Now, when it's left hanging, it asks the arduino directly if it has actually finished or just forgot to say so.

Without the software backlash compensation, the circles where terrible, but with it, you can hardly see that there is any backlash at all.

With these software changes, the machine is now mostly working. The next hardware stage is to mount the dremel on the z axis and try cutting rather than drawing. But I think some more software updates first: I think I should try to add some text capability or the ability to import svg paths. Either would be great for any simple 2D engraving, but I think possibly essential for when I get to the next stage of machine rebuilding. The bit where I make the machine make the parts for the 5-axis variant.

So, just to show how noisy it is and also to show the whole setup, live and drawing, including the backlash compensation in full effect, here is a video of the machine... I have yet to name it... drawing some more calibration and test stuff.



Monday, 11 July 2011

Z axis


Got a bit of time at the weekend, so managed to finish of the Z axis on the new metal machine.

I've changed the stepper connections to tubing, X and Z are using some tough plastic fuel line from the RC cars I had, and the Y axis is using some softer stuff (also fuel line, but probably not aged into being hard).

I've got to add the mount for the Dremel (I had anticipated the weight, so I've beefed up the strength of the gantry), put the H-bridges on a PCB so I can control the steppers from my arduino, then write the control software. That should keep me busy for the rest of the week.

Tuesday, 5 July 2011

Tubing

Okay, so I'm a bit thick. The video of the desktop CNC has the rods connected via rubber tubing, which I don't have, but I had seen nice metal couples, so thought I might make my own.

Two things wrong there. Firstly: making your own CNC couples without a set of taps for making the clamping work, or a drill press for drilling out the holes without masses of error, or some aluminium in the right shape so I don't have to break something, is very very very hard. Secondly, I do have something that resembles rubber tubing. I have quite a bit of heat-shrink tubing that is overwise sitting there staring at me saying "hey, over here. I want to hug your shaft!"

So, tonight, I'm going to drill out proper bolt holes in the beds to lock the polymorph in place, and then I'm going to shrink on the steppers to the studding. That means, apart from software, I'm almost ready for a full XY demo. :)

Monday, 4 July 2011

Metal

I took the plunge, bought some stuff, and waited for it to arrive. Saturday afternoon I started, but only after realising I didn't even know where my saw was. I had to pop out for bolts twice, get a new saw, and even a new drill bit (the one I was using bent double, must have been mild steel), but at least most of the expense was on things that are reusable. Unfortunately for me, I don't have many of the tools I need, and the ones I have are Imperial, so almost worse than useless as I'd probably end up mixing and matching and making a mess of everything.

The steppers, the studding (threaded rod), the coupling nuts, the new ICs to power the steppers and the perspex all came by post from eBay sellers. The rest, I picked up from B&Q, and was surprised that it's not all that overly priced.

Working from a plan inspired by the video on how a guy built a CNC from plumbing, I cut, drilled, bolted, and filed until I ended up with an XY bed.

Adding the steppers with aluminium mounts and sticking the locking nuts to the beds with polymorph (polycaprolactone) and superglue (krazy glue or cyanoacrylate for non-US) meant I could test out the steppers.

The only fail so far has been the stepper motors not being gripped enough by the nuts even though they are filled with polymorph and then superglued on. I guess I will have to wait for the taps and dies to arrive so I can make properly grub screw locking connector collars for the stepper shafts and the studding.


Wednesday, 29 June 2011

In motion

After trying cables, first building it like a draftsmans drawing board (the criss-cross at the back design), and then more linearly with two loops, first with kevlar thread, then with cotton, I tried tracks (which you can see pictured). Two more failed attempts later, I finally gave up trying to get rid of the backlash in the Lego machine.
It's never going to be a full scale machining CNC made out of the parts I have, but, I can make one that has limited backlash by using the linear actuators that came with my digger (set 8294).

Now, with these actuators, I can't move the table as far, but it does have very limited backlash.

Also, now I have done this, why didn't I know about THESE!?

Anyway, here is a video of it in motion. About time I hear you say. Well, the next step is no longer Lego. I've got annoyed with the limitations and I went and ordered some bits. Next update will reveal more, but just one clue...



Thursday, 23 June 2011

Software updates

No pictures in this one as my only real changes have been software ones.

I started by adding more and more functions to the python file I'm using to command the CNC pen machine, but after a while I realised that the control software I'd written was really bad, and the backlash was really really bad. I hunted for an algorithm to control the motors better than they had been, and after many dead ends, found a video referencing PID control which then lead me straight to the wikipedia article...

So, I planned to implement this algorithm in my arduino, only to find someone had already done it... so, I dropped it in, and after only about an hour of tinkering, managed to get it to control all three axes with much greater accuracy and speed than I had managed with my home grown pile of ifs. Excellent, now I had a machine that was quicker and more accurate at it's own motor control.

Backlash is still a major issue, and because of the speed of the new system (the new code makes it quicker) the bendyness is more of an issue too. I set to figuring out a final solution to this problem last night, looking over my collection of lego and trying to find something that looked like it might keep backlash at a minimum, but even though I prototyped a few designs, they all had problems. Some were just clumsy, some where not large enough to provide enough motion, some where just as sloppy as the gears I'm currently using, and one turned out to be impossible.

However, there is still one technique that I haven't tried that might solve it, and that is using cables. I haven't got any real cables, but lego beams with cotton thread as my pulley and belt system might turn out to be good enough. I'll see how it goes, and use the left over pieces to reinforce the Z-axis (which has been the source of the problem with respect to bendyness)

Monday, 13 June 2011

Python Powered


The H-Bridges arrived and I almost missed my dinner due to trying to wire them up with my solderless prototyping board. After the initial frenzy I realised that to do anything real with this stuff I'm going to have to make it work without sticking wires into arduinos and actuall make a half shield for it....




That done (and that was a lot of work as I have virtually no experience in doing that amount of soldering on a small board) I took out the drill style head and replaced it with a pen grip. Thought that it might be better to start with. Anyway, after some initial playing around (and realising that when you code a controller to take int based positions and ignore any decimal
points it thinks that your small numbers are really really large) I got it to draw a circle, and a square from python (via the serial library that comes with python), and even hand-held it through drawing an 'F'.
The tolerances for lego are terrible due to the flexibility of the plastic, but it does perform the same operation over and over with little reproduction error. The square was run three times in total and doesn't look like it's been "widened" by going over a number of times.
The F shows why it's not great though, the top bar is almost diagonal, even though the motors were told to go straight, that's all due to the bendyness of the structure holding the Z axis.

Sunday, 5 June 2011

More power

I managed to get some time to work on the machine. After a little trouble trying to get all the NXT servo motors built into the frame without interfering with each other it now has powered axes.

It took a while figuring out how to get the encoder working reliably on the arduino, and because of the amount of encoder signal lines (6 in all), I had to switch over to using the arduino mega. Even that is at it's limit for hardware interrupts. After making that work, writing the code was quite simple.

It kinda works. I've tested it on the logic voltages to see if I can get it to work at all, and even though the low voltage means very little force in the motors, it was enough to prove it moved about and always came back to it's zero point. Now I've got to wait until my motor driver ICs arrive (going with L293D as it has some existing tutorials for usage) before starting to write more utility style functions for it including things like "find home" and making it keep the motors synchronised when they're travelling.

Thursday, 2 June 2011

All moved in. So, of course it's building time.

We settled in quickly and now we all live together in London. It's been hard up until now and nothing shows that I'm happy more than being productive.

Other than lots of coding bringing up my old engine inside Ubuntu, I've also started work on a Lego CNC. Initial pics show slow daily progress, but I hope to have something that can cut cheese or toast by the time the weekend is over. I hope so anyway.



Wednesday, 6 April 2011

Hoping to be together

I'm keeping my fingers crossed, but it looks like we might finally have a place to live in London. We might be all living together before May hits us. Just in time for the youngest's third birthday.