Class FakeDistanceSensor
java.lang.Object
org.horizon36596.simloop.fakehardware.AbstractFakeDevice
org.horizon36596.simloop.fakehardware.FakeDistanceSensor
- All Implemented Interfaces:
com.qualcomm.robotcore.hardware.DistanceSensor,com.qualcomm.robotcore.hardware.HardwareDevice,FakeDevice
public class FakeDistanceSensor
extends AbstractFakeDevice
implements com.qualcomm.robotcore.hardware.DistanceSensor
Fake What the robot reads, read out of the SDK 12.0
DistanceSensor modelled on the REV 2m Distance Sensor (a VL53L0X time-of-flight chip).
Unchanged robot code resolves it with hardwareMap.get(DistanceSensor.class, name) and reads
getDistance(DistanceUnit) exactly as it does on the real robot.
Two ways to drive it
- Scripted:
setDistance(DistanceUnit, double)andsetNothingInRange()take effect at once. - From a source:
setDistanceSource(DistanceUnit, DoubleSupplier)hands the fake something to ask once perupdate(double), such as aorg.horizon36596.simloop.sensor.RangeFindercasting a ray from the sensor's mount to the field walls and game pieces. Asking on the tick, not on every read, keeps the getter a pure read.
What the robot reads, read out of the SDK 12.0 VL53L0X bytecode
- Whole millimetres. The chip reports an integer number of millimetres; the driver divides it
by 10 for
CM, 1000 forMETERand 25.4 forINCH, and returns it unchanged forMM. This fake rounds the true distance to the nearest millimetre and divides the same way, so a reading is the same double a robot would print. - Nothing in range is a large number, not the SDK's sentinel. The REV 2m driver never returns
DistanceSensor.distanceOutOfRange: it passes on whatever the chip reports, and with no target in range that is the chip's own "no target" value (REV_2M_NO_TARGET_MM), which reads as roughly 819 cm or 322 in. Robot code that tests== distanceOutOfRangenever sees a match on a real REV 2m, and in this sim it does not either. A sensor whose driver does return the sentinel is built withnew FakeDistanceSensor(maxRangeMm, DistanceSensor.distanceOutOfRange); the sentinel is then returned as it is in every unit, never divided, so the comparison works. - Metadata: device name
"REV 2M ToF Distance Sensor"and manufacturerOther, as the driver reports.
Not modelled: noise, the sensor's field of view (a ray caster decides what it sees), the
target's reflectivity, the chip's timing budget and the driver's timeout (which reads 65535 mm). The
SDK's concrete Rev2mDistanceSensor class is not faked, so hardwareMap.get(
Rev2mDistanceSensor.class, name) does not resolve; robot code that asks for the DistanceSensor
interface, as the SDK's own sample does, works.
Deterministic: no clock, no randomness. A fresh sensor sees nothing in range.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.HardwareDevice
com.qualcomm.robotcore.hardware.HardwareDevice.Manufacturer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe farthest target a REV 2m sees, millimetres.static final doubleWhat a REV 2m reports with nothing in range, millimetres.Fields inherited from interface com.qualcomm.robotcore.hardware.DistanceSensor
distanceOutOfRange -
Constructor Summary
ConstructorsConstructorDescriptionA REV 2m Distance Sensor:REV_2M_MAX_RANGE_MMrange,REV_2M_NO_TARGET_MMwhen nothing is in range.FakeDistanceSensor(double maxRangeMm, double outOfRangeReadingMm) A range sensor with its own range and its own "nothing in range" reading. -
Method Summary
Modifier and TypeMethodDescriptionReturns"REV 2M ToF Distance Sensor", the stringRev2mDistanceSensor.getDeviceNamereturns.doublegetDistance(org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit unit) The distance the sensor reports: the true distance rounded to whole millimetres, or the out-of-range reading when nothing is within range, converted the way the SDK's VL53L0X driver converts it (see the class javadoc).doubleReturns the farthest target the sensor reports, millimetres.doubleReturns what the sensor reports with nothing in range, millimetres, or the SDK's sentinel.intReturns1, as the SDK's I2C device drivers report.booleanReturns true when the current target is within the sensor's range, so a reading is a real distance.voidsetDistance(org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit unit, double distance) Put a targetdistanceaway from the sensor's face, from now on.voidsetDistanceSource(org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit unit, DoubleSupplier source) Asksourcehow far the target is on everyupdate(double)from now on.voidTake every target away from now on, so the sensor reports out of range.voidupdate(double deltaTime) Samples the source set withsetDistanceSource(DistanceUnit, DoubleSupplier), if there is one.Methods inherited from class org.horizon36596.simloop.fakehardware.AbstractFakeDevice
close, getConnectionInfo, getManufacturer, resetDeviceConfigurationForOpModeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.qualcomm.robotcore.hardware.HardwareDevice
close, getConnectionInfo, getManufacturer, resetDeviceConfigurationForOpMode
-
Field Details
-
REV_2M_MAX_RANGE_MM
public static final double REV_2M_MAX_RANGE_MMThe farthest target a REV 2m sees, millimetres. SPEC: REV's product name and datasheet range, 2 m, in the driver's default long-range mode. A real sensor's range falls short of this on a dark or angled target; that is not modelled.- See Also:
-
REV_2M_NO_TARGET_MM
public static final double REV_2M_NO_TARGET_MMWhat a REV 2m reports with nothing in range, millimetres. NEEDS MEASUREMENT (2026-09-28): 8190 mm is the VL53L0X "no target" reading FTC teams widely report from this sensor (819 cm, 322.4 in); it has not been read off this team's sensor. The SDK driver passes the chip's number straight through, so whatever the chip sends is what robot code sees.- See Also:
-
-
Constructor Details
-
FakeDistanceSensor
public FakeDistanceSensor()A REV 2m Distance Sensor:REV_2M_MAX_RANGE_MMrange,REV_2M_NO_TARGET_MMwhen nothing is in range. -
FakeDistanceSensor
public FakeDistanceSensor(double maxRangeMm, double outOfRangeReadingMm) A range sensor with its own range and its own "nothing in range" reading.- Parameters:
maxRangeMm- the farthest target the sensor reports, millimetres (> 0); anything farther reads asoutOfRangeReadingMmoutOfRangeReadingMm- what the sensor reports with nothing in range, millimetres, orDistanceSensor.distanceOutOfRangefor a driver that returns the SDK's sentinel (returned unconverted in every unit)- Throws:
IllegalArgumentException- ifmaxRangeMmis not positive and finite, oroutOfRangeReadingMmis NaN or negative
-
-
Method Details
-
setNothingInRange
public void setNothingInRange()Take every target away from now on, so the sensor reports out of range. Clears any source. -
update
public void update(double deltaTime) Samples the source set withsetDistanceSource(DistanceUnit, DoubleSupplier), if there is one. A range sensor has no dynamics of its own.- Specified by:
updatein interfaceFakeDevice- Parameters:
deltaTime- how far to advance, in seconds; unused- Throws:
IllegalArgumentException- if the source answers NaN or a negative distance
-
isTargetInRange
public boolean isTargetInRange()Returns true when the current target is within the sensor's range, so a reading is a real distance.- Returns:
- true when the current target is within the sensor's range, so a reading is a real distance
-
getMaxRangeMm
public double getMaxRangeMm()Returns the farthest target the sensor reports, millimetres.- Returns:
- the farthest target the sensor reports, millimetres
-
getOutOfRangeReadingMm
public double getOutOfRangeReadingMm()Returns what the sensor reports with nothing in range, millimetres, or the SDK's sentinel.- Returns:
- what the sensor reports with nothing in range, millimetres, or the SDK's sentinel
-
getDeviceName
Returns"REV 2M ToF Distance Sensor", the stringRev2mDistanceSensor.getDeviceNamereturns.- Specified by:
getDeviceNamein interfacecom.qualcomm.robotcore.hardware.HardwareDevice- Overrides:
getDeviceNamein classAbstractFakeDevice- Returns:
"REV 2M ToF Distance Sensor", the stringRev2mDistanceSensor.getDeviceNamereturns
-
getVersion
public int getVersion()Returns1, as the SDK's I2C device drivers report.- Specified by:
getVersionin interfacecom.qualcomm.robotcore.hardware.HardwareDevice- Overrides:
getVersionin classAbstractFakeDevice- Returns:
1, as the SDK's I2C device drivers report