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

Set work coordinate #1004

Merged
merged 4 commits into from Apr 10, 2018
Merged

Set work coordinate #1004

merged 4 commits into from Apr 10, 2018

Conversation

breiler
Copy link
Collaborator

@breiler breiler commented Apr 10, 2018

Added functionality for setting work coordinates requested in #977.

It's also possible to use simple mathematical expressions such as the following:
set_work_coords

@codecov-io
Copy link

Codecov Report

Merging #1004 into master will increase coverage by 0.1%.
The diff coverage is 23.52%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master    #1004     +/-   ##
===========================================
+ Coverage     29.94%   30.05%   +0.1%     
- Complexity      995     1007     +12     
===========================================
  Files           140      141      +1     
  Lines          9807     9871     +64     
  Branches        895      902      +7     
===========================================
+ Hits           2937     2967     +30     
- Misses         6584     6616     +32     
- Partials        286      288      +2
Impacted Files Coverage Δ Complexity Δ
...r/uielements/helpers/MachineStatusFontManager.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...illwinder/universalgcodesender/GrblController.java 53.73% <0%> (-1.07%) 69 <0> (ø)
...uielements/components/WorkCoordinateTextField.java 0% <0%> (ø) 0 <0> (?)
...desender/uielements/panels/MachineStatusPanel.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...inder/universalgcodesender/AbstractController.java 62.16% <0%> (-0.16%) 95 <0> (ø)
...illwinder/universalgcodesender/model/Position.java 51.72% <60%> (+1.72%) 10 <3> (+3) ⬆️
...com/willwinder/universalgcodesender/GrblUtils.java 69.9% <71.42%> (+0.28%) 82 <4> (+1) ⬆️
...lwinder/universalgcodesender/model/GUIBackend.java 45.84% <85.71%> (+3.33%) 57 <3> (+6) ⬆️
... and 1 more

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 dc49d9e...39d5c5f. Read the comment docs.

@breiler breiler requested a review from winder April 10, 2018 18:08
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.

Wow, this is really cool. I would have expected it to be a lot more complicated, nice job.

@@ -187,7 +187,12 @@ public void resetCoordinatesToZero() throws Exception {
public void resetCoordinateToZero(final Axis coord) throws Exception {
Copy link
Owner

Choose a reason for hiding this comment

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

Does it make sense to have resetCoordinateToZero and resetCoordinatesToZero have default implementations which call setWorkPosition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a good idea!

*
* @author wwinder
*/
public class GrblUtils {
// Note: 5 characters of this buffer reserved for real time commands.
private static final DecimalFormat decimalFormatter = new DecimalFormat("0.0000");
Copy link
Owner

Choose a reason for hiding this comment

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

There is a constant Localization.dfs which can be used here to make sure the decimal separator doesn't change to a comma for different regions. new DecimalFormat("0.0000", Localization.dfs);

}

@Override
public void setWorkPositionUsingExpression(final Axis axis, final String expression) throws Exception {
Copy link
Owner

Choose a reason for hiding this comment

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

Wow, this is really cool. I had no idea you could do something like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Me neither, google was my friend! 😄

@jahnj0584
Copy link

jahnj0584 commented Apr 10, 2018 via email

@winder
Copy link
Owner

winder commented Apr 10, 2018

If the expression starts with +, -, * or / the current value is inserted to the left, otherwise it evaluates whatever you put in directly.

So if the axis is at 10, "+ 2" is evaluated as "10 + 2". But if you type in "2 + 2" it evaluates to 4 even though you are at 10.

The scripting language is javascript so you can put whatever you want in there. I tried the << bitshift operator and it worked, you can chain them together so if you are at 11, * 1 << 1 it evaluates as 11*1<<1 which turns into 22.

@jahnj0584
Copy link

jahnj0584 commented Apr 10, 2018 via email

@flounderscore
Copy link

flounderscore commented Apr 10, 2018 via email

@winder winder merged commit e6bc552 into winder:master Apr 10, 2018
@winder
Copy link
Owner

winder commented Apr 10, 2018

@jahnj0584 it would depend on your order of operations, but I think so. Let us know, I just merged it in :)

@winder
Copy link
Owner

winder commented Apr 10, 2018

@flounderscore you're right, you would have to do 10 * -1

@winder
Copy link
Owner

winder commented Apr 10, 2018

@flounderscore or zero out the axis first so that the math is right.

@flounderscore
Copy link

flounderscore commented Apr 10, 2018

Any chance to make the math feature optional? All my coordinates are typically <0.
Edit: Or explicitly have a "variable" representing the current position, e.g. "#/2 - 5".

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

5 participants