Line Sensors as Input

Following a Line

Now that we can sample the line sensors, let's think about how to write a program which will allow the robot to follow a line. If the line is centered, what should the robot do? We want it to drive straight. If the right sensor has moved over the line, what should the robot do? We want it to turn a little bit to the right. And finally, what if the left sensor has moved over the line? We want it to turn a little bit to the left. Which task it performs will be based on the input from the line sensors, and since we have more than two possible options, the if/else if/else format is going to be a good choice. Use the template program below, and your previous experience from the other tutorials, to write a code to make the robot follow a line!

Hint: Look at the comments in the template program. They will help you understand what you are writing the program to do, as well as other suggestions of similar types of code you have writing in previous tutorials.


import com.ridgesoft.intellibrain.IntelliBrain;

import com.ridgesoft.io.Display;

import com.ridgesoft.robotics.AnalogInput;

import com.ridgesoft.robotics.Motor;

import com.ridgesoft.robotics.ContinuousRotationServo;



public class ModuleFive_Display {

	public static void main(String[] args) {



AnalogInput leftOutter = new IntelliBrain.getAnalogInput(4);

	

    //create the motors



    //create the line sensors



	while(true){

		

                //create variables to store the values from sampling the line sensors



		

        	if ( //left sensor is over a line ) {

            	

                    //what do you want the motors to do? implement it!



        	} 



        	else if ( //right sensor is over a line) {

            	

                    //what do you want the motors to do? implement it!



        	}

 

        	else {  //which situation does this represent?

            	

                    //what do you want the motors to do? implement it!

        	}

		}

	}

}



More Following a Line


  1. What happens if you use the left outer and right outer sensors instead of the inner sensors? Try it!