Class HootReplay
- All Implemented Interfaces:
AutoCloseable
This replays all signals in the given hoot log in simulation. Hoot logs can
be created by a robot program using SignalLogger. Only one hoot log
may be replayed at a time.
The signal logger always runs while replay is running. All custom signals written
during replay will be automatically placed under hoot_replay/. Additionally,
the log will contain all status signals and custom signals from the original log.
During replay, all transmits from the robot program are ignored. This includes features such as control requests, configs, and setting signal update frequency. Additionally, Tuner X is not functional during log replay.
To use Hoot Replay, construct a HootReplay(String) before any devices are constructed
to load a hoot file and start replay. It is recommended that this is constructed immediately
before a CANBus to fulfill this requirement. Non-critical failures from opening and
reading the file can be fetched using getStatus().
After devices are constructed, Hoot Replay can be controlled using play(),
pause(), stop(), and restart(). Additionally, Hoot Replay
supports stepTiming(double) while paused. The current file can be closed using
close(), after which a new file may be loaded.
-
Constructor Summary
ConstructorsConstructorDescriptionHootReplay(String filepath) Loads the given file and starts signal log replay. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Ends the hoot log replay.getBoolean(String name) Gets a boolean user signal.static StatusSignal.SignalMeasurement<boolean[]> getBooleanArray(String name) Gets a boolean user signal.static StatusSignal.SignalMeasurement<Double> Gets a double user signal.static StatusSignal.SignalMeasurement<double[]> getDoubleArray(String name) Gets a double array user signal.static StatusSignal.SignalMeasurement<Float> Gets a float user signal.static StatusSignal.SignalMeasurement<float[]> getFloatArray(String name) Gets a float array user signal.static StatusSignal.SignalMeasurement<Long> getInteger(String name) Gets an integer user signal.static StatusSignal.SignalMeasurement<long[]> getIntegerArray(String name) Gets a boolean array user signal.static <T> StatusSignal.SignalMeasurement<Optional<T>> getProtobuf(String name, Protobuf<T, ?> proto) Gets a Protobuf user signal.static StatusSignal.SignalMeasurement<byte[]> Gets a raw-bytes user signal.static StatusSignal.SignalMeasurement<byte[]> getSchemaValue(String name, HootSchemaType type) Gets a schema-serialized user signal.final StatusCodeGets the status from opening and reading the file for replay.static StatusSignal.SignalMeasurement<String> Gets a string user signal.static StatusSignal.SignalMeasurement<String[]> getStringArray(String name) Gets a string array user signal.static <T> StatusSignal.SignalMeasurement<Optional<T>> Gets a WPILib Struct user signal.static <T> StatusSignal.SignalMeasurement<Optional<T[]>> getStructArray(String name, Struct<T> struct) Gets a WPILib Struct array user signal.static <MEAS extends Measure<?>>
StatusSignal.SignalMeasurement<MEAS> getValue(String name, DoubleFunction<MEAS> unitFactory) Gets a unit value user signal.static booleanGets whether a valid hoot log file is currently loaded.static booleanGets whether hoot log replay has reached the end of the log.static booleanGets whether hoot log replay is actively playing.static StatusCodepause()Pauses the hoot log replay.static StatusCodeplay()Starts or resumes the hoot log replay.static StatusCoderestart()Restarts the hoot log replay from the start of the log.static voidsetSpeed(double speed) Sets the speed of the hoot log replay.static StatusCodestepTiming(double stepTimeSeconds) Advances the hoot log replay time by the given value.static StatusCodestop()Stops the hoot log replay.static booleanwaitForPlaying(double timeoutSeconds) Waits until hoot log replay is actively playing.
-
Constructor Details
-
HootReplay
Loads the given file and starts signal log replay. Only one hoot log may be replayed at a time.This must be constructed before constructing any devices or checking CAN bus status. It is recommended that this is constructed immediately before a
CANBusto fulfill this requirement.When using relative paths, the file path is typically relative to the top-level folder of the robot project.
This API is blocking on the file read.
- Parameters:
filepath- Path and name of the hoot file to load- Throws:
IllegalArgumentException- The file is invalid, unlicensed, or targets a different version of Phoenix 6
-
-
Method Details
-
close
public void close()Ends the hoot log replay. This stops the replay if it is running, closes the hoot log, and clears all signals read from the file.- Specified by:
closein interfaceAutoCloseable
-
getStatus
Gets the status from opening and reading the file for replay.- Returns:
- Status from opening and reading the file for replay
-
isFileLoaded
public static boolean isFileLoaded()Gets whether a valid hoot log file is currently loaded.- Returns:
- true if a valid hoot log file is loaded
-
play
Starts or resumes the hoot log replay.- Returns:
- Status of starting or resuming replay
-
pause
Pauses the hoot log replay. This maintains the current position in the log replay so it can be resumed later.- Returns:
- Status of pausing replay
-
stop
Stops the hoot log replay. This resets the current position in the log replay to the start.- Returns:
- Status of stopping replay
-
restart
-
isPlaying
public static boolean isPlaying()Gets whether hoot log replay is actively playing.This API will return true in programs that do not support replay, making it safe to call without first checking if the program supports replay.
- Returns:
- true if replay is playing back signals
-
waitForPlaying
public static boolean waitForPlaying(double timeoutSeconds) Waits until hoot log replay is actively playing.This API will immediately return true in programs that do not support replay, making it safe to call without first checking if the program supports replay.
Since this can block the calling thread, this should not be called with a non-zero timeout on the main thread.
This can also be used with a timeout of 0 to perform a non-blocking check, which is equivalent to
isPlaying().- Parameters:
timeoutSeconds- Max time to wait for replay to start playing- Returns:
- true if replay is playing back signals
-
isFinished
public static boolean isFinished()Gets whether hoot log replay has reached the end of the log.- Returns:
- true if replay has reached the end of the log, or if no log is currently loaded
-
setSpeed
public static void setSpeed(double speed) Sets the speed of the hoot log replay. A speed of 1.0 corresponds to replaying the file in real time, and larger values increase the speed.- Minimum Value: 0.01
- Maximum Value: 100.0
- Default Value: 1.0
- Parameters:
speed- Speed of the hoot log replay
-
stepTiming
Advances the hoot log replay time by the given value. Replay must be paused or stopped before advancing its time.- Parameters:
stepTimeSeconds- The amount of time to advance- Returns:
- Status of advancing the replay time
-
getSchemaValue
public static StatusSignal.SignalMeasurement<byte[]> getSchemaValue(String name, HootSchemaType type) Gets a schema-serialized user signal. Users can callgetStruct(String, Struct),getStructArray(String, Struct), andgetProtobuf(String, Protobuf)to directly get schema values instead.- Parameters:
name- Name of the signaltype- Type of the schema, such as struct or protobuf- Returns:
- Structure with all information about the signal
-
getStruct
public static <T> StatusSignal.SignalMeasurement<Optional<T>> getStruct(String name, Struct<T> struct) Gets a WPILib Struct user signal.- Type Parameters:
T- Struct type- Parameters:
name- Name of the signalstruct- Struct deserialization implementation- Returns:
- Structure with all information about the signal
-
getStructArray
public static <T> StatusSignal.SignalMeasurement<Optional<T[]>> getStructArray(String name, Struct<T> struct) Gets a WPILib Struct array user signal.- Type Parameters:
T- Struct type- Parameters:
name- Name of the signalstruct- Struct deserialization implementation- Returns:
- Structure with all information about the signal
-
getProtobuf
public static <T> StatusSignal.SignalMeasurement<Optional<T>> getProtobuf(String name, Protobuf<T, ?> proto) Gets a Protobuf user signal.- Type Parameters:
T- Protobuf type- Parameters:
name- Name of the signalproto- Protobuf deserialization implementation- Returns:
- Structure with all information about the signal
-
getRaw
Gets a raw-bytes user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getBoolean
Gets a boolean user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getInteger
Gets an integer user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getFloat
Gets a float user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getDouble
Gets a double user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getValue
public static <MEAS extends Measure<?>> StatusSignal.SignalMeasurement<MEAS> getValue(String name, DoubleFunction<MEAS> unitFactory) Gets a unit value user signal.- Type Parameters:
MEAS- Unit measure type- Parameters:
name- Name of the signalunitFactory- Factory for creating the unit type, such asRotations::of- Returns:
- Structure with all information about the signal
-
getString
Gets a string user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getBooleanArray
Gets a boolean user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getIntegerArray
Gets a boolean array user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getFloatArray
Gets a float array user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getDoubleArray
Gets a double array user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-
getStringArray
Gets a string array user signal.- Parameters:
name- Name of the signal- Returns:
- Structure with all information about the signal
-