Robust safety encoder for accurate measurement