Examples

Use-Case

This example program demonstrates how to use the AndyMark Distance Sensor in an FTC OpMode. It initializes the sensor from the robot's hardware map and continuously measures distance while the OpMode is active. Using the onboard VL53L0X time-of-flight sensor, it reports highly accurate distance readings from approximately 30 mm up to 2000 mm, with a field of view of about 25°. The data is read over the I2C bus (default address 0x29) and updated in real time on the Driver Station screen, allowing teams to see exactly how far objects are from the sensor.

This example is particularly useful for testing sensor functionality, validating wiring and I2C communication, and experimenting with sensor placement on a robot. Because it outputs clear, live distance measurements, teams can use it to tune autonomous behaviors, detect obstacles, and refine mechanisms that rely on object detection. The program is designed so that even users without in-depth programming knowledge can run it as a diagnostic or learning tool.

Mounting Examples

Configuration

Code Example

public class AndyMarkTOFSensor extends LinearOpMode 
{
    private AndyMarkDistanceSensor sensor_distance;

    @Override
    public void runOpMode() 
    {
        sensor_distance = hardwareMap.get(DistanceSensor.class, "sensor_distance");

        waitForStart();

        while (opModeIsActive()) 
        {
            double distance = sensor_distance.getDistance(DistanceUnit.CM);
            telemetry.addData("Distance: ", distance);
            telemetry.update();
            
            sleep(100); // Small delay to avoid excessive telemetry updates
        }
    }
}

Last updated

Was this helpful?