Automatically Upload G-Code Files to G-Code Sender

Will Winder
Posts: 435
Joined: Fri Apr 20, 2012 2:40 pm
Location: Hudson, MA
Contact:

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

Post by Will Winder » Mon Oct 21, 2013 8:10 pm

I would use the python streaming app mentioned earlier and have it process a named pipe. From there you can start your stream simply and have the channel remain open indefinitely, now you just need to make a simple program to search for new files in whatever fashion you like and write them into the named pipe.
ShapeOko #367: Dual-Y drive, Belt on outside, 1000mm Y-Axis, DW660 Spindle, Nema-23 X/Y motors.

Primary developer on Universal Gcode Sender.

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

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

Post by philmurp » Tue Oct 22, 2013 1:41 am

calica wrote: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
Thank you for the response. So i tried to move my motors through matlab using the following code:

s = serial('COM3');
set(s,'BaudRate',9600);
fopen(s);
fprintf(s,'G0 X10')
out = fscanf(s);
fclose(s)
delete(s)
clear s

I got the motor to move once and then it wont respond anymore. Do you have any suggestions on code that would make this work? (I was using this code and then changing the X Coordinate just to test it manually and it wont move after my initial movement no matter what the coordinate is)

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

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

Post by calica » Sat Oct 26, 2013 8:31 am

I don't use grbl so this is mostly theory (but I do use the reprap firmwares). And I haven't used matlab in about 20 years.

Are you attempting to run the same code multiple times and it is failing on subsequent runs. Are you restarting matlab between runs? Have you tried issuing multiple G0 and G1 before the fclose? I think you should do the fscanf after each command is sent. Maybe display "out" to see what grbl is returning. Maybe check if s == null (or matlab equivalent) to see if the com port is being opened consistently. Does fopen() return an error?

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

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

Post by philmurp » Wed Oct 30, 2013 10:39 pm

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.
By using a python file, would I then need to have the Python program up and execute that file in order to stream the G-Code. Currently, I run my program in matlab, it outputs a G-Code text file which can then be uploaded to run my system. However I want a solution for which I can simply run my matlab program and not have to do anything else and the file will be uploaded and my system will run with no user input. I have attempted using matlab to write directly to the serial port but have hit some issues with this. Is there anything you might suggest that will not require any user input? Thanks again.

\

Phil

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 » Thu Oct 31, 2013 12:13 am

You don't have to have the Python program running. You can invoke Python from Matlab, as with any other external command -- something along the lines of "python stream.py thefile.nc". Surely, that must be possible from Matlab.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

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

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

Post by calica » Fri Nov 01, 2013 9:22 am

cvoinescu wrote:You don't have to have the Python program running. You can invoke Python from Matlab, as with any other external command -- something along the lines of "python stream.py thefile.nc". Surely, that must be possible from Matlab.
That is probably an easier solution. Looks like the matlab "system" command will work. http://www.mathworks.com/help/matlab/ref/system.html

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 » Fri Nov 01, 2013 11:08 am

That's exactly what you need.
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 » Fri Nov 01, 2013 3:20 pm

calica wrote:
cvoinescu wrote:You don't have to have the Python program running. You can invoke Python from Matlab, as with any other external command -- something along the lines of "python stream.py thefile.nc". Surely, that must be possible from Matlab.
That is probably an easier solution. Looks like the matlab "system" command will work. http://www.mathworks.com/help/matlab/ref/system.html
Thanks for the suggestion however I am running into a problem with this:

When I use code:

system('python test.py 2')

My matlab responds with:

??? Undefined function or method
'python' for input arguments of type
'char'.

There is not to much literature online about this so I am stuck on how to fix this.

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 » Fri Nov 01, 2013 5:20 pm

I don't know Matlab, but my reading of the documentation suggests that it should work. You may want to read this:
http://www.mathworks.co.uk/help/matlab/ ... l#f0-38522
It seems that simply saying

Code: Select all

!python test.py 2
should work.
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 Nov 03, 2013 5:45 pm

cvoinescu wrote:I don't know Matlab, but my reading of the documentation suggests that it should work. You may want to read this:
http://www.mathworks.co.uk/help/matlab/ ... l#f0-38522
It seems that simply saying

Code: Select all

!python test.py 2
should work.
So I have gotten the python file to work in python and control my motors. However when I use the following code in matlab: system('python pgcode.py') (file name is pgcode.py)

I receive the following error:
'python' is not recognized as an internal or external command,
operable program or batch file.

I have set a PATH for python, and python and the python file are in Matlab's current directory. Reading online it is often an issue of not having python in the correct directory but i believe that I have this correct so I am not sure what to do.

Post Reply