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

fixes #69 #1222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

fixes #69 #1222

wants to merge 3 commits into from

Conversation

carneeki
Copy link
Contributor

Single Block Mode: Useful for testing a g-code program.
To enable

  1. Tools -> Options, go to the UGS tab
  2. Tick the "Enable Single Step Mode" check box.
  3. Tick the "Enable Single Block Mode" check box.
  4. Click OK.

Behaviour
Each line of the file will require pressing play to continue to the next line.
This mode will NOT change the Z position of the tool. For testing programs, I recommend taking the cutter out, and then testing your program.

Untested (please help!)

  1. How comments will be treated.
  2. If pressing CS on Grbl to continue will work.
  3. Other controllers (TinyG, Smoothie etc..). I have only tested this on a Grbl board, which didn't have buttons hooked up so I could not test the above line item.

@codecov-io
Copy link

codecov-io commented Apr 29, 2019

Codecov Report

Merging #1222 into master will decrease coverage by 0.16%.
The diff coverage is 7.84%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1222      +/-   ##
============================================
- Coverage     36.32%   36.15%   -0.17%     
- Complexity     1106     1107       +1     
============================================
  Files           150      150              
  Lines          8587     8638      +51     
  Branches        874      883       +9     
============================================
+ Hits           3119     3123       +4     
- Misses         5156     5202      +46     
- Partials        312      313       +1
Impacted Files Coverage Δ Complexity Δ
...der/universalgcodesender/AbstractCommunicator.java 63.63% <ø> (ø) 21 <0> (ø) ⬇️
...der/uielements/panels/ConnectionSettingsPanel.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...er/universalgcodesender/utils/SettingsFactory.java 8.33% <0%> (-0.11%) 2 <0> (ø)
.../universalgcodesender/utils/GcodeStreamReader.java 65.78% <0%> (-20.42%) 11 <0> (ø)
...inder/universalgcodesender/AbstractController.java 60.38% <0%> (-0.89%) 97 <0> (ø)
...lwinder/universalgcodesender/model/GUIBackend.java 47.5% <100%> (+0.13%) 54 <0> (ø) ⬇️
...illwinder/universalgcodesender/utils/Settings.java 46.15% <16.66%> (-0.74%) 41 <0> (ø)
...der/universalgcodesender/BufferedCommunicator.java 75.51% <9.09%> (-11.69%) 46 <1> (+1)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82ec70c...f3cdcf9. Read the comment docs.

@winder
Copy link
Owner

winder commented Apr 30, 2019

First of all, nice job diving into the guts of UGS! Getting through all of the abstraction layers to plumb in a new feature like this is a big accomplishment.

I think this is working because you've accidentally tied single-step mode and single-block mode to the same parameter, without that real-time pauses would interrupt the stream until the send buffer was full. Related to that, I suspect that the machine doesn't actually do anything until 2 commands are sent (probably not noticeable because the first commands are generally setting up state). In any case, implicitly enabling single-step mode when single-block mode is set is probably the right move. Or maybe I'm mistaken about this because you are pausing at such a low level.

I also think that you might need to send dispatchListenerEvents(PAUSED, ""); to synchronize the communicator (more on this at the end).

I do have some larger concerns specifically because this is cutting across all of the core abstraction layers. In general I've been trying to keep features like this as high level as possible. With that in mind I have two alternative implementations to consider:

  1. add a streamOneCommand() method to IController (implemented generically in AbstractController). GUIBackend:send would be able to call that instead of beginStreaming. This could get tricky because of the state maintained in the controller that gets initialized during beginStreaming, maybe a initStream would be needed followed by beginStreaming or streamOneCommand.
  2. Perform the pause in the commandSent callback. This one is also not perfect because of the real-time pause. Maybe pause could be updated with pause(Boolean realTime). This is probably the least intrusive approach.

In both cases, perhaps GcodeCommand would need to be updated with some sort of "source" or "type" flag (i.e. ad-hoc / streaming command)

I'm also nervous about adding in implicit pauses at this low level. In general most of the core UGS bugs are related to synchronizing state between communicator/controller/backend, so adding features using the approach you're using is sort of a last resort (and one of the major motivators for the UGS platform).

@winder
Copy link
Owner

winder commented Apr 30, 2019

Curious what you think about these comments @breiler since you've been cleaning up these layers a lot in the last year.

!peekNextCommand().getCommandString().isEmpty() ) {

logger.log(Level.INFO, "singleBlockMode: pausing");
pauseSend();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dispatchListenerEvents(PAUSED, ""); is needed here.

Copy link
Owner

@winder winder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it looks like this would work, the relationship between these components is a bit more delicate than you may realize. Let's consider the alternatives before merging this in.

@carneeki
Copy link
Contributor Author

carneeki commented Apr 30, 2019 via email

@breiler
Copy link
Collaborator

breiler commented Apr 30, 2019

It's a lot harder to be on the reviewing side than I imagined...

Regarding the comments, I don't think they reflect the function as you've described yet. I'm thinking that for this method to work, both singleStep and singleBlock needs to be activated and if I were to implement a new Communicator I would probably not get it right based on the comments. Intuitively I would probably expect that the setSingleStepMode would function as a way to enable single stepping a gcode program. So we might have other issues with the naming of some existing methods. 😬

I think you have a good point @winder about these functions being a bit too low level. I have been thinking about adding a function for creating breakpoints on specific lines, but don't have any ideas on strategies on how to get there. But it sounds like this would be possible with the second option.
I would much rather have the pause before the command is sent. That way it could be possible to add a "step next"-action that would peek for the next command in the queue and somehow set a pause flag before sending the next command.

I'm sorry for not having any concrete ideas on how to achieve this...

@winder
Copy link
Owner

winder commented May 1, 2019

@carneeki I think that updating "pause" would be the simplest way to implement this. I'm not sure about allowing jogging during a stream though, seems like that would be hard to get right and potentially dangerous.

There is some documentation about all of this, but it is not detailed or complete:
source
website

@breiler breakpoints would be pretty cool. The gcode stream's line number is the original line number for that reason (the gcode editor / line highlighter uses it in this way to map the original source line to the expanded lines), so even if an arc is expanded to a series of lines each of the segments would be tagged with the original line number.

This package does breakpoints well, and UGS almost has all the pieces available where it could have something similar: https://github.com/duembeg/gsat

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

Successfully merging this pull request may close these issues.

None yet

4 participants