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