ultrasonic, initialise?

I started using an ultrasonic sensor to detect the height of loads of cones in front of it by moving up and down.

However, the sensor isn’t working every time, I mean, work after a few tries.

I have to start with something hanging 6cm in front of the sonar. After I remove it by user-control, the value of sensor was like locked at 6, and it doesn’t change no matter what.
I have to cover the input and output by finger, giving a -1 value, then remove and it will work as normal.
But this move is certainly not allowed in competition during pre-auton.

Is there some kind of solution by initialising or restarting?

What language? It sounds like a programming issue.

Vex cortex, but doesn’t look like it’s programming issue

“Vex cortex” is not a language. Are you using RobotC, PROS, etc.?

oh, sorry.
robotc 2.0, the codes were just


sensorvalue[in1]

There is an initialization call to the ultrasonic ranger that should be performed outside your control loop.