state machine for ultrasonic measurement