CnC Machine Controled by BGE

Hello everyone,

Me and my brother Started a crazy project a year and a half ago, to build a CnC miller out of nothing,
So we’ve built a structure with stepper motors on 3 axis controlled by an Arduino Board.
To Command everything i choosed to use the Blender Game Engine. (that’s why i’m posting here;)).
I’m using Pyserial to send commands to the arduino.

So i’ve coded quite a bit and so far we can :
-Send Commands to arduino and get answers back.
-do Direct control of the mill with keyboard like with a joystick.
-Draw Straight lines with Start and end coordinates.

here’s some pictures of the machine, the electronic system and some stuff we made so far :

Sorry seems i can’t add pictures or URL just yet, will update as soon as possible,
(Pics are posted on DeviantArt on Zagio’s account maybe you can find em there)

Thanks guys for checking out our project, I’ll prolly bother you soonish with crazy questions, and show you guys and news happening for this project :slight_smile:

… sorry for any english errors in this post, french man here, sometimes my english is broken …

Nice work, keep@it =)

thanks for the cheer up !

so here’s a first problem ive got :
I draw an object in blender, then i Get all the vertices coordinates and start to draw lines but,
each vertex doesnt lists in the order they were created but seems to be somehow randomly distributed in the array.
anyone got any idea on how to sort vertices out ?

That is normal. You can read the mesh and create the node-graph for your needs.

Python list.sorted key mode should work,

Let me know of you need any help

edit: the sorted thing won’t really work, now that I think about it, because you can’t sort all three floats at the same time… hrm.

how to order vectors by 3d space?

edit: if you’re doing tool paths, don’t you really want a curve to work along?
one neat trick you could do, is use a mesh, that is just a edge, and have that be the tool path,
color the ‘first’ vertex a different color…

This way you know where to start, then look up the edge that contains this vertex, then move to that the other vertex that shares this edge over time, when you get to your point, look up and other edges that share this new vertex? (repeat at each point until the end?)

maybe save a list of vertex you have already visited to check against?

hey, thx for the hints, the vertex color is an awesome idea, so far im just setting up the first vertex to be at 0,0 (im really checking only X and Y for now i ll work on Z axis way later).

and yes exactly i need to check wich vertices are connected by an edge that the point im having troubles with, i dont know where to get edges data.

i think BGE resorts vertex array to be more efficient for drawing, wich is great for what BGE is meant for but very bad for me :(.

So you have to think of how you want to progress between vertices. You probably wan’t to do the highest layer first. So that’s easy. Sort by Z distance. Then you need to pick a point and follow the edge. Picking a point is easy (random.choice) and following an edge should be simple enough (you may have to use shade-smooth on your object). Then you work your way down.

Otherwise, the standard way of doing this is g-code. You can do your interface and a g-code -> pyserial converter in BGE. Then the g-code can be generated elsewhere.

Well, here some news :

My object as no faces its just a chain of edges, when i use debugmode to show vertex index in viewport, everything is as expected. the vertex order matches the vertex creation order.

But to access vertex data in GE i need to create faces, because it seems that GE dosnt import any mesh data with no faces. So i belive that’s when my vertex array get messed up.

So my idea is to make a python script to export the mesh vertex array in a file before GE starts, then import the data from the file with GE and i should be able to draw my shape in the correct order.

I’ll keep up with news as i’m progressing!

btw thanks again for all the help guys !

Why not use Blender rather than the BGE?

It seems the BGE is not sufficient for your needs while Blender is designed for mesh manipulation.

But, I do not really see what you want to achieve. CNC programming and surface 3D presentation does no fit very well.

If you want to define tool paths Blender’s curves might be an idea to look at.

Yes, I’m gonna use bpy to extract the vertex datas for now.
So far ive been using bge to have a real time simulation, when i move the real tool with keyboard control ive got a 3D tool moving on screen and postion in mm is shown wich is a pretty nice feature.
I was thinking about the path tool too im gonna check that out yes, so far ive just got an algorithm to “draw” lines, Its working pretty well.
But i still need (for now :eyebrowlift:) to give it points data by hand.
When finnished i shouldnt have to edit any data while the bge is running this should be done earlier (idealy even outside of blender then imported).
And of course most fun in this project is to devellop as much as i can just by myself wich is why i didnt use any “plug and play” solutions like GCode and CAM softwares.
Right now, I’m still working on my custom exporter/importer (been a rough week at work hope to get much done this weekend).

I use to work with an Industrial CnC machine a few years ago. Like Monster said, try using curves. We use to use Nurbs for the CnC machine from Rhino3D after modification from imported models, usually from 3DsMax or SolidWorks. The machine tended to start from the base of the object, cutting around the X, Y axis to create the silhouette, then it would finish off on other areas from the Z axis.

You do not need real-time at all. It is the core idea of a CNC that you do not need it. You feed it and it runs automatically. Real-time control is remote control.

It is useful in simulating the device as it does not cost materials and tools (just time). But you can create an animation within blender as this is non-interactive. While generating the necessary animations you can even watch it in the preview window similar to cloth sim.