Lesson 9: More about sensor input

Because sensor input is so important to robot functionality, I really want to make sure that you completely understand it. In this lesson we will review topics already discussed in th previous two lessons, and I will also introduce some more advanced input topics.

I really brushed over the AnalogInput class in the last lesson. The main thing we use analog inputs for is potentiometers, but sometimes we need to use them for other things. In tese cases we use the AnalogInput class because we don't want the functionality of a potentiometer. Just as usual, the Analog class has a get() method that will return the voltage of the analog input. This functions the same way that a AnalogPotentiometer object would if you didn't set it up with any calibration values (you used the single integer constructor).

So why do we need this class? Code Red has used it for creating an 11th digital input port. A lot of times we will use an encoder on each of our four wheels, an encoder on some manipulator mechanism, and boom! We have used up all the digital inputs on the roboRIO since each encoder takes up two. If we wanted to add a limit switch, we need to come up with some sort of expansion plan. You can purchase (or make, although this is much more difficult) a breakout board that connects to the expansion port on the roboRIO, or if you only need one or two more digital inputs you can use an analog port and convert the signal to digital. This actually requires a small piece of hardware called a pull up. A pull up converts the digital signal from a limit switch into analog, and then we need to covert that analog signal back to digital in our code.

TODO Insert pictures of a pull up, how they work and how to make one.

The Code Red Robot Library provides a VirtualizablePsuedoDigitalInput class that represents a digital input plugged into an analog port. It can be used just like a DigitalInput would, for example:

VirtualizablePsuedoDigitalInput input;

public void robotInit() {
    input = new VirtualizablePsuedoDigitalInput(0);
}

public void teleopPeriodic() {
    if (input.get()) {
        // do an action
    }
}

We have only started to scratch the surface of all the different kinds of sensors you can have. Here are some more common types of sensor input:

We are not going to learn about Ultrasonic sensors and accelerometers. I would like to mention, however, that there is an accelerometer inside the roboRIO, so if you want to use an accelerometer you may want to consider using that internal sensor as it is already present on your robot. If you want to know more about those two classes in the WPI Java Library, please refer to their respective javadoc: