synthetos / g2

g2core - The Next Generation
Other
622 stars 296 forks source link

Homing somewhat broken on rotary axes #435

Open justinclift opened 4 years ago

justinclift commented 4 years ago

Came across an interesting bug (with workaround) while setting up homing for the A axis.

The problem line of code is here:

https://github.com/synthetos/g2/blob/9fd1dae6aa9f7285894d8c1f31efefc18c1447f0/g2core/cycle_homing.cpp#L238

That code works for linear axis, where "max" - "min" yields a reasonable value. But it doesn't work for rotary axis with max and min both == -1, which we use to indicate an infinite rotary axis (360 degree rotation).

My initial dodgy workaround is to set my A axis min value to -370 (one full turn, with a bit extra for good measure), and max to 370.0 (ditto). This allows homing to work.

The proper approach is probably to check if the given axis being homed is both rotary and has -1 for both min/max values. For that specific situation, using a travel_distance of 360.0 + latch.backoff seems like it would be correct.

For rotary axes with less than 360 degree rotation, the existing calculation (max - min + latch.backoff) will probably be ok. Shouldn't be too hard to make a PR, and will do so over the next few days.