Let's Make Robots!

CNC machine v2.1 - aka "Valkyrie Reloaded"

Cuts shapes with better precision then me :D
AttachmentSize
tiny2313_stepper.brd22.52 KB
tiny2313_stepper.sch336.57 KB
serial_gcode.py_.txt730 bytes

Pictures:

 - the front 

 - the back

- left

- right

- the power unit

- and some closeups here and there

 

Description:

This is the second third version of a homemade CNC machine build using mostly off the shelve parts.

The first one aka "The beast" had a lot of precision issues due to play in most parts which in turn was caused by mostly bad cutting. Also one of the biggest problems was that when I have build it I did not think to allow later adjustments to be done. 

So this time almost every part of it allows for some adjustments. It is also easier to build due to the different design. 

Purpose: 

I have been asked many times over why I did this below are a few possible answers:

- because I wanted to see if I can 

- because I like doing this kind of stuff

- because I think such a machine is useful

- because I want to use it to mill PCB's, I'm tired of messy etching, bad exposure, bad transfers ... etc

- because I also want to build some other stuff and I need precision

- because I learned a lot building it

- because maybe I can make some money out of it in the end 

- etc, etc ...

Technical details:

- 250 by 160 265 by 225 mm maximum work area

- 50 by 35 by 35 cm machine size (could sit on my desktop :))

- with the material I have tested (laminate wood pretty tough material) it can cut at around 80 to 100  100 - ? (must still find out maybe as high as 400) mm per minute

Construction materials:

The main material used is 16 mm MDF - I used about a square meter all together.

The rails are 10 by 20 mm aluminum corners used for ... I don't know for what but the margins are slanted at an angle - I used 3 meters of it.

The lead screws are standard M8 type threaded, nothing fancy - 3 meters.

The bearings used are two types because I did not have enough of them, but you can get away with ABEC7 bearings - 16 for the X-axis + 8 for Y-axis + 8 for Z-axis + 8 for the lead screws = 40 bearings.

The motors I used are 7.5 degrees per step, 24 volt, canstack stepper motors, the kind you should find in almost all older printers. 

The electronics used are all home build. The brain of the machine is an Arduino (the single sided version), and the motor drivers are created around Attiny 2313 paired with an l298. 

The wires used are CAT 5 pairs used for power, and pairs from an old SCSI flat cable for data. 

The screws used in the construction are standard M8 of different lengths and M6 screws to fix the rails.  

Mechanics:

A. Lead screws

The design is as simple as it gets, it is all based on lead screw transmission.

I chose to use this kind of transmission because it has three advantages:

1. Force ratio is high - to move the nut along the screw the rotational force applied is low compared to the output. That allows the use of those small motors

2. Precision - even with the large step angles provided by the motors I still get pretty good sub millimeter precision: 76,8 steps/mm - good enough for my requirements for now at least.

3. Ease of implementation - you only need two bearings at the ends of the screw, two normal nuts to hold it in place, one long nut to move around. 

The linear rail system allows the axes to move freely along their axis and ensure there is no side load on the lead screws.

B. Rail system

On this machine the linear rails are using a different system as on the first version, inspired by the new version of the CNC machines created by the guy here. Obviously the new system is a lot easier to implement than the one before due to it's simplicity. The only drawback is that it requires a strange type of bearing called a V-groove bearing which comes with a V shaped groove along the center of the other housing. I could not find any of those, so I used a pair of normal bearings put side by side to create a small groove in the center.

Electronics:

The electronics of this thing are composed of two parts: the Arduino board and the motor boards.

The Arduino is just a standard single side board, not much to say about it, if you want to build your own see here.

The motor boards I designed myself, they are based on an Attiny 2313 and l298. You can find the schematics below.

I have built my own controller because I did not want to have a mess of wires around the machine from the Arduino to the drivers. This way I can control all 3 axis by using just two wires trough the I2C protocol. 

Software: 

The software is divided in three parts: 

- pc side

- Arduino side

- motor controller side

On the pc side I'm using the excellent Inkscape to draw the shapes, and a plugin to convert them to G-Code coordonates. Then I'm using a simple python script to send the G-Code to the Arduino, over the serial link. 

On the Arduino I have a modified version of the code from the RepRap project (www.reprap.org), adapted to use I2C to command the motors instead of driving pins directly. 

On the motor controller side the software takes different commands trough I2C and executes them. 

Open source:

All code and driver schematics are available here:

http://github.com/TinHead/Valkyrie-CNC-source-code

 


Please ask for more info, I will add it, I do not have anything more on my mind now. 

 


Update 15-Aug-2009 - hit a wall ...

I clearly remember updating this page about 2 -3 weeks ago but I must have been drunk ... O.o

 

I was saying back then that I still have an issue, that sometimes the I2C bus seems to bail out causing the machine to stop working. 

I was finally able to do some testing last night  and I managed to replicate this "bug" and the conclusion is that it only happens when the machine is under load, i.e. cutting something.

The question remaining is: Why? Is it a power issue? Wiring issue ?

No idea ...  currently it uses a single 12 V rail from the ATX power source, I'm  thinking on rewiring this fellows power lines to use one rail for each motor.

Ideas anyone? 

 


Update 18-Aug-2009 - Here comes the source code

 

As promised I have made the source code available to the world. I do not like the way Drupal handles attachments (does not accept archives), so I decided to upload the code on GitHub. 

Git (http://git-scm.com/) on which GitHub is based is a very nice version control system and pretty easy to use. 

I have created a GitHub account, you can find my page here:

http://github.com/TinHead/Valkyrie-CNC-source-code/tree/master

To download the source code as a ZIP or TAR archive you can click on the  "Download" button :)

For hardcore geeks install git and clone the code with: 

git clone git://github.com/TinHead/Valkyrie-CNC-source-code.git 

Have fun with it, clone it, fork it, patch it, optimize it ... eh write it in assembly if you wish.


Update 28-Sep-2009 - Some revelations

Lately I spent my time trying to understand the timers of the Attiny 2313.

While playing around with different PWM setups and frequencies I found out two things:

1. timers are not easy, but they are very useful beasts

2. why I could not get microstepping to work on the Valkyrie 

While  1 is pretty obvious, 2 requires some explanations:

- microstepping requires that you adjust the power on the motor windings  in such a way that a full step (say 100% an winding A and 100% in B) may be divided in multiple smaller steps.

- to achieve the above PWM has to be employed on the H-Bridge enable pins

- if PWM is employed  and you drive the motors at their nominal voltage you loose torque so microstepping is a no go, the stepper might microstep without load but not under load (the PWM frequency plays an important role here, higher frequencies tend to amplyfy the problem)

- so the solution to be able to microstep is to have the motors powered at a (much?) higher voltage than the nominal voltage and apply PWM with the right frequency (which sadly varies from motor to motor) to control the power.

 In my case the motors have an assumed  nominal voltage of 12v (based on datasheets of similar motors) and I'm driving them with 12v -> no microstepping possible. 

I have two options now:

- change the motors with 5v motors

- redesign the controllers to allow higher voltage input, the caps have to be replaced.

 PS: I know this stuff is nothing new, I'm practically reinventing the wheel, but this is what it takes for me to really "get it" :)


Update 25-Nov-2009 - All work and no play makes TH a dull boy

Long time no update, sorry got lost in todo stuff and never finished the todo stuff ... bah.

Things I managed to do:

1. Redesigned the motor driver with the following things in mind:

- used a ground plane to reduce some noise

- linked all inputs of the L298 to PWM capable pins on the Attiny 2313

- moved the enable inputs to non PWM pins because of the above

- the driver is designed with two layers now ... looks nicer but it is also harder to build

- replaced power and motor pins with screw connectors so it is easier  to connect the wires

- motor power is now independently routed so the driver has one power input with a voltage regulator for the logic and a separate one for the motor - on the logic power input you can use up to 12v (to be safe because the caps are 16V) on the motor up to around 40v.

- fixed a problem with the reset button in the schematic, now the reset works as it is supposed to. Before it would actually create a short, it worked but not really as it should have been.

- changed the diodes to schottky type, SB560 (not sure if they changed anything yet, but they do recommend them in the l298 datasheet)

- rearranged stuff around, I tried to follow the advices of B0SC0 on this, thanks B0SC0 :)

2. On the software side:

- found the problem with the Arduino code limiting the speed of movement (actually John_NY lead me up to this, thanks John)

- implemented full torque halfstepping on the driver trough PWM (still testing that) 

Things I did not managed to do (in random order):

- really get into XK-1 to use it instead of Arduino for the XMOS challenge  - needs lots of work I only got to blink a LED on it for now

- implement microstepping ... the short version is that it kind of works but totally unusable I think the torque loss is just to great or something, or a problem with my code.

- create two more new drivers to put them on the Valkyrie 

- implement home sensors on the axes to home the machine 

- work on the plastic extruder - still just an unclear recurring idea in my head

- squash the I2C lockup bug - but I have some ideas now

- other random stuff not related to Valkyrie


I will update the git repository with the new stuff soon, and also add the v1 controller re-designs by B0SC0 and John_NY in there.


Update 06-Dec-2009 - Bigger motors => bigger problems

 

So I finally got my hands on bigger motors with the kind help of a friend. 

These guys  are bipolar 1 Amp per coil 200 steps per revolution motors. Very cool Japanese motors. 

But there of course to use them I have to recreate the motor holders 'cause  those ones have a very different mount... 

Also driving two of them with one driver for the X-axis... seems risky to say the least, an early test proves that they can easily blow up my driver and melt the hell out of CAT5 type wires because of current draw. I'm now considering trying to use a really big radiator on the Xaxis driver, and if that fails building a special driver for the Xaxis with two L298's on it.

Looks like I will never get to finish porting the code to the XK-1 this year  ....

 


Update 20-Dec-2009 - Moving forwards to 2.1 (?)

So bigger motors are here (yey!) but not in use yet ... as usual I got side tracked with other stuff ...

The new ones need other mounts, and I just can't find an easy way to adapt the current mount for them. So I decided to delay mounting them, and go on using the old motors until I have a working machine which can do the mounts for me :) 

Had it too long on my TODO list: New Z axis, to really take advantage of the Y axis length. As it was it "eat" about 100 mm usable workarea, just by the sheer size of it so I was pondering for a long time to fix that. This actually happened this weekend because I broke the old axis. So I had to rebuild, and I gained the missing mm on the Y axis  :D

Also on my TODO was having some kind of home/eol sensors to make it easy to home the machine and stop it before destroying itself while trying to go further then possible. The drivers were designed with this in mind but I never got to try/test it. So today I finally got the drivers to respond back over I2C so they can yell "Hey I'm home already !" back to the Arduino. Which is very cool :D I'm going to implement this in the code ASAP.

One other thing waiting in my TODO is to try making an thermal plastic extruder as they have on the RepRap machine as a second tool for the Valkyrie, I was finally able to take a few steps in that direction. I played with a thermistor for the first time, and got it to show the room temperature properly, but not higher temperatures yet... I have no comparison to check it against.   

And finally it looks like I'm going to hit the limits of the Arduino  pretty soon with this project, I think reimplementing the extruder and the end stops will fill the rest of it up ... so I have to start working on the XMOS or get an Atmega 368 ... which I cannot seem to find locally ...

That's it for now, stay tuned .. 


 Update 21-Dec-2009 - Pythons

 There have been several requests for the python script I use to send the g-code over to the Arduino trough the serial connection. It requires python and pyserial installed to work.

Here we go:

<code>

import serial,sys,time
serial = serial.Serial('/dev/ttyS0', 19200, timeout=1)

def check_conn():
    serial.write("G21\n")
    if serial.readline().strip()=="ok":
        print "Connected"
    else:
        sys.exit("Serial connection could not be established")

def send_line(line):
    print "Sending "+line
    serial.write(line)
    response = serial.readline()
    while not response:
        time.sleep(1)
        response = serial.readline()

def main():
    try:
        filename = sys.argv[1]
    except IndexError:
        print "Usage: serial_gcode filename"
        sys.exit
    try:
        g_code = open(filename, 'r').readlines()
    except IOError:
        print "An error occured opening the file "+filename
    check_conn()
    for line in g_code:
        send_line(line)


   
if __name__ == "__main__":
    main()

</code>

And attached above http://letsmakerobots.com/files/serial_gcode.py_.txt, please remove the .txt ending.

Have fun !

 


Update - 04 Jan 2010 -Valkyrie Reloaded

 

The last two days I worked on and off on the Valkyrie slowly putting it back together.

I mounted the new Z, got the motors mounted. I got the drivers checked, fixed and running.

I'm running the motors at around 30V now (give or take 5V) and with the help of the redesigned drivers, I'm running them in a so called "full torque half stepping" mode (at least it seems to work) see here for info on that: 

http://www.piclist.com/tecHREF/io/stepper/linistep/halfstep.htm

I still have to re adjust the axis, right now I have problems with both X and Y, Z seems fine, I will do that tomorrow with a fresh mind. 

I moved the drivers off of the machine to avoid EMF as much as possible, will run tests ASAP to see if I still get lockups on the I2C bus. 

So basically I have the machine back online, I hope I will be able to start doing useful stuff with it soon.


12 - January - 2010 - 2.1 is here aka "Valkyrie Reloaded"

Check out the new video for now, I will update the rest in the

following days.  

 

 


19 - Jan - 2010 - Video for Oddbot

 

Hi all,

Since China gouvernment seems to protect it's people form bad things like youtube, OddBot is unable to see any of my youtube videos.

So here you go Oddbot a download link:

http://www.4shared.com/file/200950593/5bfc7e36/valkyrie21avi.html

Let me know if it works.

 


17 - Feb - 2010

Brain: We must prepare for tomorrow night.
Pinky: Why? What are we going to do tomorrow night?
Brain: The same thing we do every night, Pinky - try to take over the world!

Long time no update, well I didn't have much to say really. The machine is more or less done and more or less working ;) My biggest problem is still having the time to actually do stuff with it. 

So here is some random stuff on my TODO/WIP list:

- implement G02/G03 in the Arduino while keeping the Atmega168 - done needs testing 

- trying to get the code written by Triffid Hunter which is here: http://github.com/triffid/ATmega-Skeleton/tree/master/mendel/ to work with my I2C controllers - previous commit worked to some degree, last one does not work at all, the author is still heavily developing on it. But it shows a lot of promise and cool features.

- thinking on the next generation of the driver - a few choices here not sure which to go for:

a. keep it I2C based but add l297 on to take care of the stepping and currents (got 4 of l297 I might as well give it a shot)

b. drop I2C, use step/direction/enable with l297 - standard Reprap but keep the Arduino controlling the beast  

c. drop I2C,  use step/direction/enable with l297,drop Arduino, use parallel port and EMC2 directly to do all nasty G-code processing part

d. drop I2C,  use step/direction/enable with l297, keep Arduino but do G-code processing on PC and send only stepping commands to Arduino. (This one would be future proof too)

e. keep I2C, add l297, keep Arduino but do G-code processing on PC and send only stepping commands to Arduino. (This one would be future proof also)

- working on the Valkyrie 3.0 which should have the following features (draft):

  • CAD designed
  • Open Source - all files including G-code for parts will be available
  • Self replicating - yes you got that right, all structural parts will be designed in a way which will allow an existing machine to cut them for another
  • More precise - parts will not be manufactured as before
  • Light weight yet sturdy (well we'll see about light weight)
  • Larger cutting area, yet same size or even smaller
  • NEMA17 200 steps per revolution motors 
  • New drivers or electronics altogether
  • Home/EOL sensors are a must 
  • ... and some other stuff

- working on the software side a lot

- working on a nice control panel for the machine 

- thinking on creating a website for this project so I do not flood LMR :)


03 - Mar - 2010 - Every time you think you have it all nicely working - disaster strikes :P

Sunday evening I finished surgery on the v2 drivers to get them to work with Step / Enable / Direction signals instead of I2C (see here on why it took me all weekend). The code was 90% written but I was too tired to do any good about it so I decided to just mount the drivers back in the box and wire them up and leave software/testing for Monday.

That was a very bad decision since I ended up somehow with the motor power connections inverted and on Monday morning when I powered the thing up without checking, all L298's on the drivers were instantly killed ... not even some blue smoke :P

Good thing I tested without the Tiny's plugged in though or else I would have killed any hope to machine the PCB's for the V3 drivers. 

Anyway I replaced the burned l298's this morning so probably tonight I'll have a live Valkyrie lurking around. 

On the software side of things I have multiple firmware choices to play with on the Arduino. My old code does not work anymore since it used I2C, which has to be removed now and replaced with functions to do the step signals. While that isn't hard to do really, I have found several alternatives which provide some extra features or are simply better written:

1. The most complete candidate seems to be the one written by Chris Meighan (yes he did write his own firmware besides that nice java control panel) for which the only release ever done is to be found here . Note that it will not compile straight up and requires fixes here and there to fit on the Arduino, I got it to compile and fit but I still need to do some testing so I will not post it yet.

2. Triffid_Hunter has been writing on a very nice c only replacement for the Arduino 5D firmware, but currently it is in a fairly unstable stage.   

3. grbl  is another c only implementation, haven't played with it yet cause may goal now is to have acceleration in the movements and it does not provide any. But it might be the most stable code.

4. this  one also seems cool, not tested yet.

Of course I can always start hacking on my own and take the best out of the above with credits to their respective owners, but it might not be necessary for now.

 

 


09 - Mar - 2010 - It's alive :)

Fixed the drivers yeah!

 

Acceleration Arduino firmware seems to do nicely, but it is not what I hoped PCB milling is a no go as it would take forever...

As I'm going to Spain I'm trying to finish the new design of V3, maybe I'll have it ready until then.

Here is a quick preview:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Still a lot to think and work on it, but I think it is coming up nicely :D 


02 - Apr - 2010 - Done!

This is it ! The Valkyrie 2.1 is officially done! It is doing it's job as well as possible considering it's birth :)


 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
... see the update in the main post.

Looking around the web, it seems like there isn't much too helpful information with DIY CNCs (maybe I'm not looking hard enough).

RepRap proved off-putting when their pages and updates seemed unkept.

All in all, Your build was quite inspiring, and I'm following your lead. You said you used a python script for a pass on the g-code to the arduino through the serial port. How exactly did you do this? Looking into it, I assume you used python and pyserial. Is there any way you can post the source code up for the python-end of your build?

 

If you need any help with the build, do not hesitate to ask. 

You are right, I'm using pyserial. 

Basically I'm reading the gcode file, then I'm the lines one by one trough the serial while waiting for the OK from the Arduino.

The script is as simple as it get's I will post it tonight when I get home, right now I'm at work.

 

 

i am glad to read you found better steppers for your proyect.......... i was worried for you to struggle with microstepping. when i measured the 1.8 degree steppers i have i noticed i wont need microstepping at all..... then readed your info working on pwm and stuff i double check my settings and confirmed my findings,,,,,,,,, everything ok....

 

what torque your new steppers have..... did you test them? if you what to drive 1 amp motors you could use 2 hbridges one on top of the other.... parallel pit to pin... you must notice that you can also rise the voltage that feeds the motors, better perfomance....

are they 4 wire motors?  my new ones are unipolar 6 wire, 12 volts 0.4 amp vexta steppers.... wired as bipolar half coiled...

 i think that in order to get allways the best results in proyects, you must keep things as simple as they can be..... really dont know why to use i2c when the driver circuits are so simple to manage..... in the reprap gcode interpreter there is a delay value i was playing with to get better results.... it is on the stepper control tag..... 

return ((distance * 60000000.0) / feedrate) / master_steps;   i changed the value to 1000000000  (9 cero).

 

also have limit switches on all axis...... i cant see them on your machine.... very good feature.....

 

 

Microstepping is cool but very hard to implement. I wanted microstepping because besides a better resolution with those cheap steppers, it would create a much smoother movement and reduce overall resonance. Anyway I can live without it though :)

The new steppers are bigger and have very good torque. They are bipolar, so they have 4 wires. I did some tests with them, they work very nicely.

I agree with the KISS idea in my projects too, I chose to use I2C because it seemed more elegant then the pulse/direction solution,I can always change that.

Not sure why you needed  to modify the value there, I had no problems with that...

Limit switches will be implemented next, I'm tired of homing the machine manually everytime :P

Very nice and clean build you have there, I'm using some similar solutions on my own mini-cnc that's been in the making for years now, it seems like.

How is the mechanical resonance after adding the new motors? It will probably still scream a bit during operation, yes?

What I did was to add a small flywheel to the leadscrews which dramatically cut down on noise, and also increased my max speed to at least double of what it was before, although acceleration may have to be tuned down if the rotating mass is large enough (too large?),Mine are about 5cm in diameter cut with a hole-saw from 8mm plywood. They are probably a bit larger than they need to be, but they do give a mean max-speed. ;) (did do - my machine is currently in pieces, awaiting some redesign)

So basically what you'll have is:
[Motor shaft] -> [Rubbery connector] -> {Lead screw] -> [Small flywheel]
Feels right to have the flywheel right at the shaft connector, but that's just based on my instinct :)

This will be the mechanical analog of a second order low-pass filter, with the rubber connector playing the role of the capacitor (Being kind of springy, it stores potential energy.) And the fly-wheel takes the role of an inductor (Storing kinetic energy). I believe the reason that this allows a higher max speed is because the resonant frequency of the mechanical system is increased so as to avoid oscillations.

But the simplest and best way to see what happens is probably just to realize that the flywheel will tend to keep the lead-screw spinning for the fraction of a second that the motor shaft does not. With the semi-rigid shaft connector further enchancing this smoothing action.

Edit:
A soft connector between the motor and lead-screw is probably very important for this to work properly. I can't imagine the fly-wheel doing much good if the lead-screw can't move slightly independent from the shaft. The rubber acting as a highly damped spring probably doesn't hurt to kill of oscillations either.

I haven't got to mount the new motors yet, I need to create new mounts for them ... But with the old ones it wasn't screaming too much. But thanks for the tip, I will give it a try if I think it's needed.

Right now I'm rebuilding the Z-Axis, should enhance the Y axis work area by around 100 mm yey !

That sounds familiar - And if you ever think you're finished, it's probably just mental preparations for the next build. :)

Btw,  how do you power the your motors? Overvoltaged and current limited? I'm using some inline power-resistors to limit stall-current. Primitive, but all my dirt cheap controller cards could accomodate.

... I'm powering them over voltaged and I thought I got current limiting working on my controller by using pwm on the input pins of the l298 driver, but that does not seem to do it right, so I guess they are both over voltaged and not really current limited ... The motors I've been using do get pretty hot, I think somewhere in the range of 80 degrees celsius. I thought about adding some resistors but I did not relly liked the idea, maybe I should reconsider though. ..

You've got such a nice controller with all the possibilities in the world - I say stick with it. Sooner or later you'll figure it out :) Haven't got the software to view your schematics, but I'm guessing you're using the sense voltages per the l298 datasheet. And feed them to two ADC channels on the uC. And based on that reading you vary the duty cycle to get closed loop control of the current?

edit: I see Attiny2313 doesn't have an ADC, so no-go on that one.  Apparently it has an analog comparator, perhaps that could be used somehow. I'm thinking something along the lines of 100% duty cycle until the comparator trips, (Which is assumed to happen when the motor winding is at it's rated current.) and then drop the duty cycle accordingly. E.g. if your motor is rated for 12V and you supply it 36V drop duty cycle to about 33%. This is just off the top of my head, and I'm not quite sure how it'll play out in meatspace. At the end of the day this is probably not doable without some more external circuitry, as the Attiny datasheet suggests it only has one 2-input comparator.

I'm sorry to say I seem to be running out of ideas here...