CNC easy linear movement routine

Hello everyone and thanks in advance,
First of all, I am a very newbie on Arduino and Contraptor, and I feel a little like "butter spread over too much bread"
I have a contraptor machine, just XY axis one. I want it to make circles from a list of XY points but I can not find how to do it smoothly.
I'm trying reading the contraptor routines, but I feel pretty lost.
What I am trying to do is, from a list of X and Y coordinates, make the plotter do lines from one point to the other, just that, but I would like both axis to move at the same time (or at least as much as possible). Can anybody suggest me some code to start and have a look?

Best,
Diego

Famous is the bresenham's circle algorithm which can be found here

Instead of SetPixel() you need to call Drill() ...

Thanks for your answers!
I would rather do not use the G-code interpreter. I just have the X and Y points and I want to join them. I have no arduino code, but this may help

x_coors={0, 3, 6, 9, 10}
y_coors={10,9,8,3,0}

then, point 0 would be (x[0],y[0])
I would like to use just steps and direction orders
Is it possible?

If you want to hardcode a list of points on a circle of fixed radius at a fixed point, that approach will work.

Otherwise you will need to perform a linear approximation of a circle. Depending on the range of circle sizes you want to move along, you might get away with just defining points every 5 degrees, or so.

I've done this with two functions - cartToPolar() and polarToCart(), to convert cartesian coordinates to polar coordinates and polar coordinates to cartesian coordinates. cartToPolar takes x1, y1, x2, y2, and returns theta and r. x1, y1 are the center of the circle, and x2, y2 are a point on the circle.

polarToCart takes the same arguments in a different order, but computes a point on the circle centered at x1, y1, with a given angle and radius, returning x2, y2.

Call polarToCart with differing values for the angle, and fixed values for center and radius.

A google search of polar coordinate systems will give you the equations, if you are rusty on your basic algebra.

Yes, I noticed that :slight_smile:
So, any algorithm you may suggest my for that issue?

I feel all the comands based on GCode are reduced to steps and direction functions of the stepper motors. Is this right? If so, is there any routine based in just those 4 commands (2 for the X axis and 2 for the Y axis) that may help me?

f you want to hardcode a list of points on a circle of fixed radius at a fixed point, that approach will work.

Otherwise you will need to perform a linear approximation of a circle. Depending on the range of circle sizes you want to move along, you might get away with just defining points every 5 degrees, or so.

I've done this with two functions - cartToPolar() and polarToCart(), to convert cartesian coordinates to polar coordinates and polar coordinates to cartesian coordinates. cartToPolar takes x1, y1, x2, y2, and returns theta and r. x1, y1 are the center of the circle, and x2, y2 are a point on the circle.

polarToCart takes the same arguments in a different order, but computes a point on the circle centered at x1, y1, with a given angle and radius, returning x2, y2.

Call polarToCart with differing values for the angle, and fixed values for center and radius.

A google search of polar coordinate systems will give you the equations, if you are rusty on your basic algebra.
Posted by: Richard Crowley

Thanks for the info, but I am looking for functions for the steppers, so I give a list of X and Y coordinates and makes lines between adjacent points :slight_smile:

DDA or Bresenham's?

Any of the two will work :slight_smile: Just the one you find easier...
My point is that I want both axis to move at the same time. I mean I do not want first the X axis then stop X motor, and the Y axis and then stop Y motor... I don't know if that is possible....

Excusme Richard, I do not reject it, simply I don't understand it :slight_smile: I mean I am getting very confused trying to find what i need. I just would like to know if you could point me to some routines, like posting a link or something :slight_smile:
You all are being really kind, I really mean it. I'm sorry, I think my english is not good enough and let you to misunderstandings
Best,
Diego

The thing is that I using the machine for an automatic, random plotting
I just want the machine to draw lines and only lines.
These lines are based on some points that the very same Arduino that controls the machine generates using random routine based on information collected by sensors. Let me expalin it again: Arduino takes info from some sensors and generates a vector of points that are to be plotted by the machine. i just need the routine that plots lines based on points. That's why I messing so much :slight_smile: I do not need most part of Contractor implementation an it takes most of the memory of Arduino. I just need a tiny part of code that I am not being able to identify :frowning:

That's what I'm trying :slight_smile:
It seems Contraptor forum is a little bit dead... But I will keep trying!
Thanks a lot for your support!

I edit my last answer: the forum is alive and they have just answer me there too.
Thanks a lot all you guys for being so comprenhensive. I hope I managed to find a solution, so I some one ever finds the same problem, please send me a message!