Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause plot programmatically #75

Closed
aarondfrancis opened this issue Feb 6, 2020 · 17 comments
Closed

Pause plot programmatically #75

aarondfrancis opened this issue Feb 6, 2020 · 17 comments

Comments

@aarondfrancis
Copy link

aarondfrancis commented Feb 6, 2020

Hey there,

Is there a way to pause a plot via GPIO or the CLI as if the physical button had just been pressed?

I see that there is some sort of "alternate pause" available

SC,13,<use_alt_pause> - turns on (1) or off (0) alternate pause button function on RB0. On by default. For v1.1 boards, it uses RB2 instead. (new in v2.0)

but am not quite sure how to use it. I'm not sure where the RB2 pin is either.

Thanks in advance for any help!

@oskay
Copy link
Contributor

oskay commented Feb 6, 2020

Can you please clarify your question? What is it that you are trying to pause, and how do you want to pause it? Are you plotting from Inkscape, or from the CLI, or "via GPIO"?

Also: The document that you have linked is (as it says there) deprecated in its entirety. Please refer to the current EBB documentation, hosted at: http://evil-mad.github.io/EggBot/ebb.html

@aarondfrancis
Copy link
Author

Sure... I can try.

When a file is being plotted, one can push the pause button and it will pause and store the appropriate resume data.

Is there a way to pause a currently running plot without pushing the button? (And not by changing the layer name to have a preceding !.)

I'm happy with any method you can provide. If it's possible using the CLI I can do that, if it's possible by using some combo of GPIO and the RB0 (?) pin, I can do that.

I've read that there is an alternate pause functionality, from the documentation you linked:

SC,13,use_alt_pause - turns on (1) or off (0) alternate pause button function on RB0. On by default. For EBB v1.1 boards, it uses RB2 instead.

I'm not sure how to use that though. Since it's on by default, if I hit the RB0 pin (wherever that is) with a HIGH, will the axidraw pause itself (and store the resume data) as if the physical button was pressed?

Hope that's clearer.

Thanks

@oskay
Copy link
Contributor

oskay commented Feb 6, 2020

Are you plotting from the AxiDraw CLI or from Inkscape, or something else?

@aarondfrancis
Copy link
Author

CLI

@oskay
Copy link
Contributor

oskay commented Feb 6, 2020

And you would like to provide an externally-generated I/O signal to control initiate a pause?

@aarondfrancis
Copy link
Author

I can if that's the only way! Ideally I'd like to signal the running process itself with e.g. SIGINT, as that'd be easier. But if that's not possible an I/O signal to the board is fine.

@oskay
Copy link
Contributor

oskay commented Feb 6, 2020

SIGINT?

There is not presently any mechanism in place for a third-party process to gracefully stop (or otherwise modify) a plot in progress via the CLI. However, the code is open source, so you might want to consider adding a check for a separate internal signal in parallel with the "button press" detection that works with your application.

The "alternate pause" feature on B0 works as follows: There is an internal pull-up on input pin B0. If you ground that pin, then the EBB will record that event as though you had pressed the PRG button. (We apparently need to document this better in the EBB command set documentation.)

The set of three pins directly above the three pins used for the servo connector are the "B0" connector. These three pins are ground, +5V, signal B0, reading from the edge of the board inward.

Here is an example photo showing an external pause button connected to B0:
IMG_1699

@aarondfrancis
Copy link
Author

😂

Haha way less interesting than that, SIGINT like kill -2 https://pubs.opengroup.org/onlinepubs/7908799/xcu/kill.html.

My ideal would be starting a process via CLI and then sending an interrupt signal would pause the process, allowing the axidraw to be sent back to home position. Currently if I need to stop a plot I send kill -9 which means the internal positioning is lost and I have to move it back home manually.

I'll take a look into the CLI code and see if I can find where the button press code is and perhaps weasel a solution in there. I don't know python very well, but it can't be too difficult to read it.

Thanks for the info on the B0 pin, that's really helpful. I'm running the whole thing off a Pi so I may look at wiring one of the Pi's GPIO pins to the B0 and then I can gracefully pause it that way.

Those are the things I needed to know, I appreciate the help!

@oskay
Copy link
Contributor

oskay commented Feb 6, 2020

Great. We'll look into adding a software-controlled pause in the future. The hardest part from my perspective is to see how it would be initiated-- what the interface would look like.

@oskay oskay closed this as completed Feb 6, 2020
@aarondfrancis
Copy link
Author

https://stackoverflow.com/a/1112350/1408651

This is how I envision it:

  • User starts a plot with python axicli.py file.svg
  • Axidraw starts
  • User hits Ctrl+C for some reason
  • CLI behaves exactly as if the physical button on the EBB was pressed.

@aarondfrancis
Copy link
Author

aarondfrancis commented Feb 7, 2020

Last question!

I'm trying to add an option --pause_if_exists to the CLI, but I can't seem to get it to pass all the way through for the life of me.

I've tried this in axidraw.py

self.OptionParser.add_option("--pause_if_exists",\
                    type="string", action="store", dest="pause_if_exists",\
                    help="Pause the plot if this file exists")

and this in core.py

parser.add_argument("--pause_if_exists",\
                help="Pause if file exists")

and I see there is also common_options.py?

Ultimately, I'm trying to add

if self.options.pause_if_exists is not None and path.exists(self.options.pause_if_exists):
            pause_state = 1

in axidraw.py. I've gotten the axidraw to pause by hardcoding the file path in the CLI, but now I'm trying to pass a path in and I can't seem to decipher where all I need to add the option code.

Thanks!

@oskay
Copy link
Contributor

oskay commented Feb 7, 2020

Any reason not to just use two files there, one to enable the option, the other to assert pause?

@aarondfrancis
Copy link
Author

aarondfrancis commented Feb 7, 2020 via email

@oskay
Copy link
Contributor

oskay commented Feb 7, 2020

There are a few layers deep that you need to feed those options, including the CLI core, axidraw_control, and axidraw.

As an alternative, I think that you might be able to use different configuration files to specify this. If you use a different config file per machine -- identical except for port name -- that should work, and I expect that axidraw_conf.port is not nulled out.

We've often seen driving one AxiDraw per Pi, but it's new for us seeing multiple AxiDraws per Pi.

@aarondfrancis
Copy link
Author

Interesting. I will try that tomorrow morning. Thanks!

@aarondfrancis
Copy link
Author

Solved it!

I thought that adding a param would be the easiest option, but as you said there are so many layers to get that to work.

It turns out the SIGINT was trivial. Here's what I ended up adding (along with a few imports at the top)

image

Not sure if this is PR worthy, as I'm unsure how common the use-case is. Regardless, it's working for me now!

I can send a kill -2 [pid] and it exits gracefully.

Thanks for all your help!

@oskay
Copy link
Contributor

oskay commented Feb 7, 2020

Thanks-- we'll think about this and see if something like that fits in with our general plans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants