Distance measurement and automatic braking system