DIY closed loop cnc machine

HI all, hope you are doing well.

My question is it possible to build to make diy closed loop cnc machine?

Recently,I used rotary encoders with stepper motors(a NEMA 17 and a chinese optical quadrature encoder) and wrote a sketch to control the shaft position via strings recieved from USB. I used PID and stepperaccl library.

AFAIK,grbl doesn't support optical encoders feedback.So step missing might be an issue as i intend to use my cnc to mill aluminium. So i was wondering how hard it is going to be to write a g code decoder sketch for Universal G-code Sender along with my stepper control sketch to control a cnc.

Am i missing something? seems fairly possible to me.

forgive me for my noobness.

The software to use feedback with steppers will be hard to find because a well designed machine will not need feedback. The steppers will be sized and powered so that they will not miss steps at reasonable movement rates.

Got my answer,Thank you @groundFungus.

So i need to use over sized steppers.They are costly,thought i might get around using feedback xD.

saminhasan1999: So i was wondering how hard it is going to be to write a g code decoder sketch for Universal G-code Sender along with my stepper control sketch to control a cnc.

First, let me say that I agree 100% with @groundFungus.

You should also be aware that reading encoder pulses without missing any is hard work for an Arduino.

However if you are really set on building your own feedback system I suggest that you interpret the GCode on your PC and just send to the Arduino the data needed for the number of steps on each axis.

Writing a GCode interpreter on a PC (for example with Python) would be much easier than on an Arduino. It would also take a large computation load off the Arduino.

...R

So i need to use over sized steppers.

I did not say oversized (though that won't hurt), I said properly sized. That means that you choose a motor based on the torque that you need plus a safety factor.

Sorry guys,forgot to explain my intension, wanted to use cheaper steppers to ,which are sort of under powered.

So now my plan is to write a scrpit in python to decode Gcode and send the shaft position using pyserial and csv. and in the arduino ,the sketch be will for decoing the csv values for each of the motors shaft and move the shaft to the desired position using encoder feedback.

Also, just noticed,arduino does miss counts at high rpm or if i use 2 quadrature encoder at their highest resolution(using change to trigger interupts).

I have blue pill(stm 32) .Can i use it as a replacement for arduino without changing the code?

Is there any solution to encoder count miss?

Thank you ,You guys are my hero

You asked the question:"Is there any solution to encoder count miss?". That is definitely the wrong question. The correct question is: "is there a way for the Arduino to detect a missed step". You can only do something about a missed step if you find you have one.

Paul

Sorry sir for my bad english, indeed the arduino missed that pulse(not the encoder). I used the encoder library written by PaulStoffregen. It works fine and i want to keep it that way.

is there any solution to for arduino failing to register encoder pulses?

Also ,does arduino sketches run on stm32 without a problem?

saminhasan1999: is there any solution to for arduino failing to register encoder pulses?

Write a better program or use a faster microprocessor (or both).

You have not told us how many encoder pulses per second will be produced when all the motors are moving at maximum speed.

And, supposing your encoders are working properly and detect that a motor has missed a step - what can you do about it? Most CNC machining operates on the basis that the cutting tool moves steadily to give a smooth cut. If the tool stops because the load on the motor is too great there will be no means to force the motor onwards. Also the other axes will have moved on so everything will be out of step. IMHO the correct approach is to select a feed rate that is within the capability of your motors.

...R

Even when most here won’t like the answer: For propper CNC, get a propper CNC controller. Go to http://linuxcnc.org, get a MESA card (~100 bucks) and let LinuxCNC do the magic.

Alternative 1: Get integrated servo motors instead of steppers. Cost is ~ +20.- per motor compared to stepper + inferior stepper driver.

Alternative 2: Build the servo motor yourself: https://www.youmagine.com/designs/dc-motor-closed-loop-control-software

Alternative 3: Go to https://www.maslowcnc.com/, it used Arduino Uno and 3 axis with encoders.

@BluePill: I have written a modified version of GRBL 1.1 for BluePill with 2xCoreXY (aka foamcutter) + “RC Servo as Z-Axis” based on https://github.com/yaroslavVl/6-AXIS-USBCNC-GRBL.git - this is a good base. Anyway, no match with LinuxCNC.

There are $15 optical encoders with a resolution of 600 pulses per revolution and a stepper should be able to do 25 revolutions per second. This gives 15000 pulses per second or 30000 interrupts per second for a quadrature encoder. If the Arduino contains code that blocks interrupts for more than 2/30000 of a second (66 micro seconds) then interrupts will be lost.

That's why you should use a decent CNC contoller and/or integrated servo motors.

zwieblum:
Even when most here won’t like the answer: For propper CNC, get a propper CNC controller. Go to http://linuxcnc.org, get a MESA card (~100 bucks) and let LinuxCNC do the magic.

That won’t solve the problems caused by an inadequate stepper motor.

And with a suitable stepper motor Arduino code should be fine.

…R

thanks to you all for your valuable time and sharing your experience, going to buy proper motors first and looks like ditching the closed loop thing is a far easier option.