Automatically Upload G-Code Files to G-Code Sender

philmurp
Posts: 42
Joined: Sat Oct 12, 2013 5:26 pm

Automatically Upload G-Code Files to G-Code Sender

Post by philmurp » Sat Oct 12, 2013 7:11 pm

Hello,
I am looking to automate my CNC positioning machine. I have written a program that will automatically compile a .txt file with G-Codes. However I still have to manually upload that file into my g code sender (GRBL controller is what I'm using) in order to run my stepper motors. I am asking if there is anyway to have the G-Code sender automatically search for a file name and upload that .txt file in order to run my stepper motors without any manual input. I am a new user of GRBl interpreters and so whether a solution to this requires a software modification or if you have a g code sender program that already does this, any help is greatly appreciated!

Gadgetman!
Posts: 1061
Joined: Sun Aug 25, 2013 12:44 pm
Location: Norway
Contact:

Re: Automatically Upload G-Code Files to G-Code Sender

Post by Gadgetman! » Sat Oct 12, 2013 10:04 pm

Worst case, make the tool you're using send 'COPY CON filename.txt COMx' as a command to the OS...
(COMx being the COM-port that the nC machine is identified as)

The file will be sent over as quickly as the port allows, and the controller will probably be overrun with commands pretty soon, but at least it will all go automatic...

There's a GOOD REASON why you shouldn't automate this step...

Bad Code Break Stuff...

You don't run code like this without constant supervision.

Also, on most forums, doubleposting is considered a bit 'naughty'. And if you absolutely have to post the same question twice, add a link to the first post in the second, and write that all answers should go in the first post.
Otherwise you just end up with a lots of people wasting their time writing comments and suggestions already posted, or asking for details that you have already given in the other post.
It gets confusing and horrible timewaster.
Weird guy...
Shapeoko 2014F: 1000mm X/Y, 300W Quiet Cut spindle, Arduino Uno/G-shield and GRBL 0.9i
15x30 drag chains, custom spindle mount, 9mm belts, 8mm endplates, 6mm motor plates.

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Automatically Upload G-Code Files to G-Code Sender

Post by cvoinescu » Sat Oct 12, 2013 11:18 pm

A simple copy doesn't work, because GRBL does not use serial flow control (at least not in a form recognized by the operating system). The G-code senders have some funny logic to send the commands as fast as GRBL can accept them, but no faster. Ideally, GRBL would have flow control, but hardware serial flow control can't work on the Arduino, and software flow control (XON/XOFF) isn't implemented.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

Gadgetman!
Posts: 1061
Joined: Sun Aug 25, 2013 12:44 pm
Location: Norway
Contact:

Re: Automatically Upload G-Code Files to G-Code Sender

Post by Gadgetman! » Sun Oct 13, 2013 10:43 am

Maybe I should have put a couple of smileys in or something...

I was just tossing a dumb idea after another dumb idea.
(Of course, I forgot that not everyone has the same experience with slow serial units and high-speed ports. Imagine an oldfashioned A0 pen plotter that suddenly gets lots of commands all garbled up because the buffer overflows... Not good... And they have limit switches and all kinds of safeguards... )
Weird guy...
Shapeoko 2014F: 1000mm X/Y, 300W Quiet Cut spindle, Arduino Uno/G-shield and GRBL 0.9i
15x30 drag chains, custom spindle mount, 9mm belts, 8mm endplates, 6mm motor plates.

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Automatically Upload G-Code Files to G-Code Sender

Post by cvoinescu » Sun Oct 13, 2013 1:31 pm

There is a Python program in the GRBL git repository that sends code to GRBL, using the correct flow control (there are two versions, a dumb one that sends one command at a time and waits for confirmation, and a smart one that sends as many commands as GRBL has buffer space for). That can be used to automate the sending of G-code.

I don't have a problem in principle with sending G-code automatically -- especially if it's not for milling, but for something more benign. You can use GRBL to control your window curtains, for instance. Or maybe a camera slider. Even for milling, it's OK to start with a text file, and have one command that processes that file into G-code and sends the G-code to the machine (after some careful testing and simulation to work out the bugs in the conversion, of course). If all you do is engrave some tags, for instance, there's no point in simulating and checking the G-code for every run. Just be sensible about it, always supervise your machine, and have the emergency stop button easily accessible.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

philmurp
Posts: 42
Joined: Sat Oct 12, 2013 5:26 pm

Re: Automatically Upload G-Code Files to G-Code Sender

Post by philmurp » Sun Oct 13, 2013 6:18 pm

cvoinescu wrote:There is a Python program in the GRBL git repository that sends code to GRBL, using the correct flow control (there are two versions, a dumb one that sends one command at a time and waits for confirmation, and a smart one that sends as many commands as GRBL has buffer space for). That can be used to automate the sending of G-code.

I don't have a problem in principle with sending G-code automatically -- especially if it's not for milling, but for something more benign. You can use GRBL to control your window curtains, for instance. Or maybe a camera slider. Even for milling, it's OK to start with a text file, and have one command that processes that file into G-code and sends the G-code to the machine (after some careful testing and simulation to work out the bugs in the conversion, of course). If all you do is engrave some tags, for instance, there's no point in simulating and checking the G-code for every run. Just be sensible about it, always supervise your machine, and have the emergency stop button easily accessible.
To be clear I am using this G-Code in an automted retrieval system. So, I will be given an input of products that need to be removed from a shelving unit, and my G-Code will move the device to the required coordinates where I will then retrieve the units required. So no milling required.

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Automatically Upload G-Code Files to G-Code Sender

Post by cvoinescu » Sun Oct 13, 2013 11:24 pm

philmurp wrote:To be clear I am using this G-Code in an automted retrieval system. So, I will be given an input of products that need to be removed from a shelving unit, and my G-Code will move the device to the required coordinates where I will then retrieve the units required. So no milling required.
Automated retrieval, window curtains, fish feeding -- same difference. :D

Seriously, though, I love it when G-code is used in more unexpected ways. If you have some time, can you give us more detail about the system, or point us in the right direction? Pure curiosity, of course.

The two files I was talking about are simple_stream.py and stream.py from the script/ directory in the GRBL Git repository.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

philmurp
Posts: 42
Joined: Sat Oct 12, 2013 5:26 pm

Re: Automatically Upload G-Code Files to G-Code Sender

Post by philmurp » Mon Oct 14, 2013 1:25 am

cvoinescu wrote:
philmurp wrote:To be clear I am using this G-Code in an automted retrieval system. So, I will be given an input of products that need to be removed from a shelving unit, and my G-Code will move the device to the required coordinates where I will then retrieve the units required. So no milling required.
Automated retrieval, window curtains, fish feeding -- same difference. :D

Seriously, though, I love it when G-code is used in more unexpected ways. If you have some time, can you give us more detail about the system, or point us in the right direction? Pure curiosity, of course.

The two files I was talking about are simple_stream.py and stream.py from the script/ directory in the GRBL Git repository.
Heres a bit more about the project:
Its an automated inventory control type problem. The front end of the system involves the business owner capturing an image of their current inventory level (think shelves of a newsstand). Then image analysis in Matlab will provide current inventory levels based upon that image in a vector format. Based upon set reorder points Matlab code will then generate what products need to be packed for today and how many of each product. Based upon preset locations in our shelving system, my code with then output a G-Code that will run my automated retrieval system to each location where product needs to be retrieved. I am using a timing belt system to run my retrieval unit (I am in the process of calibrating my stepper motors to run my unit to the correct locations). Then the actual retrieval will be done using a pneumatic air cylinder that will move into the shelves and pick up units with vacuum suction heads and then places the product on a conveyor to be collected,packed, and shipped to the business owner. The reason I am looking to automate the sending of my G-Code is because I am at the point where given an original image I can output a .txt file with G-Code that will run my retrieval system. However in order to send this G-Code to my boards/shield ( I am using a gshield v4 bundle) I have to manually upload this text file into the G-Code sender. (The interface I am using for this is 'g code controller' it was recommended by Synthetos as a supported interface with the gshield) This isn't the end of the world if the only way to do it is manually, but ideally I would like my system to be able to run completely automatically from start to finish.

I haven't been able to experiment with the suggestions you gave yet, but I will early this week and give you feedback. Thanks for all the help it is much appreciated, and feel free to critique my system in general if you see something that is odd (I am in the early testing phases and I am sure I will run into lots of issues :).

calica
Posts: 107
Joined: Wed Apr 11, 2012 8:13 am

Re: Automatically Upload G-Code Files to G-Code Sender

Post by calica » Mon Oct 14, 2013 11:29 pm

It sounds like your system has fewer moves that go a greater distance. Probably no need to worry about streaming multiple commands. Just send one gcode and wait for a response from grbl (read until a newline). Communication is via COM port (or tty on *nix). Should be simple to write to the com port rather than a text file, remove a "moving part".

Some info on using a serial (com) port from Matlab: http://www.mathworks.com/help/matlab/se ... vices.html

Gadgetman!
Posts: 1061
Joined: Sun Aug 25, 2013 12:44 pm
Location: Norway
Contact:

Re: Automatically Upload G-Code Files to G-Code Sender

Post by Gadgetman! » Tue Oct 15, 2013 8:09 am

How big is your system?

Can we have some pictures?
Please?

Years ago, I wanted to build 'something' to handle my CD and DVD collection, but as Makerslide didn't exist, and I had no idea how to build the moving bits without taking out a mortgage, it never happened. These days, all my CDs are ripped into iTunes, and my DVDs gets the MakeMKV/Handbrake treatment to end up on a 2TB drive(physical media goes into big piles in the attic), so it's a bit redundant now.
My electronic components and my sci-fi books, though...
Weird guy...
Shapeoko 2014F: 1000mm X/Y, 300W Quiet Cut spindle, Arduino Uno/G-shield and GRBL 0.9i
15x30 drag chains, custom spindle mount, 9mm belts, 8mm endplates, 6mm motor plates.

Post Reply