evil-mad / axidraw

Software for the AxiDraw drawing machine
GNU General Public License v2.0
432 stars 131 forks source link

reading the axicli return values from within processing #91

Open stephanschulz opened 4 years ago

stephanschulz commented 4 years ago

I have a processing.org sketch that successfully calls UNIX commands to interact with the axicli API.

In the below code I can get /usr/local/bin/python3 axicli.py version and it prints the version number in the console. BUT when trying to call /usr/local/bin/python3 axicli.py "+sketchpath+"data/AxiDraw_trivial.svg -v --report_time the console print no return info.

All of this works just fine when doing directly from the console. But there I am not using /usr/local/bin/python3 before the command.

Just for reference here is a minimal example:

https://gist.github.com/stephanschulz/8b14e69bf17fd120d9cf51a6eab348f2

oskay commented 4 years ago

This function prints output; it does not really have an intended function of saving that output to a file or stream. (The "real" output of axicli is the output SVG file. If an output file is saved, that, not the "side channel text" is what is saved.)

From the command line, you should be able to use something like axicli AxiDraw_trivial.svg -Tv > log.txt 2>&1 in order to save the output stream to a file called log.txt.

I do not have experience with trying to this within Processing or Java, and it looks to me that the above command wont work within exec.

Here is one discussion of the issue: https://stackoverflow.com/questions/882772/capturing-stdout-when-calling-runtime-exec That, in turn, links to an example solution that I found on archive.org here.

I can see that you're trying to do something similar; this may be a matter of the correct approach but something not quite right in the implementation -- you might try that version and see if you can get it to work.

Some other possible directions could include calling a very short shell script or python script, which returns the correct information to your processing sketch.

Example 1:

In your processing sketch use something like:

    String commandToRun = "/bin/bash "+sketchpath+"script.sh "+sketchpath+"data/AxiDraw_trivial.svg -Tv";

Then, in your sketch folder, add the following file* and name it script.sh:

#!/bin/bash
/usr/local/bin/python3 -m axicli $1 $2 > log.txt 2>&1
cat log.txt
rm log.txt

This is a little "quick and dirty" -- calling axicli with file name (argument $1) and options (argument $2), saving a log, reading out the log, then deleting the log. But it does point a potential way forward.

---------------------------------------------

Estimated print time: 00:03 (minutes, seconds)
Length of path to draw: 0.15 m.
Pen-up travel distance: 0.14 m.
Total movement distance: 0.28 m.
This estimate took: 0:00:00 (Hours, minutes, seconds)

---------------------------------------------
DONE!

Example 2:

In your processing sketch use something like*:

    String commandToRun = "/usr/local/bin/python3 "+sketchpath+"estimate.py "+sketchpath+"data/AxiDraw_trivial.svg";

Then, in your sketch folder, add the following file and name it estimate.py:

import sys
from pyaxidraw import axidraw 
ad = axidraw.AxiDraw()
ad.plot_setup(sys.argv[1])
ad.options.report_time = True
ad.options.preview = True
ad.plot_run()
print(ad.time_estimate)

This program uses the AxiDraw python module, calculates the plot duration, and prints the time estimate such that your program can read the result. To me, this is better, as you get the numeric output, not the human-oriented console output.

---------------------------------------------

3.352

---------------------------------------------
DONE!

(*) Use the actual location of bash/python on your computer.

stephanschulz commented 3 years ago

Hello Windell

We received our 2nd axidraw SE/A3 and it works perfectly.

For a new artwork we want to include the axidraw in, I am considering to move the pen holder to the other side of the X-axis arm (see attached image).

Other than my plotted image needing to be flip / mirrored / rotated are there any mechanical concerns that would worry you?

Thanks for your advice.

Stephan.

On Oct 2, 2020, 9:46 PM -0400, Windell Oskay @.***>, wrote:

This function prints output; it does not really have an intended function of saving that output to a file or stream. (The "real" output of axicli is the output SVG file. If an output file is saved, that, not the "side channel text" is what is saved.) From the command line, you should be able to use something like axicli AxiDraw_trivial.svg -Tv > log.txt 2>&1 in order to save the output stream to a file called log.txt. I do not have experience with trying to this within Processing or Java, and it looks to me that the above command wont work within exec. Here is one discussion of the issue: https://stackoverflow.com/questions/882772/capturing-stdout-when-calling-runtime-exec That, in turn, links to an example solution that I found on archive.org here. I can see that you're trying to do something similar; this may be a matter of the correct approach but something not quite right in the implementation -- you might try that version and see if you can get it to work. Some other possible directions could include calling a very short shell script or python script, which returns the correct information to your processing sketch. Example 1: In your processing sketch use something like: String commandToRun = "/bin/bash "+sketchpath+"script.sh "+sketchpath+"data/AxiDraw_trivial.svg -Tv"; Then, in your sketch folder, add the following file and name it script.sh:

!/bin/bash

/usr/local/bin/python3 -m axicli $1 $2 > log.txt 2>&1 cat log.txt rm log.txt This is a little "quick and dirty" -- calling axicli with file name (argument $1) and options (argument $2), saving a log, reading out the log, then deleting the log. But it does point a potential way forward.

Estimated print time: 00:03 (minutes, seconds) Length of path to draw: 0.15 m. Pen-up travel distance: 0.14 m. Total movement distance: 0.28 m. This estimate took: 0:00:00 (Hours, minutes, seconds)


DONE! Example 2: In your processing sketch use something like: String commandToRun = "/usr/local/bin/python3 "+sketchpath+"estimate.py "+sketchpath+"data/AxiDraw_trivial.svg"; Then, in your sketch folder, add the following file and name it estimate.py: import sys from pyaxidraw import axidraw ad = axidraw.AxiDraw() ad.plot_setup(sys.argv[1]) ad.options.report_time = True ad.options.preview = True ad.plot_run() print(ad.time_estimate) This program uses the AxiDraw python module, calculates the plot duration, and prints the time estimate such that your program can read the result. To me, this is better, as you get the numeric output, not the human-oriented console output.

3.352


DONE! — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

oskay commented 3 years ago

No, it should be fine to run on either side, as far as the primary mechanics are concerned.

oskay commented 3 years ago

Inadvertently closed.