pykit package¶
Subpackages¶
- pykit.inputs package
- pykit.networktables package
- Submodules
- pykit.networktables.loggeddashboardchooser module
LoggedDashboardChooserLoggedDashboardChooser.addOption()LoggedDashboardChooser.fromLog()LoggedDashboardChooser.getSelected()LoggedDashboardChooser.keyLoggedDashboardChooser.listenerLoggedDashboardChooser.onChange()LoggedDashboardChooser.optionsLoggedDashboardChooser.periodic()LoggedDashboardChooser.previousValueLoggedDashboardChooser.selectedValueLoggedDashboardChooser.sendableChooserLoggedDashboardChooser.setDefaultOption()LoggedDashboardChooser.toLog()
- pykit.networktables.loggednetworkboolean module
- pykit.networktables.loggednetworkinput module
- pykit.networktables.loggednetworknumber module
- pykit.networktables.loggednetworkstring module
- pykit.networktables.loggednetworkvalue module
- pykit.networktables.nt4Publisher module
- pykit.wpilog package
- Submodules
- pykit.wpilog.wpilogconstants module
- pykit.wpilog.wpilogreader module
- pykit.wpilog.wpilogwriter module
WPILOGWriterWPILOGWriter.autoRenameWPILOGWriter.defaultPathRioWPILOGWriter.defaultPathSimWPILOGWriter.dsAttachedTimeWPILOGWriter.end()WPILOGWriter.entryIdsWPILOGWriter.entryTypesWPILOGWriter.entryUnitsWPILOGWriter.filenameWPILOGWriter.folderWPILOGWriter.isOpenWPILOGWriter.lastTableWPILOGWriter.logWPILOGWriter.logDateWPILOGWriter.logMatchTextWPILOGWriter.putTable()WPILOGWriter.randomIdentifierWPILOGWriter.start()WPILOGWriter.timestampId
Submodules¶
pykit.autolog module¶
- class pykit.autolog.AutoLogInputManager[source]¶
Bases:
objectA manager class for handling automatic input loading of dataclass fields.
- classmethod getInputs() List[Any][source]¶
Returns the list of registered classes for input loading.
- Returns:
A list of registered classes.
- logged_classes: List[Any] = []¶
- class pykit.autolog.AutoLogOutputManager[source]¶
Bases:
objectA manager class for handling automatic logging of output members (fields/methods).
- logged_members: Dict[Type, List[Dict[str, Any]]] = {}¶
- classmethod publish(instance: Any, table: LogTable)[source]¶
Publishes the values of all registered members of an instance to a LogTable.
- Parameters:
instance – The instance whose members are to be published.
table – The LogTable to publish data to.
- classmethod publish_all(table: LogTable, root_instance=None)[source]¶
Publishes all registered members of all registered class instances.
This method scans for all instances of classes registered with autologgable_output and publishes their decorated members to the provided LogTable. It also handles caching of root instances to avoid redundant garbage collection scans.
- Parameters:
table – The LogTable to publish data to.
root_instance – An optional list of root instances to start publishing from. If None, it scans for all instances of registered classes.
- classmethod register_member(class_type: Type, member_name: str, is_method: bool, log_type: LoggableType | None, key: str = '', custom_type: str = '', unit: str | None = None)[source]¶
Registers a member (field or method) of a class for automatic output logging.
- Parameters:
class_type – The class to which the member belongs.
member_name – The name of the member (field or method).
is_method – True if the member is a method, False otherwise.
log_type – The LogValue.LoggableType to log the member as.
key – The key to use for logging. Defaults to the member name.
custom_type – A custom type string for the log entry.
unit – The unit string for the log entry.
- root_cache: List[Any] = []¶
- pykit.autolog.autolog(cls=None, /)[source]¶
A class decorator that adds ‘toLog’ and ‘fromLog’ methods to a dataclass for automatic logging.
The ‘toLog’ method serializes the dataclass fields to a LogTable. The ‘fromLog’ method deserializes the data from a LogTable into the dataclass fields.
This decorator is designed to be used with dataclasses and supports nested dataclasses decorated with @autolog.
- Parameters:
cls – The class to decorate.
- Returns:
The decorated class or a wrapper function.
- pykit.autolog.autolog_output(key: str, log_type: LoggableType | None = None, custom_type: str = '', unit: str | None = None)[source]¶
A decorator for methods or fields in a class to automatically log their output.
- Usage:
@autologgable_output class MyComponent:
my_value = 5
@autolog_output(“MyValue”) def get_my_value(self):
return self.my_value
- Parameters:
key – The key to use for logging the member’s value.
log_type – The LogValue.LoggableType to log the value as. If None, it’s inferred.
custom_type – A custom type string for the log entry.
unit – The unit string for the log entry.
- Returns:
A decorator function.
pykit.logdatareciever module¶
- class pykit.logdatareciever.LogDataReciever[source]¶
Bases:
objectAn abstract base class for classes that receive and process log data.
- putTable(table: LogTable)[source]¶
Processes a LogTable instance. This method is called for each log entry.
- Parameters:
table – The LogTable containing the log data for a specific timestamp.
- timestampKey: str = '/Timestamp'¶
pykit.loggedrobot module¶
- class pykit.loggedrobot.LoggedRobot[source]¶
Bases:
IterativeRobotBaseA robot base class that provides logging and replay functionality. This class extends IterativeRobotBase and integrates with the Logger to automatically handle the logging of robot data and periodic loops.
Constructor for the LoggedRobot. Initializes the robot, sets up the logger, and creates I/O objects.
- default_period = 0.02¶
pykit.logger module¶
- class pykit.logger.Logger[source]¶
Bases:
objectManages the logging and replay of data for the robot.
- classmethod addDataReciever(reciever: LogDataReciever)[source]¶
Adds a data receiver to the logger.
- Parameters:
reciever – The LogDataReciever to add.
- checkConsole: bool = True¶
- cycleCount: int = 0¶
- dashboardInputs: list[LoggedNetworkInput] = []¶
- dataRecievers: list[LogDataReciever] = []¶
- classmethod getTimestamp() int[source]¶
Returns the current timestamp for logging. In replay mode, it gets the timestamp from the log entry. In normal mode, it gets the current FPGA timestamp.
- Returns:
The current timestamp in microseconds.
- classmethod isReplay() bool[source]¶
Checks if the logger is currently in replay mode.
- Returns:
True if in replay mode, False otherwise.
- metadata: dict[str, str] = {}¶
- classmethod periodicAfterUser(userCodeLength: int, periodicBeforeLength: int)[source]¶
Called periodically after the user’s robot code. This method finalizes the log entry for the current cycle by recording outputs, performance data, and then sends the log table to all registered receivers.
- Parameters:
userCodeLength – The execution time of the user’s code in microseconds.
periodicBeforeLength – The execution time of the periodicBeforeUser method in microseconds.
- classmethod periodicBeforeUser()[source]¶
Called periodically before the user’s robot code. This method updates the log table with new data, either from the replay source or from the live robot hardware.
- classmethod processInputs(prefix: str, inputs)[source]¶
Processes an I/O object, either by logging its state or by updating it from the log.
In normal mode, it calls ‘toLog’ on the inputs object to record its state. In replay mode, it calls ‘fromLog’ on the inputs object to update its state from the log.
- Parameters:
prefix – The prefix for the log entries.
inputs – The I/O object to process.
- classmethod recordMetadata(key: str, value: str)[source]¶
Records metadata information. This is only active when not in replay mode.
- Parameters:
key – The key for the metadata.
value – The metadata value.
- classmethod recordOutput(key: str, value: Any, unit: str | None = None)[source]¶
Records an output value to the log table. This is only active when not in replay mode.
- Parameters:
key – The key under which to record the value.
value – The value to record.
- classmethod registerDashboardInput(dashboardInput: LoggedNetworkInput)[source]¶
Registers a dashboard input for periodic updates.
- Parameters:
dashboardInput – The LoggedNetworkInput to register.
- replaySource: LogReplaySource | None = None¶
- running: bool = False¶
- classmethod setReplaySource(replaySource: LogReplaySource)[source]¶
Sets the replay source for the logger.
- Parameters:
replaySource – The LogReplaySource to use for replaying data.
pykit.logreplaysource module¶
- class pykit.logreplaysource.LogReplaySource[source]¶
Bases:
objectAn abstract base class for providing log data for replay.
- end()[source]¶
Cleans up resources used by the replay source. This method can be overridden by subclasses for cleanup tasks.
- start()[source]¶
Initializes the replay source. This method should be implemented by subclasses to prepare for data replay.
- timestampKey: str = '/Timestamp'¶
pykit.logtable module¶
- class pykit.logtable.LogTable(timestamp: int, prefix='/')[source]¶
Bases:
objectRepresents a table of loggable values for a single timestamp. It stores data as key-value pairs where keys are strings and values are LogValue objects.
Initializes a new LogTable.
- Parameters:
timestamp – The timestamp for the log entries in this table, in microseconds.
prefix – The prefix for all keys in this table.
- addStructSchema(struct: Any, seen: Set[str])[source]¶
Adds the schema for a WPILib struct and its nested structs to the log table.
- Parameters:
struct – The struct instance.
seen – A set of already processed type strings to avoid recursion loops.
- addStructSchemaNest(structname: str, schema: str)[source]¶
Adds the schema for a nested WPILib struct to the log table.
- Parameters:
structname – The name of the struct.
schema – The schema string of the struct.
- static clone(source: LogTable)[source]¶
Creates a shallow copy of a LogTable.
- Parameters:
source – The LogTable to clone.
- Returns:
A new LogTable instance with the same data.
- depth: int¶
- get(key: str, defaultValue: Any) Any[source]¶
Gets a value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found.
- Returns:
The retrieved value or the default value.
- getAll(subtableOnly: bool = False) dict[str, LogValue][source]¶
Returns all log values in the table.
- Parameters:
subtableOnly – If True, returns only the entries within the current subtable’s prefix.
- Returns:
A dictionary of all log entries.
- getBoolean(key: str, defaultValue: bool) bool[source]¶
Gets a boolean value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getBooleanArray(key: str, defaultValue: list[bool]) list[bool][source]¶
Gets a boolean array value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getDouble(key: str, defaultValue: float) float[source]¶
Gets a double value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getDoubleArray(key: str, defaultValue: list[float]) list[float][source]¶
Gets a double array value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getFloat(key: str, defaultValue: float) float[source]¶
Gets a float value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getFloatArray(key: str, defaultValue: list[float]) list[float][source]¶
Gets a float array value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getInteger(key: str, defaultValue: int) int[source]¶
Gets an integer value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getIntegerArray(key: str, defaultValue: list[int]) list[int][source]¶
Gets an integer array value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getRaw(key: str, defaultValue: bytes) bytes[source]¶
Gets a raw (bytes) value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getString(key: str, defaultValue: str) str[source]¶
Gets a string value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getStringArray(key: str, defaultValue: list[str]) list[str][source]¶
Gets a string array value from the log table.
- Parameters:
key – The key of the value to retrieve.
defaultValue – The value to return if the key is not found or the type is incorrect.
- Returns:
The retrieved value or the default value.
- getSubTable(subtablePrefix: str) LogTable[source]¶
Returns a new LogTable instance representing a subtable of the current one. The new table shares the same underlying data but has an extended prefix.
- Parameters:
subtablePrefix – The prefix for the subtable.
- Returns:
A new LogTable for the specified subtable.
- getTimestamp() int[source]¶
Returns the timestamp of the log table.
- Returns:
The timestamp in microseconds.
- prefix: str¶
- put(key: str, value: Any, typeStr: str = '', unit: str | None = None)[source]¶
Puts a value into the log table, automatically handling WPILib structs and arrays. The value is wrapped in a LogValue object.
- Parameters:
key – The key for the log entry.
value – The value to be logged.
typeStr – An optional custom type string.
- putValue(key: str, log_value: LogValue)[source]¶
Puts a LogValue object into the log table.
- Parameters:
key – The key for the log entry.
log_value – The LogValue object to be stored.
- setTimestamp(timestamp: int) None[source]¶
Sets the timestamp of the log table.
- Parameters:
timestamp – The new timestamp in microseconds.
- writeAllowed(key: str, logType: LoggableType, customType: str) bool[source]¶
Checks if a write operation is allowed for a given key and type. Prevents changing the type of an existing log entry.
- Parameters:
key – The key of the log entry.
logType – The LoggableType of the new value.
customType – The custom type string of the new value.
- Returns:
True if writing is allowed, False otherwise.
pykit.logvalue module¶
- class pykit.logvalue.LogValue(value: Any, typeStr: str = '', unit: str | None = None)[source]¶
Bases:
objectRepresents a value in the log table, encapsulating its type, a custom type string, and the value itself.
Initializes a LogValue, inferring the loggable type from the value’s Python type.
- Parameters:
value – The value to be logged.
typeStr – An optional custom type string.
- Raises:
TypeError – If the value type is not supported.
- class LoggableType(*values)[source]¶
Bases:
EnumEnum for the different types of loggable values.
- Boolean = 2¶
- BooleanArray = 7¶
- Double = 5¶
- DoubleArray = 10¶
- Float = 4¶
- FloatArray = 9¶
- Integer = 3¶
- IntegerArray = 8¶
- Raw = 1¶
- String = 6¶
- StringArray = 11¶
- static fromNT4Type(typeStr: str) LoggableType[source]¶
Converts an NT4 type string to a LoggableType.
- Parameters:
typeStr – The NT4 type string.
- Returns:
The corresponding LoggableType, or Raw if not found.
- static fromWPILOGType(typeStr: str) LoggableType[source]¶
Converts a WPILOG type string to a LoggableType.
- Parameters:
typeStr – The WPILOG type string.
- Returns:
The corresponding LoggableType, or Raw if not found.
- custom_type: str¶
- getNT4Type() str[source]¶
Gets the NT4 type string for this value.
- Returns:
The custom type string if available, otherwise the default NT4 type.
- getWPILOGType() str[source]¶
Gets the WPILOG type string for this value.
- Returns:
The custom type string if available, otherwise the default WPILOG type.
- log_type: LoggableType¶
- unit: str | None = None¶
- value: Any¶
- static withType(log_type: LoggableType, data: Any, typeStr: str = '', unit: str | None = None) LogValue[source]¶
Creates a LogValue with a specified loggable type.
- Parameters:
log_type – The LoggableType to assign.
data – The value.
typeStr – An optional custom type string.
- Returns:
A new LogValue instance.