Marlin firmware custom codes

Hey all!

So I slapped together a basic Rambo MPCNC for routing with the 660 a bit over a year ago. Over the winter it sat in dust as it was cold in the garage.

Well it’s warming up and I’m stuck at home so I’ve been busy modding the MPCNC up.

So far I added the dual endstops. That was easy.
Then I added G38.2 functionality so I can use it to find corners of objects… that was not so easy

Now my next challenge: round stock. I want to use G38.2 to find the edges of a circle and these points to find the center of the circle.

The only way I can think to do this would be to find the left edge, find the right edge. I need to take these values and somehow find the average and set that to 0.

I was thinking of making my own Mcode, but everywhere I look they talk about “marlin_main.cpp” files which for some reason I cannot find.

So I’m reaching out here to ask if this is even a possible thing and if there are any suggestions out there.

Thanks for the support!

marlin_main.cpp existed in the 1.1.x branch but since 2.0.x it no longer exists. The gcode functionality has been split where Marlin/src/gcode/gcode.h defines all the codes and the implementation resides in individual files below Marlin/src/gcode/.

I think if you clone an existing function and give it a different G or M code, you should be able to determine if it works (with the duplicated functionailty), and if so then you can change the guts inside the handler to implement your function.

And don’t you need to probe at least three points to define a circle?

The midpoint of the left/right gives the x and 2 back/forth gives the y.

Thanks. I’ll look into this