Adding smarts to the MPCNC

Like many of you, I am always looking to improve my MPCNC. It really did perform very well as a stock Primo (thanks, Ryan!), and even better when I made a number of improvements to speed it up. One downside of its current form is a lack of intelligence. And mine is waning with age, so any artificial intelligence I can add would be helpful. I would love for any of you to point out previous discussions/projects in which people used some closed-loop feedback, or other forms of artificial intelligence in software or hardware to make their MPCNC faster, stronger, and/or more accurate. More usable is also a big plus!

What is the latest word on closed-loop steppers (like S42B) or other servomotors?
If you have used one and like it, PLEASE POST A REPLY here.

I am trying to get my Z travel to keep up with my fast XY travel (>70mm/sec) when carving complex terrain with lots of ups and downs, and I am sometimes skipping Z steps and ruining a nice piece of wood near the end of the carving process. Very disappointing. So I am looking for a closed-loop approach that would notice if Z was off and fix it before gouging out my wood.

To get the conversation started, something I have not seen yet is a vision-based approach to closed-loop control. The closest thing I found here was a laser triangulation idea from Anttix. But cameras and lenses are getting very cheap and higher frame rates may allow watching the collet or cutter itself and correcting for any deviations from the gcode. That’s just one kooky idea of mine, inspired by optical autofocus mechanisms with sub-micron precision we used on microscopes in my lab.

I am willing to entertain all AI approaches, like Peter’s multiple tape measures to get high accuracy. Did that ever come to anything?

3 Likes

You can regear (differnt screws) the Z to move faster. There is plenty of power when the steppers are not moving so fast. Or do some testing I have the accelerations set extremely low on the Z axis you can easily turn them up and probably double your speed as is. If you look at the calc you can see you are probably never even getting close to the speeds you set. Not sure why you would skip steps though, that is not right unless you are overheating or lacking lube. The Z is by far the safest axis …as set.

One of my welding robots has a camera to adjust weld position to compensate for any material discrepancy. It’s by servo robot. Obviously, at $40k it is out of reach of hobbist, but might give you some ideas.

Closed loop control of stepper would need some sort of encoder feedback. Perhaps you can change steppers with double ended shafts and mount an encoder on them?

Just spit balling…

Dang-nabit! They’ve already got weapons, don’t make 'em any smarter! Next thing you know they’ll be after our women-folk (or men-folk, or non-binary-folk, or non-folk, we don’t discriminate here)!

There are some of these closed loop, BIGTREETECH S42C v1.0 42 Stepper Motor Closed Loop Driver Board with O | Biqu Equipment that will work as is but I’m not convinced that is the best solution currently.

The smarts…above my pay grade currently.

If I were to make requests though, the laser thing that seems pretty common would be rad. Where it takes a picture and moves the gcode to fit the material position. Seems like a very solid step one to some real smarts.

Smarts and laser targeting systems… It’s almost like you don’t actually pay attention to the movies any more…

1 Like

Not really. I built it, but never put in the work required to assess its accuracy, and I have never used it while cutting anything. It was a little finicky, and definitely needed some iterations to make it work better.

I also experimented with closed loop steppers (not on the MPCNC but for 3D printing). I attached some encoders to the X and Y steppers on my Prusa i3, and made some measurements. My conclusion was that the steppers were really accurate, even at very high speeds. (The Trinamic stepper drivers may have something to do with that, they seem to be quite smart). The precision of extrusion seems to be a much more important issue in 3D printing than the X/Y/Z motion.

For the MPCNC, I did quite a bit of research into precision. The belts seem to be one of the largest sources of inaccuracy. Another is tilt of the router. A closed loop loop stepper that has an encoder on the shaft cannot compensate for those. A closed loop stepper also tries to correct for positional inaccuracies all the time. I think that gives a lot of potential issues with undershoot, overshoot, and extra “wobbling” / vibration.

If you just want to detect missed steps, then simpler approaches are possible. Trinamic drivers can detect missed steps for example. You could also try mounting an acceleration sensor. When things start to go wrong, you often get a lot of vibration that you can measure this way. I never tried that myself though.

His machine is already juiced up on its own firmware.

I have not tried the closed loop steppers. But I have a lot of experience in unmanned ground robotics (driverless cars). As soon as you use closed loop, you are replacing the open loop accuracy and resolution with the closes loop sensor accuracy. There isn’t a good way to combine them. Open loop steppers are extremely accurate and precise until they skip steps.

Once you skip steps, you are likely to already have lost your work piece. But even if you managed to skip away from the work, the closed loop sensor needs to be super accurate to be able to get you back on track. And then, because you are already pushing the machine so hard, it won’t be long until you skip again.

Additionally having sensors all the time means that you have the risk of the closed loop sensors thinking the machine is out of place, even when the steppers are not skipping steps.

So that is where I would set the goal posts. The open loop needs to be accurate and precise enough to be good enough for all the milling. Because even though you are controlling steppers, the difference will always be in the sensors. If there is noise, or latency in the open loop sensors, then you will have to accept that as the truth.

The steppers with the built in encoders seem like they would be much more accurate than any camera based system. Our ground vehicles all has expensive camera and lidar systems on them. They also have expensive inertial sensors. But they also all have wheel encoders. The wheel encoders are 100x cheaper, and 10x more accurate than any of them. Even considering the occasional wheel slip (which def. messes things up, but is recoverable).

Our standard system has 100 micro steps per mm. The steppers are not that accurate, because 1/16th microstepping has some noise. But conservatively, whole steps are 6.25 steps per mm or .16mm. That would be impressive for any closed loop sensor. But it is also able to “measure” that very fast (650Hz at 100mm/s), with bearly zero latency. Cameras are going to be 30Hz or 60Hz, and then you have to process those images. A very fast computer and algorithm (like the nvidia graphics card cuda optimized alg.) Would be able to process the image before the next one. So 30Hz or maybe 60Hz is close to the max and you’re not talking about a raspberry pi anymore. All those big fat images need to be moved around, which is high speed buses. If you are expecting very high accuracy, you will beed high resolution, which increases the size and the processing time. It is a really difficult problem.

3 Likes

Thanks for the update and info, Peter.
Helpful insights about sources of error. In the present case, I am just considering closed-loop to prevent missed steps, not necessarily to improve accuracy, which is already very good. I like the idea of just getting a stronger stepper motor and a Trinamic driver that can detect skipped steps and hit the pause button for me. And a “rumble sensor” is a great idea.

Thanks for the problem-solving and ideas, Ryan. I already put a lower-pitch lead screw on (1-start, 2mm per rev), to prevent the heavy spindle from falling when the stepper power is off. I like that pitch and want to keep it. I think the reason I am skipping steps sometimes is just down to the sheer weight and inertia of the spindle (1.5kW water-cooled, weighs about 10 pounds) and the specific shapes I am carving. It is definitely harder to manually screw it in the up direction than down, using my fingers on the coupler.

Although it is warmer than usual here in Ireland, I have a water-cooled heatsink on the Z motor that keeps it below 30C, and a fan on the stepper driver that keeps the IC in it at 53C or less. (would an overheated stepper driver cause skipped steps?)
I had just cleaned off and re-greased the leadscrew before my most recent fail (see photo below), and checked that all the Z axis rails/bearings are sliding freely without slop or binding. I have done a fair bit of tweaking of the relevant variables to optimize speed and torque for all three axes:
-microsteps
-stepper driver current setting
-max speed setting in grbl
-acceleration setting in grbl
(and upped voltage to 40V, and increased max pulse rate dramatically by going to the Teensy controller.)
I am often pushing everything close to the limit.

Here is what lost Z steps look like. I also heard a difference in the sound, due to the finishing bit carving a suddenly deeper cut. But because I had not been vacuuming up the dust, it took me about 4 passes to cop on that there was a serious problem.

More smart ideas about smarts, please!

It depends on the driver. Drv8825s will just power off if they get to hot. That really sucks. The trinamic drivers and Marlin will reduce their holding current if they get too hot. That can lead to skipped steps, but they are at least trying instead of quiting like the drvs. IIRC, you have some big, separate drivers. I have no idea on those.

1 Like

Great food for thought, Jeffeb3! I am often referring to Artificial Intelligence as Artificial Stupidity when it gets it wrong. I seem to recall Dui ripped out his S42B closed-loop steppers when they began fighting each other.
Issues of noisy sensors, too-slow feedback loop, data overload if processing images, are all good points you make. A wider safety margin on an open-loop system may be the right answer for now.

I think there are two areas here that are related but worth distinguishing: One is closed-loop (basically servo) control of the machine, and the other is closed-loop refinement of the workpiece.

For the servo control, the accuracy is going to depend on the distance between the point of measurement and where the action is happening. Closed-loop steppers will not have information about the deflection of the machine, whereas a DRO mounted to the router will include deflection of the tubes but not fully capture the tilt of the router. The multiple tape measure approach could use the measured points to virtually measure the tip of the cutter, and then you’re that much closer to measuring the true cutting position.

Measuring the workpiece is a different philosophy. I’m thinking something very different like suppose you were grinding a surface plate. You would have some method of measuring flatness and then the software generates code to selectively grind the high spots. Or if you are making aspheric optics, you have some evaluation methodology and you generate grinding motions from the aberrations.

On a more basic level, if you wanted to cut out a contour that was precise with lots of zeros, you could sneak up on the desired perimeter shape, like people who do woodworking by hand (I’m told). Leave some material behind, measure it with a microscope, and come back and take off a little more, and repeat. This transforms the accuracy problem into a repeatability problem, and repeatability can be orders of magnitude better.

My line follower I would consider a first baby step toward closing the loop around the workpiece. It’s mostly a demo to stoke the imagination and not intended for production, but I think it’s within this general area.

Servo control of the machine and closed loop refinement of the workpiece are independent. You could use them together or individually, although closed loop refinement of the workpiece might reduce the usefulness of servo control of the machine, since accuracy no longer matters and repeatability might be just as good on an open-loop machine.

One of the problems is, where is the ‘smarts’ supposed to reside? Moving the tool based on measurements means there needs to be a host program somewhere to close the loop. I had put it into OctoPrint as a plugin, since that seemed quickest, but for advanced methods perhaps it would need to be a standalone program with a gcode sender module and a calculation and optimization main loop. I think this is one of the barriers, since it is nontrivial to build this even for a simple job.

6 Likes

Thanks, Jamie, for helping us differentiate and refine what “smarts” might mean for CNC. And thanks for sharing your marvellous line tracer! I wonder if you were inspired by Glowforge’s laser cutter, which seems to have some features like this. They were the first (to my knowledge) to add a camera to a laser cutter to make it smarter and easier to use, such as cutting or engraving along a traced sketch. You are helping CNC get to that level.

I like this thought! Now, how to automatically ‘sneak up’ on the ideal carving?

1 Like

Good comments above. I have spent alot of time diving into MPCNC error. Think just pushing string pots around with a basic core under no load. As someone posted above, about .15mm seems a good estimate. Maybe a little better? 0.1 or 0.05? Doesnt matter. To “close the loop” on your feedback syatem, you would want to have a device that can measure 10% of that accurately. Or 0.015mm. Then the controller can make a sensible adjustment. Yes that is possible. And yes machine vision is a possibility. But not a lot of turn-key solutions out there. The hardware is getting cheaper every day, but I still think you need programming and hardware mounting expertise to make it work. I am not going to count the sleepless hours I spend think about this. But in the end, if you start cutting material with a router, the error increases beyond the above references due to flex. My current method of countering that is using the machine to drill accurate center punch holes. And making 2nd pass z adjustments.

1 Like

Looking back at original post, made me think of another application. High end DMLS metal printers use use a camera to monitor the Z movement just like you describe. Often there are glitches where the powder bed does not move and redistribute the powder correctly. I think they create a machine fault which can be corrected before the next layer is melted. Probably accurate to 0.25mm or so.

Another idea in the Smart CNC series: Perhaps thermal imaging could be used to optimize feeds and speeds, or control a mist cooler system.

Here is a Flir thermal camera shot of a fine taper bit doing a finishing pass.

5 Likes

Look up venturi coolers. We have one on one of our lathes when machining hardened shafts. Needs steady supply of air, but gets cold enough to form frost on the nozzle.

1 Like

Assuming closed loop stepper isn’t an option (hopefully it is, and simpler than alternatives?).
Then would you want to end up with solution(s) that detect missed steps, then take action to pause, re-home, reposition and continue? Worse case redo cut path from last known good checkpoint inferred from gcode, or explicitly embedded checkpoints.

Detect missed steps via ADXL345 accelerometer + Klipper on Pi is sensitive enough to measure 3D printer frame resonance frequencies during calibration step, not sure if/whether can active monitor resonance during a cut?

How can missed steps be detected without encoder on the stepper? Audible detection, ampage draw spike, vibrations, something else?

Maybe closed loop steppers have (or could be modified to have…) firmware settings that detect and trigger alert when steps missed, but not take corrective action directly (just use the closed loop stepper for it’s encoder and ability to detect missed steps beyond an acceptable threshold), instead let the gcode executing controller rollback to last known good checkpoint and retry cuts…

Auto zeroing Z could be done with simple spring metal arm suspended at bit height in a corner and metal plate in corner/side of the spoilboard/stock. Or maybe integrate z probe with a metal corner/side clamp, wire to T track perhaps. Or you could get fancy and use some Camera + LED + Vision algo to detect when bit touches (blown/brushed clean) stock based on bit’s shadow connecting with bit (think about how DeWalt chop saw casts sharp shadow onto stock). Pressure sensor approach seems more likely to mark/damage soft stock but 3D printers use that approach for bed leveling/probing too.

2 Likes

I would have cried and sweared a lot. :frowning: