Tech Toolbox
  • Please Visit https://ftc-tech-toolbox.vercel.app/ for the new tech toolbox!!
    • Introduction
    • Choosing an IDE
    • Creating an OpMode
    • Motors and Encoders
    • Servos
    • Gamepad Controls
    • Drive Systems
    • Lynx Modules
    • Telemetry
    • Wireless Download
    • The Sleep Command
  • Please Visit the New Link
    • Tank Drive / Skid Steer (Part 1)
    • Mecanum Drive (Part 1)
    • Turrets
    • Linear Slides
    • Kicker
    • Active Intake / Sweepers
    • Flywheels / Shooters
  • Please Visit the new Link
    • Base Class (Step 1)
    • Module Classes (Step 2)
    • OpMode Classes (Step 3)
  • This domain is now depreciated and is no longer updated!
  • This domain is now depreciated and is no longer updated!
    • What is Localization?
    • General Odometry Logic
    • Tank (No Deadwheels)
    • Mecanum (No Deadwheels)
    • Deadwheel Odometry (Mecanum and Tank)
    • VSLAM
  • This domain is now depreciated and is no longer updated!
    • What is Control Theory?
    • Custom PID Loops
    • Essential Control Theory Concepts
    • Resources for Learning Advanced Control Theory
  • This domain is now depreciated and is no longer updated! Please visit this domain for the new TT!
    • Introduction
    • Mecanum Drive (Part 2)
    • Tank Drive (Part 2)
    • Introduction to Pure Pursuit
    • Pure Pursuit: Mecanum
    • Pure Pursuit: Tank
    • Advanced Pure Pursuit
    • Guided Vector Fields
    • Autonomous Movement Libraries
  • Sensors
    • IMU
    • Color Sensors
      • Advanced Sensing Code
    • Distance Sensors
    • Touch Sensor
  • Computer Vision
    • Setting up Camera/Intro to Computer Vision Tools
      • Intro to OpenCV
      • Vuforia
    • Streaming Frames
    • Color Thresholding
    • April Tags
    • Linear Regression
    • Machine Learning Toolchain
    • Object Distance Estimation
    • Object Tracking / Driving to an Object
    • Computer Vision Simulators
  • Simulators
    • Beta8397 Simulator
    • VRS
  • Cool Codebases
Powered by GitBook
On this page
  • Implementation
  • Using the Sensor Values
  1. Sensors

Distance Sensors

Determining Distance to Objects

The REV 2M distance sensor is the best bet for teams looking to make use of a distance sensor in their code. This time-of-flight sensor is very useful for determining the robots distance from objects, up to 2 meters.

Implementation

Initialize the Sensor

DistanceSensor distance_sensor;
distance_sensor = hardwareMap.get(DistanceSensor.class, "distance");

Finding the distance returned by the sensor

distance_sensor.getDistance(DistanceUnit.INCH);
//Units can be MM, CM, INCH, or METER

Using the Sensor Values

You can use the sensor to do an action if it is below a certain distance threshold to an object.

distance = distance_sensor.getDistance(DistanceUnit.INCH);
if(distance < 10){
    //Certain Action
}

You can also use the sensor to do something if it is more than a certain distance away from an object.

distance = distance_sensor.getDistance(DistanceUnit.INCH);
if(distance > 10){
    //Certain Action
}
PreviousAdvanced Sensing CodeNextTouch Sensor

Last updated 1 year ago