Adapting the speed of the robot based on the Ultrsonic Sensor's value

Hello everyone:

I am using a robot with Ultrasonic Sensor. Using the value of the sensor, the robot is coded to take action.
The action is:
Gradually increase the speed of the robot until the maximum speed (set to 60).

The problem faced:
Once the robot finds an obstacle, it stops. But, when the obstacle is removed, the robot moves with greater speed. How to avoid this?

How to avoid this?

Set the speed to a lower value before moving seems the obvious way

We will need more detail in order to provide more help