CNC machine using UCGS (Universal GCode Sender) with an Arduino with a feedback

Hello :smiley:

I am working on this project for a month and I finished the design and everything about that but know I am not very familiar with gcodes and i know some basic command but i dont know if there is a commands that can help me solve my problem

So here is my problem I want to add a feedback(current position and the speed of the motors) to my cnc machine using the UCGS (Universal G Code Sender) and I dont know if it is possible or not or how to make it ?

Or

can I use a different ways that by putting an encoder or count the pulses of the stepper motor to know my feedback then send it the UCGS .

That does not sound like a question for this Forum. The GCodeSender is a PC program. I suggest you ask on some of the CNC forums or maybe there is a help website for GCodeSender.

I have never used the program but I have always assumed it is a dumb program that just sends whatever text it finds in a GCode file.

...R

I agree with you

i started to write my own code but it is not working anyway if u are familiar with coding cnc machine i can post the code that i am working on it and i will ask on the cnc forum

Adamshehab:
i started to write my own code

For what?

...R

I started to write my own code for cnc machine the control of the stepper motor instead of using the firmware

Gcode can not control feedback from the motors. Their is a Gcode motor speed control but it just sets a value, it can not monitor anything. Gcode is like a talk only language.

I have deleted two identical copies of this topic in different sections of the forum.

DO NOT CROSS-POST, CROSS-POSTING WASTES TIME.

Adamshehab:
I started to write my own code for cnc machine the control of the stepper motor instead of using the firmware

That's an interesting project but you will also need a suitable companion program for your PC if you want feedback. As @Grumpy_Mike has said, GCode is a "talk only" language.

And, rather than writing a new Arduino program to interpret and apply GCode I suggest you interpret the GCode on the PC (which is a lot more powerful) and then the PC can send simple data for each move to the Arduino and, if you want, the Arduino can send data back to the PC program.

...R

This is probably a silly question, but here it is anyway. Why to you want feedback from your CNC machine? What will you do with that information? By the time you get that information on the PC, the CNC machine has already moved on to the next instruction.

Paul

Paul_KD7HB:
By the time you get that information on the PC, the CNC machine has already moved on to the next instruction.

Indeed - or destroyed the work piece or the tool :slight_smile:

...R

Robin2:
And, rather than writing a new Arduino program to interpret and apply GCode I suggest you interpret the GCode on the PC (which is a lot more powerful) and then the PC can send simple data for each move to the Arduino and, if you want, the Arduino can send data back to the PC program.

...R

You now opened a new door for me which is try to interpret the gcode i started to search about this now but i want to understand it well first gcode interpret on pc(still dont know how if u have any links or videos it will be very helpful) then send it to arduino after i can resend back to pc

But i want to clarify more about my project ,I have a cnc machine that is working now by the ugcs and i want to check if the machine is working right for example i will give command to x axis to move 10 cm to the right if my feedback is 10 so no problem but if it is like 9.5 or something i want to correct it

So my method is to construct a controller on arduino to give it the most accurate position by arduino instead of using the ugcs and if there is software with a feedback feature that will be great too. I thought it is possible but ik it is hard and you confirmed on this too :smiley: but if ur way can hlep me on this to get a feedback then correct it that will be too good .I waiting for any help or tios on interpret the gcode on the pc .

and thanks Robin2 for ur help and concern

Paul_KD7HB:
This is probably a silly question, but here it is anyway. Why to you want feedback from your CNC machine? What will you do with that information? By the time you get that information on the PC, the CNC machine has already moved on to the next instruction.

Paul

no it is not .No worries :slight_smile: ,but here is the thing i want to check if my machine is working good or not .For example i will give command to x axis to move 10 cm to the right if my feedback is 10 so no problem but if it is like 9.5 or something i want to correct it.But u said that the by the time i get the feedback the machine will move to next instruction that is true but i by my feedback if the feedback is right i will let my machine to move to next one if it is not i will correct the error then move to the next one .That my thoughts about the feedback by I am want to know ur thoughts to. It can help me alot

thanks

You need to put shaft encoders on each axis with better resolution that the motors have. Then you have the Arduino monitor these along with the Gcode from your PC.
Then you need to feedback a yes or no after each command and not go on to the next Gcode command until you get an acknowledgment from the Arduino.

While it could be done it is messy and involves hacking your PC code to wait for the acknowledgment.

It probably won't work for things like circles and arcs.

Adamshehab:
But i want to clarify more about my project ,I have a cnc machine that is working now by the ugcs and i want to check if the machine is working right for example i will give command to x axis to move 10 cm to the right if my feedback is 10 so no problem but if it is like 9.5 or something i want to correct it

If all you want to do is verify that the machine is moving the correct distances I suggest you get an electronic vernier calipers and clamp it firmly to one part of the machine and then cause a movement to happen.

If you just want to verify that backlash in the mechanism has been catered for I reckon a dial test indicator would be more appropriate

That sort of verification is not something you need to do continuously so I would not try to build it into my control system.

Having a program that tells you, after the fact, that things have gone wrong is not much help. It will be obvious that things have gone wrong :slight_smile:

...R

Grumpy_Mike:
You need to put shaft encoders on each axis with better resolution that the motors have. Then you have the Arduino monitor these along with the Gcode from your PC.
Then you need to feedback a yes or no after each command and not go on to the next Gcode command until you get an acknowledgment from the Arduino.

While it could be done it is messy and involves hacking your PC code to wait for the acknowledgment.

It probably won't work for things like circles and arcs.

Yes that is exactly what i am looking for like encoders to a shaft then take the reading from the arduino then from this reading i have to check it with my gcode but here is the thing how to can i compare these 2 reading ?

i thought about it that i can compare them on the arduino then if it is zero then get next command if it is different i need to send like alert to the machine that there is an error and fix it .So I have a gcode that is on the ugcs (universal gcode sender ) running and i have encoder on the arduino if i just can connect them together that will solve my problem

I tried to hack the GRBL code but i could not actually

but what u stated above is perfect if we can apply it so if you can hit me with more details it would be great specially i did not find anyone before did it so I have limited sources

thanks Grumpy_mike

Robin2:
If all you want to do is verify that the machine is moving the correct distances I suggest you get an electronic vernier calipers and clamp it firmly to one part of the machine and then cause a movement to happen.

If you just want to verify that backlash in the mechanism has been catered for I reckon a dial test indicator would be more appropriate

That sort of verification is not something you need to do continuously so I would not try to build it into my control system.

Having a program that tells you, after the fact, that things have gone wrong is not much help. It will be obvious that things have gone wrong :slight_smile:

...R

For me i want to know for the backlashes but reckon test i can test it after i finish or before i start but with feedback i can at least stop the machine when backlashes occurs and safe the work piece from a few mm error but I have a question you stated to make a interpret the gcode on the pc how can i do such thing ?

this is seems good for me and by connecting it with the reading of the arduino by the encoder it seems it be good idea instead of writing a new code from scratch

I wrote some Python code that interprets simple GCode and sends a message to the Arduino for how many steps each motor needs to make on my small lathe. Actually the PC sends 4 items of data - the total number of microseconds for the move and, for each of the 3 motors, the number of microseconds between each step.

The PC program has a file that contains the number of steps per millimeter for each axis and the number of extra steps needed to compensate for backlash when the direction changes. The allowance for backlash was determined by measurement with a DTI.

The PC program also displays a screen that allows manual control of the motors - for example to position them at the required starting point.

...R

but what u stated above is perfect if we can apply it

Part of the point of my answer was to illustrate exactly what is involved and how difficult it is. I would have thought the hardest part is to hack the ugcs gcode sender as I suspect that you don't have access to the source code of this?

Unless you can do this then you will have to write one in a language like Processing. I did a program to send Gcode in this project Proxxon MF70 Miller CNC CONVERSION

I tried to hack the GRBL code but i could not actually

That is probably what you need to do. The code in the above project is also for an Arduino to drive stepping motors and it does display a global count of the accumulated X Y Z positions ( I think it was written a long time ago ). You have to strip the time delays and actual motor movement from this code and just use the accumulated motor position. This you then compare with the shaft encoder readings. However you need to compensate for the different resolution between the motors and the encoders. What resolution are you motors? It could be that they move too fast with too much resolution to do this on a 16MHz Arduino.

As I said this is a very advanced project and while it might seem a simple solution the implementation of it requires a lot of code skills. As others have pointed out this is not a normal way of correcting what basically can only be a skipping motor based on mechanically overloading it, or compensating for backlash.

In project terms we call this an X-Y Problem

I'm a CNC miller turner grinder gundriller, fanuc, mazak, okuma, heidenhain and more

Why not download Mach3, it's free in demo form and will run up to 10,000 lines of code in this spec. it'll give you a great introduction to G-Code, I think I paid around $100 for a production unlimited licence.

I think the stock demo will let you hook up encoders no problem, it also has backlash function so the the emulator removes backlash at the start of a movement.

Post up or pm your code and I'll drop it into my Mach3

Mach3 will need an older pc with onboard serial port (not a card) Windows XP will run best, you dont need to connect it to a cnc to start learning and running programs.

Phil.

Robin2:
I wrote some Python code that interprets simple GCode and sends a message to the Arduino for how many steps each motor needs to make on my small lathe. Actually the PC sends 4 items of data - the total number of microseconds for the move and, for each of the 3 motors, the number of microseconds between each step.

The PC program has a file that contains the number of steps per millimeter for each axis and the number of extra steps needed to compensate for backlash when the direction changes. The allowance for backlash was determined by measurement with a DTI.

...R

Sorry for the late reply but i was working on hacking the problem the ugcs and finally did it (I dont know if it right to say that here or not but i am proud of myself :))) but anyways i can give u the code if u want it is in java but the new problem it is very big and i cant get the controller to convert it into C so if u can pass me ur own code and i will try make a similar one that will be very good to me if it is ok and available with you for sure

because i need just a working one to put my encoder and the feedback system to to see the outcome

thanks for ur help