Homebrew CNC machine

Alright guys,

I'm working on a homebrew CNC machine, and have most of all the setup done.

I'm trying to implement complex (i.e. arc/circle) milling capability, and need some help on how to arrange the formulas to accomplish this.

It stands that by adjusting the stepping speed of each axis accordingly that one can mill a line not solely in one axis (that is, diagonal):

Stepper stepperX(steps/rev, pins);
Stepper stepperY(steps/rev, pins);

void drawLine (int slope, int endpoint_x, int speed)
{
     stepperX.setSpeed(speed);
     stepperY.setSpeed(slope * speed);

     int endpoint_y = endpoint_x * slope;

     stepperX.step(endpoint_x);
     stepperY.step(endpoint_y);
}

Or something of the sort - I drew that up as enough of a preliminary to visualize what it would accomplish.

The question being, how would one extend that concept to a complex structure like an arc? Would the easiest way be to 'Riemann sum' it and iterate the above function many times in small increments at the slope and points of the arc of interest, or are there easier methods?

TIA,
blasthash

I've been toying with this concept but it is on the back burner at the moment.

I think it is necessary to ensure the two (or as many as you need) motors step in synch with each other and my scheme for doing that is to generate all the data for a straight line move on the PC and send it to the Arduino. (A curve is just a lot of short straight lines).

For a straight line that requires one motor to make 500 steps while the other makes 363 steps my PC code sends to the Arduino 181500, 363, 500 and the Arduino nows to run a loop 181500 times and after every 363 loops motor A makes a step and every 500 loops motor B makes a step. That way both motors complete their 500 and 363 steps in the exact same time. This also has the advantage that the Arduino has no complex maths to do. The PC can send the data for the next move while the current move is in progress.

I know this moves the motors appropriately but I haven't tried drawing or cutting with it yet.

There is another thread with a useful arrangement for turning curves into XY data but I can't immedately find it.

...R

Robin2:
I've been toying with this concept but it is on the back burner at the moment.

I think it is necessary to ensure the two (or as many as you need) motors step in synch with each other and my scheme for doing that is to generate all the data for a straight line move on the PC and send it to the Arduino. (A curve is just a lot of short straight lines).

For a straight line that requires one motor to make 500 steps while the other makes 363 steps my PC code sends to the Arduino 181500, 363, 500 and the Arduino nows to run a loop 181500 times and after every 363 loops motor A makes a step and every 500 loops motor B makes a step. That way both motors complete their 500 and 363 steps in the exact same time. This also has the advantage that the Arduino has no complex maths to do. The PC can send the data for the next move while the current move is in progress.

I know this moves the motors appropriately but I haven't tried drawing or cutting with it yet.

There is another thread with a useful arrangement for turning curves into XY data but I can't immedately find it.

...R

That makes sense. Run the line/arc milling on an interval system.

What I might do is something of this sort:

void drawCurve(int endpoint_x, endpoint_y, radius, resolution)
{
     if ((endpoint_x - current_pos_x) > 0 & (endpoint_y - current_pos_y) > 0)   
     { 
          bool quad_1_arc = TRUE;
     }
     // Iterate the above statement 3 more times for each quadrant possibility
     float circumf = 6.28 * radius;
     int stepPerInch; // We'll fill this number appropriately, and assume endpoints and radii are in inches
     int numOfSteps = (int) circumf * stepPerInch;
     for (int i = 0; i < numOfSteps; i + resolution)
     { 
          int next_x = current_pos_x + (resolution / stepPerInch);
          int next_y = (int) sqrt(pow(radius,2) - pow(next_x,2));
          int slp = (next_y - current_pos_y) / (next_x - current_pos_x);
          drawLine(slp, next_x, speed);
     }
}
                
void drawLine (int slope, int endpoint_x, int speed)
{
     stepperX.setSpeed(speed);
     stepperY.setSpeed(slope * speed);

     int endpoint_y = endpoint_x * slope;

     stepperX.step(endpoint_x);
     stepperY.step(endpoint_y);
}

In essence, what this should do is call drawLine() x number of times based on a resolution value given, also using the circle slope equation to generate the slope and next endpoints. I can't test it yet as I have no medium with which I can, but ideally it should work.

I haven't managed to get my head around arcs with end points and radii so I have no comment to offer on that stuff.

I would be concerned that setting different speeds for the two motors would not guarantee that they move in sync with each other - maybe it does. But I suspect it would not if you advance to using accelerations and decelerations.

I also wonder if integer math will be sufficient to work out slopes and speeds (or for arc calculations). This is why I prefer to do that stuff on the PC.

...R