Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add ability to use radius format of G02/G03 commands (CNC) #4676

Closed
Bob-the-Kuhn opened this issue Aug 21, 2016 · 26 comments
Closed
Labels
T: Feature Request Features requested by users.

Comments

@Bob-the-Kuhn
Copy link
Contributor

My CAM software sometimes generates the radius version of the G02/G03 command. It would be great if Marlin could handle the radius format.

I've written an Excel macro to do the conversion. I've attached it incase it's usefull to the coders.

The macro only handles positive values of the radius. Negative values of the radius requires messing with the X and Y parts of the command.
radius portion of Excel macro.txt

@Bob-the-Kuhn
Copy link
Contributor Author

I've added support for negative radius.

Turns out you don't need to mess with the X and Y values when doing negative radius.

radius portion of Excel macro (with neg radius support).txt

@Bob-the-Kuhn
Copy link
Contributor Author

Didn't mean to close this request.
Just another example of shooting myself in the foot ...

@Roxy-3D
Copy link
Member

Roxy-3D commented Aug 22, 2016

Bob, do you know the C programming language? Can you put your concept into C for us?

I don't understand what a negative radius even means. That seems kind of like an imaginary number. Why is this useful (from a mathematical perspective)?

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Aug 22, 2016

Sorry – I knew a little C about 15 years ago.

Here’s a link that shows an example of a command with a negative radius. It’s towards the bottom of the page & is titled “R Method Example 2:”

   http://www.manufacturinget.org/2011/12/cnc-g-code-g02-and-g03/

I only included the negative radius so I can call my Excel macro complete.

I’d be really surprised if any of the well known tools would generate a command with a negative radius.

@Roxy-3D
Copy link
Member

Roxy-3D commented Aug 22, 2016

Do CNC machines use negative radius on their GCode commands?

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Aug 22, 2016

I doubt it but … I’m just a beginner at CNC

@Roxy-3D
Copy link
Member

Roxy-3D commented Aug 22, 2016

Do CNC machines use negative radius on their GCode commands?
I doubt it but … I’m just a beginner at CNC

Bob, we have a constant challenge to keep the feature set of Marlin up to date and debugged for the items that user really need. We can't be adding features that are not going to be used by a significant number of those users.

The GitHub system handles this situation very well. What you do is you fork the code base, and add your features. Your customized version of Merlin that does the things you need it to do can exist in parallel to the main branch of Marlin.

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Aug 22, 2016

I agree that the negative radius is not worth the effort by itself. It’s just easy to include if positive radius is implemented.

The positive radius commands are generated by the SketchUcam plugin for the SketchUp program. These are used a lot by the DIY CNC community.

I expect that the user base for Marlin with the radius feature are those of us that want to use one machine to do both CNC and 3D printing.

Bob

PS – The second file I attached does both positive and negative radius. There’s only a few added statements from the first file to implement the negative radius.

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Aug 23, 2016

I've done my best to convert the conversion routine to C.

One file has the C functions and the Excel syntax. That one I could test. It it the conversions correctly on a large gcode program. The C functions were mimiced by Excel functions that I created for the test.

The other file has the C functions and the C syntax. I have no way of testing it so it needs to be looked at carefully before being used.

Bob
radius portion of Excel macro (with neg radius support) using C functions and syntax.txt
radius portion of Excel macro (with neg radius support) using C functions.txt

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Aug 23, 2016

I've found the GRBL code to do the conversion.

They use vector calculations. Seems like a lot more work than the method I found but I expect the real test is how fast they execute.

Attached are two files that are portions of the gcode.c file in the main grbl branch. This is where the radius conversion code is.

  • grbl_gcode.c_radius conversion.docx - straight copy of the conversion section. It has a very good explanation of how they did the conversion. Best viewed in landscape mode with 12" width paper selected.
  • grbl_gcode.c_radius conversion most comments deleted.docx - it was hard for me to see how much computing was being done so I stripped out 99% of the comments.

Bob

grbl_gcode.c_radius conversion most comments deleted.docx
grbl_gcode.c_radius conversion.docx

@thinkyhead thinkyhead added the T: Feature Request Features requested by users. label Aug 23, 2016
@thinkyhead
Copy link
Member

thinkyhead commented Aug 23, 2016

Marlin already implements G2 and G3 codes that trace an arc. G2 is clockwise arc, G3 is counter-clockwise arc. The arc begins at the current position. The X Y Z parameters specify the end-point of the arc. The I and J parameters that specify the pivot-point of the arc in the XY plane.

Marlin also implements G5 which traces a Beziér curve.

@Bob-the-Kuhn
Copy link
Contributor Author

In the general case the G2 & G3 commands can use either I J K to specify the arc or a radius. Marlin implements only the I J K method.

@Bob-the-Kuhn
Copy link
Contributor Author

I've created a pull request for this feature request.

@thinkyhead
Copy link
Member

thinkyhead commented Sep 18, 2016

I've created a pull request for this feature request.

Where? It seems to have been targeted someplace besides RCBugFix.
Please target all pull requests to RCBugFix.

@Roxy-3D
Copy link
Member

Roxy-3D commented Sep 18, 2016

Marlin already implements G2 and G3 codes that trace an arc. G2 is clockwise arc, G3 is counter-clockwise arc.

@thinkyhead Have you heard anybody talking about making G2 and G3 work with Delta's ? I wonder if it would be as easy as sending the intermediate steps down the same pathway as G1 does to get the work done?

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Sep 18, 2016

There’s two ways of specifying the arc. Marlin currently supports the I J method. This work would allow Marlin to also support the R (radius) method.

@thinkyhead
Copy link
Member

@Roxy-3D G2 and G3 work just wonderfully with Delta.

@thinkyhead
Copy link
Member

The "R" method seems like an interesting challenge. The code needs to determine the point that is equidistant from the start and end points, taking the clockwise or counter-clockwise path between them.

Note that if the start and end points are the same, there's no way to determine (with just an "R" argument) what the center of the circle should be. It could be in any direction. For this reason, full circles are forbidden with the "R" method, and you must therefore specify an XY which is a different point from where you started.

@thinkyhead
Copy link
Member

thinkyhead commented Sep 18, 2016

If the code isn't already written, here's how it will need to go…
http://mathforum.org/library/drmath/view/53027.html

float e = clockwise ? -1 : 1,                     // clockwise -1, counterclockwise 1
      dx = x2 - x1, dy = y2 - y1,                 // X and Y differences
      d = HYPOT(dx, dy),                          // Linear distance between the points
      h = sqrt(sq(r) - sq(d * 0.5)),              // Distance to the arc pivot-point
      mx = (x1 + x2) * 0.5, my = (y1 + y2) * 0.5, // Point between the two points
      sx = -dy / d, sy = dx / d,                  // Slope of the perpendicular bisector
      cx = mx + e * h * sx, cy = my + e * h * sy; // Pivot-point of the arc

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Sep 19, 2016

The code is written & tested.

I think I’ve finally figured out how to set things up so I can do the pull. But I’ve said that twice before ..

@thinkyhead
Copy link
Member

Oops, I went and wrote it. Let's compare. #4840

@thinkyhead
Copy link
Member

thinkyhead commented Sep 19, 2016

Just looking over the formula, I think maybe sx needs to be negated for the correct 90° rotation.

Corrected. Test code gives positive results:

(10,10) to (10,20) with R=10 ... CCW I:-8.66 J:+5.00
(10,10) to (10,20) with R=10 ...  CW I:+8.66 J:+5.00
(10,10) to (20,10) with R=10 ... CCW I:+5.00 J:+8.66
(10,10) to (20,10) with R=10 ...  CW I:+5.00 J:-8.66

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Sep 19, 2016

The way I’ve been shooting myself in the foot today … it may take a couple of hours before I can get my code officially into an RCBugFix pull request.

It’s already in a pull request in my section. Here’s the link to it.

https://github.com/Bob-the-Kuhn/Marlin-RCBugFix--Radius-/pull/1

@thinkyhead
Copy link
Member

thinkyhead commented Sep 19, 2016

Thanks! But I think it's pretty well covered by #4840. I've got it checking the arguments for errors, calculating the arc offsets, and it simply uses the existing plan_arc function with no extra code needed there. Very straightforward, clean, concise, compliant.

@Bob-the-Kuhn
Copy link
Contributor Author

Bob-the-Kuhn commented Sep 19, 2016

I think I finally got the pull request against RCBugFix created. Please see if #4841 is what you want to see.

The good news is that the R method is moving forward.

I looked at the plan_arc function but was afraid of touching existing code.

@github-actions
Copy link

github-actions bot commented Apr 3, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T: Feature Request Features requested by users.
Projects
None yet
Development

No branches or pull requests

3 participants