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

Custom G-Code - "current_position" - incorrect? #3958

Closed
dumitrugrl opened this issue Nov 9, 2023 · 2 comments
Closed

Custom G-Code - "current_position" - incorrect? #3958

dumitrugrl opened this issue Nov 9, 2023 · 2 comments
Labels
fix is live in the last release Please download /build the last release and try to reproduce.

Comments

@dumitrugrl
Copy link

dumitrugrl commented Nov 9, 2023

Using the current_position inside different custom G-Code sections does not seem to return the expected tool position

I was expecting it to return the coordinates of the previous G1 line present before evaluating the variable.
Is this the right assumption?

At a tool change, I am trying to compare the current X with a minimum limit allowed (stored in another variable) to avoid a collision before moving towards zero.

Any suggestions on how to achieve this?

I noticed that the variable is set using "unscaled()" function, but I am not sure what that does.

X shows -117.304, while I was expecting 64.482 (from the last move executed).

image

Project file & How to reproduce

N/A

Version

2.5.59

Operating system

windows 10

Printer model

Creality CR-10S

@dumitrugrl
Copy link
Author

dumitrugrl commented Nov 9, 2023

I don't know if the unscaled values are used some place else, but making the changes below (in the mentioned method) returns the expected values.

src\libslic3r\GCode.cpp -> std::string GCode::placeholder_parser_process

// --- original line
default_config.set_key_value("current_position", new ConfigOptionFloats({unscaled(m_last_pos.x()), unscaled(m_last_pos.y()) }));

// --- modified
Vec3d vpos = this->writer().get_position();
double x_ = vpos.x();        
double y_ = vpos.y();        
default_config.set_key_value("current_position",new ConfigOptionFloats({x_ , y_}));   // <- this gives the g-code coordinates

@supermerill
Copy link
Owner

mmm
First i though of using point_to_gcode(m_last_pos)
Then I guessyour idea of using directly the gcodewriter position is safer.
For what i have checked, it's only updated in the same thread right now.
I added the z as it's available this way.
Also added current_object_position to have the position of the current object. current_position-current_object_position should get you the old value (if there is no extruder offset)
thank you for the report & fix.

@supermerill supermerill added the fixed for the next version That means that you should be able to test it in the latest nightly build label Nov 20, 2023
supermerill added a commit that referenced this issue Nov 20, 2023
add current_object position for the position of the current object
#3958
thanks to @dumitrugrl
@supermerill supermerill added fix is live in the last release Please download /build the last release and try to reproduce. and removed fixed for the next version That means that you should be able to test it in the latest nightly build labels Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix is live in the last release Please download /build the last release and try to reproduce.
Projects
None yet
Development

No branches or pull requests

2 participants