Testing and optimizing linearity and absolute ranging in compact displacement sensors