Class Parsec
java.lang.Object
com.studica.frc.Parsec
- All Implemented Interfaces:
AutoCloseable
Studica Parsec multi-zone time-of-flight distance sensor, over CAN or USB.
Any number of Parsec objects can be open, one per device. Frames arrive in the background;
getScan() returns the newest one, or Optional.empty() when none has arrived
recently.
If the device can't be opened, the error is reported to the Driver Station and the object
stays inert: getters return empty and commands return Status.INVALID_HANDLE.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordParsec configuration, as reported by the device.static enumParsec zone grids.static final classOne distance frame. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the device.static ParsecfromSerialDevice(String devicePath) Opens a Parsec on an explicit serial device.Optional<org.wpilib.units.measure.Distance> Returns the nearest object in view: a shortcut forgetScan()thenParsec.Scan.getClosest().Reads the device configuration.getScan()Returns the newest frame.booleanReturns whether data arrived recently.booleanisOpen()Returns whether the device was opened.setOutputRate(int hz) Sets how often frames are sent.setRangingFrequency(int hz) Sets how often the sensor measures.setResolution(Parsec.Resolution resolution) Selects the zone grid.setZoneMask(long mask) Chooses which zones are measured: bit i enables zone i, counting row-major asParsec.Scan.getDistance(int)does.static Parsecusb()Opens the Parsec plugged into any USB port.static ParsecOpens the Parsec in a specific SystemCore USB port.
-
Constructor Details
-
Parsec
public Parsec(int canId) Opens a Parsec on CAN bus S0.- Parameters:
canId- CAN device ID set on the Parsec
-
Parsec
public Parsec(int canId, org.wpilib.hardware.bus.CANPort bus) Opens a Parsec on CAN.- Parameters:
canId- CAN device ID set on the Parsecbus- CAN port it is wired to
-
-
Method Details
-
usb
Opens the Parsec plugged into any USB port. It may be moved between USB ports while running. With more than one Parsec on USB, useusb(UsbPort)for each instead.- Returns:
- the Parsec
-
usb
-
fromSerialDevice
-
close
public void close()Closes the device. The object is inert afterwards.- Specified by:
closein interfaceAutoCloseable
-
isOpen
public boolean isOpen()Returns whether the device was opened.- Returns:
- false if the device could not be opened, or was closed
-
isConnected
public boolean isConnected()Returns whether data arrived recently.- Returns:
- true if connected
-
getScan
Returns the newest frame.- Returns:
- the frame, or empty if none arrived recently
-
getClosestDistance
Returns the nearest object in view: a shortcut forgetScan()thenParsec.Scan.getClosest().- Returns:
- the nearest distance, or empty if there's no recent frame or no valid reading
-
setOutputRate
Sets how often frames are sent.- Parameters:
hz- 1-60 Hz, no faster than the ranging frequency- Returns:
- the result
-
setResolution
Selects the zone grid. The sensor restarts at 15 Hz, so set the ranging frequency and output rate afterwards.- Parameters:
resolution- the grid- Returns:
- the result
-
setRangingFrequency
Sets how often the sensor measures.- Parameters:
hz- 1-60 Hz with 4x4 zones, 1-15 Hz with 8x8- Returns:
- the result
-
setZoneMask
Chooses which zones are measured: bit i enables zone i, counting row-major asParsec.Scan.getDistance(int)does. Other zones read empty.- Parameters:
mask- the zones to measure; at least one bit must be set- Returns:
- the result
-
getConfig
Reads the device configuration. Blocks up to 500 ms (USB) or 200 ms (CAN).- Returns:
- the configuration, or empty if the device didn't answer
-