robotpy_ext.misc package
robotpy_ext.misc.asyncio_policy module
This is a replacement event loop and policy for asyncio that uses FPGA time, rather than native python time.
- class robotpy_ext.misc.asyncio_policy.FPGATimedEventLoop(selector=None)[source]
Bases:
_UnixSelectorEventLoop
An asyncio event loop that uses wpilib time rather than python time
robotpy_ext.misc.looptimer module
- class robotpy_ext.misc.looptimer.LoopTimer(logger)[source]
Bases:
object
A utility class that measures the number of loops that a robot program executes, and computes the min/max/average period for loops in the last second.
Example usage:
class Robot(wpilib.TimedRobot): def teleopInit(self): self.loop_timer = LoopTimer(self.logger) def teleopPeriodic(self): self.loop_timer.measure()
Mainly intended for debugging purposes to measure how much lag.
robotpy_ext.misc.precise_delay module
- class robotpy_ext.misc.precise_delay.NotifierDelay(delay_period)[source]
Bases:
object
Synchronizes a timing loop against interrupts from the FPGA.
This will delay so that the next invocation of your loop happens at precisely the same period, assuming that your loop does not take longer than the specified period.
Example:
with NotifierDelay(0.02) as delay: while something: # do things here delay.wait()
- Parameters:
delay_period (
float
) – The period’s amount of time (in seconds).
robotpy_ext.misc.periodic_filter module
- class robotpy_ext.misc.periodic_filter.PeriodicFilter(period, bypass_level=30)[source]
Bases:
object
Periodic Filter to help keep down clutter in the console. Simply add this filter to your logger and the logger will only print periodically.
The logger will always print logging levels of WARNING or higher, unless given a different bypass level
Example:
class Component1: def setup(self): # Set period to 3 seconds, set bypass_level to WARN self.logger.addFilter(PeriodicFilter(3, bypass_level=logging.WARN)) def execute(self): # This message will be printed once every three seconds self.logger.info('Component1 Executing') # This message will be printed out every loop self.logger.warn("Uh oh, this shouldn't have happened...")
- Parameters:
period – Wait period (in seconds) between logs
bypass_level – Lowest logging level that the filter should not catch
robotpy_ext.misc.simple_watchdog module
- class robotpy_ext.misc.simple_watchdog.SimpleWatchdog(timeout)[source]
Bases:
object
A class that’s a wrapper around a watchdog timer.
When the timer expires, a message is printed to the console and an optional user-provided callback is invoked.
The watchdog is initialized disabled, so the user needs to call enable() before use.
Note
This is a simpler replacement for the
wpilib.Watchdog
, and should function mostly the same (except that this watchdog will not detect infinite loops).Warning
This watchdog is not threadsafe
Watchdog constructor.
- Parameters:
timeout (
float
) – The watchdog’s timeout in seconds with microsecond resolution.
- addEpoch(epochName)[source]
Adds time since last epoch to the list printed by printEpochs().
Epochs are a way to partition the time elapsed so that when overruns occur, one can determine which parts of an operation consumed the most time.
- Parameters:
epochName (
str
) – The name to associate with the epoch.- Return type:
None
- kMinPrintPeriod = 1000000