From 39fb0511f15cc377423148a129dc8e05659b3155 Mon Sep 17 00:00:00 2001 From: divimaestas Date: Fri, 4 Dec 2026 12:32:59 -0700 Subject: [PATCH] MCLStage: a position near zero is not an error code checked_mcl_value rejected every negative value. Madlib overloads its return channel -- MCL_SingleReadN returns micrometers or one of the integer codes -1..-8 in HardwareReturn -- and the sign alone does not separate them: a Nano-Drive resting at its commanded zero reads a few nanometres below the sensor origin, which is a position. Now a negative value throws only when it is an integer code in HardwareReturn; non-finite values still throw. The sets cannot overlap: the stage travels 0 to 100 um, so a real position never reaches -1. Found on the TIRF rig: initialize(MCLStage) threw 'read axis 1 failed: invalid value (-0.005940918739356874)' with the stage parked at zero. Repeatability there measures about 2 nm at 50 um. --- .../mcl_stage/standard_device_movement.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hardware_implementations/mcl_stage/standard_device_movement.jl b/src/hardware_implementations/mcl_stage/standard_device_movement.jl index 08d81419..23ba0d38 100644 --- a/src/hardware_implementations/mcl_stage/standard_device_movement.jl +++ b/src/hardware_implementations/mcl_stage/standard_device_movement.jl @@ -14,9 +14,15 @@ _mcl_write_z(position::Float64, id::Int) = @ccall libmadlib.MCL_SingleWriteZ(position::Cdouble, id::Cint)::Cint function checked_mcl_value(value, operation) - if !isfinite(value) || value < 0 - code = isfinite(value) && isinteger(value) ? get(HardwareReturn, Int(value), "unknown error") : "invalid value" - error("MCLStage $operation failed: $code ($value)") + if !isfinite(value) + error("MCLStage $operation failed: invalid value ($value)") + end + # Madlib signals a failure with one of the integer codes in HardwareReturn + # (-1 to -8). A position is not one of those: a stage resting at its zero + # reads a few nanometres negative, because the capacitive sensor is noisy + # about the origin, and that is a position, not an error. + if value < 0 && isinteger(value) && haskey(HardwareReturn, Int(value)) + error("MCLStage $operation failed: $(HardwareReturn[Int(value)]) ($value)") end return value end