In a programming language of your choice, implement the bottom level of the robot controller hierarchy.

Here is one possible solution:

input variables: sensor, last_sensor, last_steer, goal
output variables: sensor, last_sensor, last_steer, steer

robot

Code:
steer = last_steer;
if (goal == true && sensor < last_sensor) {
	steer = !steer;
}
if (goal == false && sensor > last_sensor) {
	steer = !steer;
}
last_steer = steer;
last_sensor = sensor;

Valid HTML 4.0 Transitional