From d175eac8db2085f459adc9a5638f465d5ee38217 Mon Sep 17 00:00:00 2001 From: Rene Hopf Date: Sat, 12 Sep 2026 21:47:42 +0200 Subject: [PATCH] change external offset to float --- .../dynamic_offsets_panel.hal | 5 +--- .../sim/axis/external_offsets/eoffsets.txt | 2 +- .../sim/axis/external_offsets/eoffsets_es.txt | 2 +- .../sim/axis/external_offsets/jwp_z_panel.hal | 2 +- .../qtdragon_hd_xyz/qtdragon_hd_postgui.hal | 13 +++++----- .../qtdragon_hd_postgui.hal | 13 +++++----- .../1280x1024_5axis/woodpecker_handler.py | 10 ++++---- docs/src/config/ini-config.adoc | 2 +- docs/src/gui/qtdragon.adoc | 13 +++++----- docs/src/man/man9/motion.9.adoc | 5 ++-- docs/src/motion/external-offsets.adoc | 6 +++-- .../screens/qtdragon/qtdragon_handler.py | 2 +- .../qtdragon_hd/qtdragon_hd_handler.py | 6 ++--- .../qtdragon_hd_vert_handler.py | 6 ++--- .../qtdragon_lathe/qtdragon_lathe_handler.py | 2 +- .../screens/qtplasmac/qtplasmac_handler.py | 2 +- src/emc/motion/axis.c | 22 +++++++++++----- src/hal/components/eoffset_per_angle.comp | 8 +++--- src/hal/components/plasmac.comp | 25 ++++++++++++++++--- src/hal/components/updown.comp | 2 ++ src/hal/user_comps/z_level_compensation.py | 6 ++--- 21 files changed, 94 insertions(+), 60 deletions(-) diff --git a/configs/sim/axis/external_offsets/dynamic_offsets_panel.hal b/configs/sim/axis/external_offsets/dynamic_offsets_panel.hal index d8fb312d375..286fa1a3837 100644 --- a/configs/sim/axis/external_offsets/dynamic_offsets_panel.hal +++ b/configs/sim/axis/external_offsets/dynamic_offsets_panel.hal @@ -1,12 +1,10 @@ loadrt siggen names=gen loadrt scale names=scalea -loadrt conv_real_sint names=cvt loadrt not names=nota loadrt or2 names=or2a addf gen.update servo-thread addf scalea servo-thread -addf cvt servo-thread addf nota servo-thread addf or2a servo-thread @@ -23,8 +21,7 @@ net E:frequency <= pyvcp.gen-frequency => gen.frequency # can also use sawtooth (others inappropriate on a reset) net G:waveform <= gen.sine => scalea.in -net G:swaveform <= scalea.out => cvt.in -net G:counts <= cvt.out => axis.z.eoffset-counts +net G:counts <= scalea.out => axis.z.eoffset-counts net E:enable <= pyvcp.z-enable => axis.z.eoffset-enable net E:enable => nota.in diff --git a/configs/sim/axis/external_offsets/eoffsets.txt b/configs/sim/axis/external_offsets/eoffsets.txt index d6accf6b2f9..e76c547c030 100644 --- a/configs/sim/axis/external_offsets/eoffsets.txt +++ b/configs/sim/axis/external_offsets/eoffsets.txt @@ -21,6 +21,6 @@ Input hal pins: axis.L.eoffset-enable (bool) axis.L.eoffset-clear (bool) axis.L.eoffset-scale (real) - axis.L.eoffset-counts (sint) + axis.L.eoffset-counts (real) Requested offset == counts*scale diff --git a/configs/sim/axis/external_offsets/eoffsets_es.txt b/configs/sim/axis/external_offsets/eoffsets_es.txt index 6c3b65abfdf..bdac90bae68 100644 --- a/configs/sim/axis/external_offsets/eoffsets_es.txt +++ b/configs/sim/axis/external_offsets/eoffsets_es.txt @@ -21,6 +21,6 @@ Pines Input hal: axis.L.eoffset-enable (bool) axis.L.eoffset-clear (bool) axis.L.eoffset-scale (real) - axis.L.eoffset-counts (sint) + axis.L.eoffset-counts (real) Offset solicitado == counts*scale diff --git a/configs/sim/axis/external_offsets/jwp_z_panel.hal b/configs/sim/axis/external_offsets/jwp_z_panel.hal index 848151cd8c4..1d5f4c072e9 100644 --- a/configs/sim/axis/external_offsets/jwp_z_panel.hal +++ b/configs/sim/axis/external_offsets/jwp_z_panel.hal @@ -3,7 +3,7 @@ addf zctr servo-thread net E:z-plus <= pyvcp.z-plus => zctr.countup net E:z-minus <= pyvcp.z-minus => zctr.countdown -net E:z-counts <= zctr.count => axis.z.eoffset-counts +net E:z-counts <= zctr.count-f => axis.z.eoffset-counts net E:z-scale <= pyvcp.z-scale => axis.z.eoffset-scale net E:z-offset <= axis.z.eoffset => pyvcp.z-offset-f net E:limited <= motion.eoffset-limited => pyvcp.limited diff --git a/configs/sim/qtdragon_hd/qtdragon_hd_xyz/qtdragon_hd_postgui.hal b/configs/sim/qtdragon_hd/qtdragon_hd_xyz/qtdragon_hd_postgui.hal index c60549ebf48..3892ee7a8ca 100644 --- a/configs/sim/qtdragon_hd/qtdragon_hd_xyz/qtdragon_hd_postgui.hal +++ b/configs/sim/qtdragon_hd/qtdragon_hd_xyz/qtdragon_hd_postgui.hal @@ -5,8 +5,9 @@ loadrt logic names=logic-and personality=0x102 addf logic-and servo-thread # load a summing component for adding spindle lift and Z compensation -loadrt scaled_sint_sums -addf scaled-sint-sums.0 servo-thread +# (eoffset counts are floats, so sum2 rather than scaled_sint_sums) +loadrt sum2 +addf sum2.0 servo-thread loadusr -Wn z_level_compensation z_level_compensation # method parameter must be one of nearest(2), linear(1), cubic (0) @@ -51,8 +52,8 @@ net zpos-cmd z_level_compensation.z-pos <= axis.z.pos-cmd net z_compensation_on z_level_compensation.enable-in <= qtdragon.comp-on net eoffset-zlevel-count z_level_compensation.counts => qtdragon.eoffset-zlevel-count -net eoffset-spindle-count scaled-sint-sums.0.in0 -net eoffset-zlevel-count scaled-sint-sums.0.in1 -setp scaled-sint-sums.0.scale0 1000 -net eoffset-counts scaled-sint-sums.0.out-s +net eoffset-spindle-count sum2.0.in0 +net eoffset-zlevel-count sum2.0.in1 +setp sum2.0.gain0 1000 +net eoffset-counts sum2.0.out diff --git a/configs/sim/qtdragon_hd/qtdragon_hd_z_compensation/qtdragon_hd_postgui.hal b/configs/sim/qtdragon_hd/qtdragon_hd_z_compensation/qtdragon_hd_postgui.hal index c08b1b1c2a7..c1f1e88c032 100644 --- a/configs/sim/qtdragon_hd/qtdragon_hd_z_compensation/qtdragon_hd_postgui.hal +++ b/configs/sim/qtdragon_hd/qtdragon_hd_z_compensation/qtdragon_hd_postgui.hal @@ -5,8 +5,9 @@ loadrt logic names=logic-and personality=0x102 addf logic-and servo-thread # load a summing component for adding spindle lift and Z compensation -loadrt scaled_sint_sums -addf scaled-sint-sums.0 servo-thread +# (eoffset counts are floats, so sum2 rather than scaled_sint_sums) +loadrt sum2 +addf sum2.0 servo-thread loadusr -Wn z_level_compensation z_level_compensation # method parameter must be one of nearest(2), linear(1), cubic (0) @@ -51,8 +52,8 @@ net zpos-cmd z_level_compensation.z-pos <= axis.z.pos-cmd net z_compensation_on z_level_compensation.enable-in <= qtdragon.comp-on net eoffset-zlevel-count z_level_compensation.counts => qtdragon.eoffset-zlevel-count -net eoffset-spindle-count scaled-sint-sums.0.in0 -net eoffset-zlevel-count scaled-sint-sums.0.in1 -setp scaled-sint-sums.0.scale0 1000 -net eoffset-counts scaled-sint-sums.0.out-s +net eoffset-spindle-count sum2.0.in0 +net eoffset-zlevel-count sum2.0.in1 +setp sum2.0.gain0 1000 +net eoffset-counts sum2.0.out diff --git a/configs/sim/woodpecker/1280x1024_5axis/woodpecker_handler.py b/configs/sim/woodpecker/1280x1024_5axis/woodpecker_handler.py index d725c8c6791..e4b8725b051 100644 --- a/configs/sim/woodpecker/1280x1024_5axis/woodpecker_handler.py +++ b/configs/sim/woodpecker/1280x1024_5axis/woodpecker_handler.py @@ -283,15 +283,15 @@ def init_pins(self): # external offset control pins QHAL.newpin("eoffset-enable", QHAL.HAL_BOOL, QHAL.HAL_OUT) QHAL.newpin("eoffset-clear", QHAL.HAL_BOOL, QHAL.HAL_OUT) - QHAL.newpin("eoffset-spindle-count", QHAL.HAL_SINT, QHAL.HAL_OUT) - QHAL.newpin("eoffset-count", QHAL.HAL_SINT, QHAL.HAL_OUT) + QHAL.newpin("eoffset-spindle-count", QHAL.HAL_REAL, QHAL.HAL_OUT) + QHAL.newpin("eoffset-count", QHAL.HAL_REAL, QHAL.HAL_OUT) - pin = QHAL.newpin("eoffset-value", QHAL.HAL_SINT, QHAL.HAL_IN) + pin = QHAL.newpin("eoffset-value", QHAL.HAL_REAL, QHAL.HAL_IN) pin.value_changed.connect(self.eoffset_changed) - pin = QHAL.newpin("eoffset-zlevel-count", QHAL.HAL_SINT, QHAL.HAL_IN) + pin = QHAL.newpin("eoffset-zlevel-count", QHAL.HAL_REAL, QHAL.HAL_IN) pin.value_changed.connect(self.comp_count_changed) - pin = QHAL.newpin("comp-count", QHAL.HAL_SINT, QHAL.HAL_IN) + pin = QHAL.newpin("comp-count", QHAL.HAL_REAL, QHAL.HAL_IN) pin.value_changed.connect(self.compensate_count_changed) pin = QHAL.newpin("map-ready", QHAL.HAL_BOOL, QHAL.HAL_IN) pin.value_changed.connect(self.map_ready_changed) diff --git a/docs/src/config/ini-config.adoc b/docs/src/config/ini-config.adoc index a99a87e94f8..bb601a10d73 100644 --- a/docs/src/config/ini-config.adoc +++ b/docs/src/config/ini-config.adoc @@ -1085,7 +1085,7 @@ Example: `loadrt motmod ... unlock_joints_mask=0x38` creates unlock-pins for joi [source,hal] ---- axis..eoffset-enable -axis..eoffset-count +axis..eoffset-counts axis..eoffset-scale ---- diff --git a/docs/src/gui/qtdragon.adoc b/docs/src/gui/qtdragon.adoc index 2fb6a5591db..871297c59d2 100644 --- a/docs/src/gui/qtdragon.adoc +++ b/docs/src/gui/qtdragon.adoc @@ -838,8 +838,9 @@ loadrt logic names=logic-and personality=0x102 addf logic-and servo-thread # load a summing component for adding spindle lift and Z compensation -loadrt scaled_sint_sums -addf scaled-sint-sums.0 servo-thread +# (eoffset counts are floats, so sum2 rather than scaled_sint_sums) +loadrt sum2 +addf sum2.0 servo-thread loadusr -Wn z_level_compensation z_level_compensation # method parameter must be one of nearest(2), linear(1), cubic (0) @@ -872,10 +873,10 @@ net z_compensation_on z_level_compensation.enable-in <= qtdragon.comp-on net eoffset-zlevel-count z_level_compensation.counts => qtdragon.eoffset-zlevel-count # add Z level and scaled spindle raise level values together -net eoffset-spindle-count scaled-sint-sums.0.in0 -net eoffset-zlevel-count scaled-sint-sums.0.in1 -setp scaled-sint-sums.0.scale0 1000 -net eoffset-counts scaled-sint-sums.0.out-s +net eoffset-spindle-count sum2.0.in0 +net eoffset-zlevel-count sum2.0.in1 +setp sum2.0.gain0 1000 +net eoffset-counts sum2.0.out ---- diff --git a/docs/src/man/man9/motion.9.adoc b/docs/src/man/man9/motion.9.adoc index 176e32450f2..03b0c4e5054 100644 --- a/docs/src/man/man9/motion.9.adoc +++ b/docs/src/man/man9/motion.9.adoc @@ -328,13 +328,14 @@ These pins represent the *commanded geometric intent* from the interpreter and a Current external offset. **axis.**_L_**.eoffset-clear** IN BOOL:: Clear external offset request -**axis.**_L_**.eoffset-counts** IN SINT:: +**axis.**_L_**.eoffset-counts** IN REAL:: Counts input for external offset. The eoffset-counts are transferred to an internal register. The applied external offset is the product of the register counts and the eoffset-scale value. The register is *reset to zero at each machine startup*. If the machine is turned off with an external offset active, the eoffset-counts pin should be set - to zero before restarting. + to zero before restarting. Non-finite values (NaN, infinity) are + ignored. **axis.**_L_**.eoffset-enable** IN BOOL:: Enable for external offset (also requires INI file setting for [AXIS_L]OFFSET_AV_RATIO) **axis.**_L_**.eoffset-request** OUT REAL:: diff --git a/docs/src/motion/external-offsets.adoc b/docs/src/motion/external-offsets.adoc index f81b24f6796..d844c8f784b 100644 --- a/docs/src/motion/external-offsets.adoc +++ b/docs/src/motion/external-offsets.adoc @@ -48,7 +48,7 @@ For each axis letter (*_L_* in xyzabcuvw) . *axis._L_.eoffset-enable* Input(bool): enable . *axis._L_.eoffset-scale* Input(real): scale factor -. *axis._L_.eoffset-counts* Input(sint): input to counts register +. *axis._L_.eoffset-counts* Input(real): input to counts register . *axis._L_.eoffset-clear* Input(bool): clear requested offset . *axis._L_.eoffset* Output(real): current external offset . *axis._L_.eoffset-request* Output(real): requested external offset @@ -68,7 +68,9 @@ pins used for wheel jogging. At each servo period, the 'axis._L_.eoffset-counts' pin is compared to its value in the prior period. The increase or decrease (positive or negative delta) of the 'axis._L_.eoffset-counts' pin is multiplied -by the current 'axis._L_.eoffset-scale' pin value. This product is +by the current 'axis._L_.eoffset-scale' pin value. The pin is a float, +so the counts need not be whole numbers; a non-finite value (NaN or +infinity) is ignored and leaves the register unchanged. This product is accumulated in an internal register and exported to the 'axis._L_.eoffset-request' HAL pin. The accumulation register is reset to zero at each machine-on. diff --git a/share/qtvcp/screens/qtdragon/qtdragon_handler.py b/share/qtvcp/screens/qtdragon/qtdragon_handler.py index 26beace8a29..6c1f0b46750 100644 --- a/share/qtvcp/screens/qtdragon/qtdragon_handler.py +++ b/share/qtvcp/screens/qtdragon/qtdragon_handler.py @@ -365,7 +365,7 @@ def init_pins(self): QHAL.newPin("eoffset-enable", QHAL.HAL_BOOL, QHAL.HAL_OUT) QHAL.newPin("eoffset-clear", QHAL.HAL_BOOL, QHAL.HAL_OUT) self.h['eoffset-clear'] = True - QHAL.newPin("eoffset-spindle-count", QHAL.HAL_SINT, QHAL.HAL_OUT) + QHAL.newPin("eoffset-spindle-count", QHAL.HAL_REAL, QHAL.HAL_OUT) pin = QHAL.newPin("eoffset-is-active", QHAL.HAL_BOOL, QHAL.HAL_IN) pin.pinValueChanged.connect(lambda p,v: self.external_offset_state_changed(v)) diff --git a/share/qtvcp/screens/qtdragon_hd/qtdragon_hd_handler.py b/share/qtvcp/screens/qtdragon_hd/qtdragon_hd_handler.py index c50902fb054..3d01285d95e 100644 --- a/share/qtvcp/screens/qtdragon_hd/qtdragon_hd_handler.py +++ b/share/qtvcp/screens/qtdragon_hd/qtdragon_hd_handler.py @@ -294,8 +294,8 @@ def init_pins(self): QHAL.newPin("eoffset-enable", QHAL.HAL_BOOL, QHAL.HAL_OUT) QHAL.newPin("eoffset-clear", QHAL.HAL_BOOL, QHAL.HAL_OUT) self.h['eoffset-clear'] = False - QHAL.newPin("eoffset-spindle-count", QHAL.HAL_SINT, QHAL.HAL_OUT) - QHAL.newPin("eoffset-count", QHAL.HAL_SINT, QHAL.HAL_OUT) + QHAL.newPin("eoffset-spindle-count", QHAL.HAL_REAL, QHAL.HAL_OUT) + QHAL.newPin("eoffset-count", QHAL.HAL_REAL, QHAL.HAL_OUT) pin = QHAL.newPin("eoffset-is-active", QHAL.HAL_BOOL, QHAL.HAL_IN) @@ -303,7 +303,7 @@ def init_pins(self): pin = QHAL.newPin("eoffset-value", QHAL.HAL_REAL, QHAL.HAL_IN) pin.pinValueChanged.connect(lambda p,v: self.external_offset_state_changed(v)) - pin = QHAL.newPin("eoffset-zlevel-count", QHAL.HAL_SINT, QHAL.HAL_IN) + pin = QHAL.newPin("eoffset-zlevel-count", QHAL.HAL_REAL, QHAL.HAL_IN) pin.pinValueChanged.connect(lambda p,v: self.comp_count_changed(v)) QHAL.newPin("comp-on", QHAL.HAL_BOOL, QHAL.HAL_OUT) QHAL.newPin("spindle-lift-on", QHAL.HAL_BOOL, QHAL.HAL_OUT) diff --git a/share/qtvcp/screens/qtdragon_hd_vert/qtdragon_hd_vert_handler.py b/share/qtvcp/screens/qtdragon_hd_vert/qtdragon_hd_vert_handler.py index 6f15fa53791..11e57a27c0b 100644 --- a/share/qtvcp/screens/qtdragon_hd_vert/qtdragon_hd_vert_handler.py +++ b/share/qtvcp/screens/qtdragon_hd_vert/qtdragon_hd_vert_handler.py @@ -294,8 +294,8 @@ def init_pins(self): QHAL.newPin("eoffset-enable", QHAL.HAL_BOOL, QHAL.HAL_OUT) QHAL.newPin("eoffset-clear", QHAL.HAL_BOOL, QHAL.HAL_OUT) self.h['eoffset-clear'] = False - QHAL.newPin("eoffset-spindle-count", QHAL.HAL_SINT, QHAL.HAL_OUT) - QHAL.newPin("eoffset-count", QHAL.HAL_SINT, QHAL.HAL_OUT) + QHAL.newPin("eoffset-spindle-count", QHAL.HAL_REAL, QHAL.HAL_OUT) + QHAL.newPin("eoffset-count", QHAL.HAL_REAL, QHAL.HAL_OUT) pin = QHAL.newPin("eoffset-is-active", QHAL.HAL_BOOL, QHAL.HAL_IN) @@ -303,7 +303,7 @@ def init_pins(self): pin = QHAL.newPin("eoffset-value", QHAL.HAL_REAL, QHAL.HAL_IN) pin.pinValueChanged.connect(lambda p,v: self.external_offset_state_changed(v)) - pin = QHAL.newPin("eoffset-zlevel-count", QHAL.HAL_SINT, QHAL.HAL_IN) + pin = QHAL.newPin("eoffset-zlevel-count", QHAL.HAL_REAL, QHAL.HAL_IN) pin.pinValueChanged.connect(lambda p,v: self.comp_count_changed(v)) QHAL.newPin("comp-on", QHAL.HAL_BOOL, QHAL.HAL_OUT) QHAL.newPin("spindle-lift-on", QHAL.HAL_BOOL, QHAL.HAL_OUT) diff --git a/share/qtvcp/screens/qtdragon_lathe/qtdragon_lathe_handler.py b/share/qtvcp/screens/qtdragon_lathe/qtdragon_lathe_handler.py index 2941b6ca88f..4d9022ba407 100644 --- a/share/qtvcp/screens/qtdragon_lathe/qtdragon_lathe_handler.py +++ b/share/qtvcp/screens/qtdragon_lathe/qtdragon_lathe_handler.py @@ -355,7 +355,7 @@ def init_pins(self): QHAL.newPin("eoffset-enable", QHAL.HAL_BOOL, QHAL.HAL_OUT) QHAL.newPin("eoffset-clear", QHAL.HAL_BOOL, QHAL.HAL_OUT) self.h['eoffset-clear'] = True - QHAL.newPin("eoffset-spindle-count", QHAL.HAL_SINT, QHAL.HAL_OUT) + QHAL.newPin("eoffset-spindle-count", QHAL.HAL_REAL, QHAL.HAL_OUT) pin = QHAL.newPin("eoffset-is-active", QHAL.HAL_BOOL, QHAL.HAL_IN) pin.pinValueChanged.connect(lambda p,v: self.external_offset_state_changed(v)) diff --git a/share/qtvcp/screens/qtplasmac/qtplasmac_handler.py b/share/qtvcp/screens/qtplasmac/qtplasmac_handler.py index b51922fe427..63fc93785c6 100644 --- a/share/qtvcp/screens/qtplasmac/qtplasmac_handler.py +++ b/share/qtvcp/screens/qtplasmac/qtplasmac_handler.py @@ -928,7 +928,7 @@ def make_hal_pins(self): self.xOffsetPin = self.h.newpin('x_offset', hal.Type.REAL, hal.Dir.IN) self.yOffsetPin = self.h.newpin('y_offset', hal.Type.REAL, hal.Dir.IN) self.zHeightPin = self.h.newpin('z_height', hal.Type.REAL, hal.Dir.IN) - self.zOffsetPin = self.h.newpin('z_offset_counts', hal.Type.SINT, hal.Dir.IN) + self.zOffsetPin = self.h.newpin('z_offset_counts', hal.Type.REAL, hal.Dir.IN) self.xMinPierceExtentPin = self.h.newpin('x_min_pierce_extent', hal.Type.REAL, hal.Dir.IN) self.xMaxPierceExtentPin = self.h.newpin('x_max_pierce_extent', hal.Type.REAL, hal.Dir.IN) self.yMinPierceExtentPin = self.h.newpin('y_min_pierce_extent', hal.Type.REAL, hal.Dir.IN) diff --git a/src/emc/motion/axis.c b/src/emc/motion/axis.c index 4cc55035c0e..0f58db2548b 100644 --- a/src/emc/motion/axis.c +++ b/src/emc/motion/axis.c @@ -23,7 +23,7 @@ typedef struct { double ext_offset_vel_limit; /* upper limit of axis speed for ext offset */ double ext_offset_acc_limit; /* upper limit of axis accel for ext offset */ - rtapi_sint old_eoffset_counts; + double old_eoffset_counts; simple_tp_t ext_offset_tp; /* planner for external coordinate offsets*/ } emcmot_axis_t; @@ -44,7 +44,7 @@ typedef struct { hal_bool_t eoffset_enable; hal_bool_t eoffset_clear; - hal_sint_t eoffset_counts; + hal_real_t eoffset_counts; hal_real_t eoffset_scale; hal_real_t external_offset; hal_real_t external_offset_requested; @@ -135,7 +135,7 @@ int axis_init_hal_io(int mot_comp_id) CALL_CHECK(hal_pin_new_bool(mot_comp_id, HAL_OUT, &axis_data->teleop_tp_enable, 0, "axis.%c.teleop-tp-enable",c)); CALL_CHECK(hal_pin_new_bool(mot_comp_id, HAL_IN, &axis_data->eoffset_enable, 0, "axis.%c.eoffset-enable", c)); CALL_CHECK(hal_pin_new_bool(mot_comp_id, HAL_IN, &axis_data->eoffset_clear, 0, "axis.%c.eoffset-clear", c)); - CALL_CHECK(hal_pin_new_sint(mot_comp_id, HAL_IN, &axis_data->eoffset_counts, 0, "axis.%c.eoffset-counts", c)); + CALL_CHECK(hal_pin_new_real(mot_comp_id, HAL_IN, &axis_data->eoffset_counts, 0.0, "axis.%c.eoffset-counts", c)); CALL_CHECK(hal_pin_new_real(mot_comp_id, HAL_IN, &axis_data->eoffset_scale, 0.0, "axis.%c.eoffset-scale", c)); CALL_CHECK(hal_pin_new_real(mot_comp_id, HAL_OUT, &axis_data->external_offset, 0.0, "axis.%c.eoffset", c)); CALL_CHECK(hal_pin_new_real(mot_comp_id, HAL_OUT, &axis_data->external_offset_requested, @@ -486,7 +486,7 @@ bool axis_plan_external_offsets(double servo_period, bool motion_enable_flag, bo int n; emcmot_axis_t *axis; axis_hal_t *axis_data; - rtapi_sint new_eoffset_counts, delta; + double new_eoffset_counts, delta, increment; static int last_eoffset_enable[EMCMOT_MAX_AXIS]; double ext_offset_epsilon; bool eoffset_active = 0; @@ -499,7 +499,14 @@ bool axis_plan_external_offsets(double servo_period, bool motion_enable_flag, bo axis_data = &hal_data->axis[n]; - new_eoffset_counts = hal_get_sint(axis_data->eoffset_counts); + new_eoffset_counts = hal_get_real(axis_data->eoffset_counts); + /* eoffset-counts is a float pin, so a HAL writer can hand us a + non-finite value. Latching it would make every subsequent delta + NaN as well, so keep the previous value and let delta come out + zero instead. */ + if (!isfinite(new_eoffset_counts)) { + new_eoffset_counts = axis->old_eoffset_counts; + } delta = new_eoffset_counts - axis->old_eoffset_counts; axis->old_eoffset_counts = new_eoffset_counts; @@ -548,7 +555,10 @@ bool axis_plan_external_offsets(double servo_period, bool motion_enable_flag, bo if (!all_homed) { continue; } if (!motion_enable_flag) { continue; } - axis->ext_offset_tp.pos_cmd += delta * hal_get_real(axis_data->eoffset_scale); + increment = delta * hal_get_real(axis_data->eoffset_scale); + if (!isfinite(increment)) { continue; } + + axis->ext_offset_tp.pos_cmd += increment; hal_set_real(axis_data->external_offset_requested, axis->ext_offset_tp.pos_cmd); } // for n first_pass = 0; diff --git a/src/hal/components/eoffset_per_angle.comp b/src/hal/components/eoffset_per_angle.comp index 85b302955e0..16988d8604d 100644 --- a/src/hal/components/eoffset_per_angle.comp +++ b/src/hal/components/eoffset_per_angle.comp @@ -6,9 +6,9 @@ description An offset is computed (from one of several functions) based on an input angle in degrees. The angle could be a rotary coordinate value or a spindle angle. -The computed offset is represented as an integer *kcounts* output pin that is a +The computed offset is represented as a float *kcounts* output pin that is a compatible input to external offset pins like *axis.L.eoffset-counts* where *L* -is the coordinate letter. Scaling of the integer *kcounts* is controlled by the +is the coordinate letter. Scaling of the *kcounts* value is controlled by the input (*k*) -- its reciprocal value is presented on an output pin *kreciprocal* for connection to *axis.L.eoffset-scale*. The default value for *k* should be suitable for most uses. @@ -77,7 +77,7 @@ pin out bool is_off "invert is_on (for convenience)"; pin out bool enable_out "To: axis.L.eoffset-enable"; pin out bool clear "To: axis.L.eoffset-clear"; -pin out sint kcounts "To: axis.L.eoffset-counts"; +pin out real kcounts "To: axis.L.eoffset-counts"; pin out real kreciprocal "To: axis.L.eoffset-scale (1/k)"; pin out real eoffset_dbg "offset (debug pin--use kcounts & kreciprocal)"; @@ -137,7 +137,7 @@ static ofunc func0,func1,func2,func3; #define LVL RTAPI_MSG_INFO #define dprint(msg,n) do { \ rtapi_set_msg_level(LVL); \ - rtapi_print_msg(LVL,"%20s %5d\n",msg,n); \ + rtapi_print_msg(LVL,"%20s %9.3f\n",msg,(double)(n)); \ } while (0) #else #define dprint(msg,n) diff --git a/src/hal/components/plasmac.comp b/src/hal/components/plasmac.comp index bd09760d2ce..cca3f99b0b8 100644 --- a/src/hal/components/plasmac.comp +++ b/src/hal/components/plasmac.comp @@ -213,11 +213,11 @@ pin out bool thc_enabled "thc is enabled"; pin out bool torch_on "turn torch on, connect to your torch on input"; pin out real torch_time "torch on time of current job"; pin out bool voidlock_is_locked "voidlock is locked indicator [mode 0 & mode 1]"; -pin out sint x_offset_counts "x offset for consumable change, connect to axis.x.eoffset-counts"; +pin out real x_offset_counts "x offset for consumable change, connect to axis.x.eoffset-counts"; pin out bool xy_offset_enable "enable x and y offsets, connect to axis..eoffset-enable"; -pin out sint y_offset_counts "y offset for consumable change, connect to axis.y.eoffset-counts"; +pin out real y_offset_counts "y offset for consumable change, connect to axis.y.eoffset-counts"; pin out real z_height "current z axis height relative to the probed zero height"; -pin out sint z_offset_counts "z offset for height control, connect to axis.z.eoffset-counts"; +pin out real z_offset_counts "z offset for height control, connect to axis.z.eoffset-counts"; pin out bool z_offset_enable "enable z offsets, connect to axis.z.eoffset-enable"; pin out real z_relative "distance of Z from last probed height"; @@ -322,10 +322,13 @@ variable double voidlock_change; /* voltage change this cycle */ variable rtapi_sint voidlock_off_count; /* current count of voidlock deactivate cycles */ variable rtapi_sint voidlock_on_count; /* current count of voidlock activate cycles */ variable double voidlock_threshold; /* voidlock threshold voltage per cycle */ +variable rtapi_sint x_offset_int; /* integer x offset counts, published on x_offset_counts */ variable rtapi_sint x_velocity; /* velocity for x motion for consumable change */ +variable rtapi_sint y_offset_int; /* integer y offset counts, published on y_offset_counts */ variable rtapi_sint y_velocity; /* velocity for y motion for consumable change */ variable rtapi_sint z_max; /* max height for testing against pierce height*/ variable rtapi_sint z_pierce; /* pierce height for testing against max height*/ +variable rtapi_sint z_offset_int; /* integer z offset counts, published on z_offset_counts */ variable rtapi_sint zero_target; /* zero height target offset */ // Pierce type user control variables variable double creep_speed_dist_travelled; /* Sum of distance traveled during creep stage */ @@ -358,6 +361,22 @@ option singleton yes; #include +/* the offset calculations are done in integer counts, while the + axis.L.eoffset-counts pins they drive are real. keep the integer value + in a variable for all reads and copy it to the real pin on every write */ +#undef x_offset_counts +#define x_offset_counts x_offset_int +#undef x_offset_counts_set +#define x_offset_counts_set(v) (x_offset_int = (v), hal_set_real(x_offset_counts_ptr, x_offset_int)) +#undef y_offset_counts +#define y_offset_counts y_offset_int +#undef y_offset_counts_set +#define y_offset_counts_set(v) (y_offset_int = (v), hal_set_real(y_offset_counts_ptr, y_offset_int)) +#undef z_offset_counts +#define z_offset_counts z_offset_int +#undef z_offset_counts_set +#define z_offset_counts_set(v) (z_offset_int = (v), hal_set_real(z_offset_counts_ptr, z_offset_int)) + typedef enum{IDLE, PROBE_HEIGHT, PROBE_DOWN, diff --git a/src/hal/components/updown.comp b/src/hal/components/updown.comp index 9d6a1633648..7d61a6830ff 100644 --- a/src/hal/components/updown.comp +++ b/src/hal/components/updown.comp @@ -3,6 +3,7 @@ pin in bool countup "Increment count when this pin goes from 0 to 1"; pin in bool countdown "Decrement count when this pin goes from 0 to 1"; pin in bool reset "Reset count when this pin goes from 0 to 1"; pin out sint count "The current count"; +pin out real count_f "The current count, as a float"; param rw bool clamp_ "If TRUE, then clamp the output to the min and max parameters."; param rw bool wrap "If TRUE, then wrap around when the count goes above or below the min and max parameters. Note that wrap implies (and overrides) clamp."; param rw sint max_ = 0x7FFFFFFF "If clamp or wrap is set, count will never exceed this number"; @@ -45,6 +46,7 @@ FUNCTION(_) { temp_count = min_; } count_set(temp_count); + count_f_set((double)temp_count); oldup = countup; olddown = countdown; } diff --git a/src/hal/user_comps/z_level_compensation.py b/src/hal/user_comps/z_level_compensation.py index 07c1c94bd96..4363c2fd21b 100644 --- a/src/hal/user_comps/z_level_compensation.py +++ b/src/hal/user_comps/z_level_compensation.py @@ -99,11 +99,11 @@ def compensate(self): self.Xn = self.xpos - self.xMin self.Yn = self.ypos - self.yMin - # get the nearest compensation offset and convert to counts (s32) with a scale (float) + # get the nearest compensation offset and convert to counts (float) with a scale (float) # Requested offset == counts * scale zo = self.zi[self.Xn, self.Yn] try: - compensation = int(zo / self.scale) + compensation = float(zo / self.scale) except: compensation = 0.0 return compensation @@ -112,7 +112,7 @@ def run(self): self.h = hal.component("z_level_compensation") self.h.newpin("enable-in", hal.Type.BOOL, hal.Dir.IN) self.h.newpin("scale", hal.Type.REAL, hal.Dir.OUT) - self.h.newpin("counts", hal.Type.SINT, hal.Dir.OUT) + self.h.newpin("counts", hal.Type.REAL, hal.Dir.OUT) self.h.newpin("clear", hal.Type.BOOL, hal.Dir.IN) self.h.newpin("x-pos", hal.Type.REAL, hal.Dir.IN) self.h.newpin("y-pos", hal.Type.REAL, hal.Dir.IN)