Lesson 34: Virtualization Technology

Virtualization means putting a layer between the rest of your code and the physical hardware. Instead of every class knowing exact ports and sensor quirks, the robot code talks to named objects with clear behavior.

Virtual Inputs

A virtual input hides how the value is measured. For example, an arm position could come from a potentiometer, encoder, or simulated value. The rest of the arm code only asks for the current position.

public interface ArmPositionSensor {
    double getAngle();
}

Virtual Outputs

A virtual output hides how the robot performs an action. A claw might use a single solenoid one year and a motor the next. The rest of the code can still call open() and close().

public interface Claw {
    void open();
    void close();
}

Why This Is Useful

Virtualization makes testing easier, keeps hardware details isolated, and lets you change mechanisms without rewriting the whole project. It also helps students reason about what a subsystem does instead of where every wire goes.

Do Not Overdo It

Too many layers can make simple code hard to follow. Virtualize when it makes the code clearer or safer. If a wrapper only hides one obvious line, it may not be worth adding.

Practice

Choose a sensor on your robot and design a small interface for it. The interface should use units that make sense to the mechanism, such as inches, degrees, or pressed/not pressed.