//import statements
import com.ridgesoft.intellibrain.IntelliBrain;
import com.ridgesoft.io.Display;
import com.ridgesoft.robotics.PushButton;
import com.ridgesoft.robotics.AnalogInput;
import com.ridgesoft.robotics.Motor;
import com.ridgesoft.robotics.ContinuousRotationServo;
import com.ridgesoft.robotics.SonarRangeFinder;
import com.ridgesoft.robotics.sensors.ParallaxPing;
main()
{
initialize display;
initialize lightSensor;
initialize Motor for left wheel;
initialize Motor for right wheel;
initialize SonarRangeFinder;
initialize PushButton;
while start button is not pressed loop
take sample from light sensor
print out value to display // this part is good for seeing how the sensor is working before movement
end while loop
Start infinite loop
ask sonar for distance
if distance greater than 0 and less than some small thresh
then stop motors
else
take light sample
// then do the following calculation to figure out the power you need for each wheel
float offset = (360.0 - (float)lightValue) * 0.016;
set right motors (8.0 + offset)
set left motors (8.0 - offset)
end of infinite loop
}//end of main
The calculation on the motor power should steer the robot around the line according
to a proportion of the light sample reading. Do the math.....
Considering the position of the two sensors relative to the line, at any point in time the robot will be in one of six states
shown in the table below:

The actions in the table define the actions your robot will need to take in order to follow the line.
For example when both sensors are over the line the robot will need to steer straight.
If the robot gets right of the line so the left sensor is on the line and the right is off you need ot steer slightly right
to get it back. Etc. etc.
Another way to represent these states is using a state diagram. EE, CS and CE majors will see lots of state
diagrams over the next several years. After you understand the notation it is fairly easy to comprehend.
Notice that the six states we have already discussed are each represented by a bubble in the diagram. The arrows represent the conditions that cause the state machine
to transition from one state to another. Specific conditions which cause each transition are listed next
to the arrow for that transition. In this case, the conditions are changes in the line sensor readings. For example the state
machine will transistion to the Centered state anytime both sensors are read high. Notice you can transtion to this state from
any of the other five states.
Now start a new project from scratch and use the followign pseudo code algorith to attempt to traverse the line
smoothly
More psuedo code:
Same import statements
main()
{
initialize all the elements like last time.
while(true)
{
sample sensors
evaluate conditions
look up new state
perform actions for new state
}
}
Part Three
Using both light Sensors and the ultraSound to stop if blocked.
Notice the following video uses the two sensors and ultraSound. The use of ultraSound makes the robot a little
more jumpy than when there is no UltraSound being used. It causes just enough delay to make you notice.
The code is the same as step two besides adding in the ultraSound from the first part above.
Grading
Make sure you team gets credit for doing as much of the lab as you can get done by the end of class.
Remember there is another lab class waiting to come in after you so when the time period is up please move on and let the new class on the computer.