Using an ultrasonic sensor to control motor to move in the forward and reverse direction

OK. That is not hard but realize if you move forward and distance remains <=10 then the robot will be stuck. Also vice versa if you move in reverse and distance remains >10 then robot will be stuck.