def getFPGATime(): """Read the microsecond timer from the FPGA. :returns: The current time in microseconds according to the FPGA. :rtype: int """ return hal.getFPGATime()
def printEpochs(self) -> None: """Prints list of epochs added so far and their times.""" now = hal.getFPGATime() if now - self._lastEpochsPrintTime > self.kMinPrintPeriod: self._lastEpochsPrintTime = now for key, value in self._epochs.items(): logger.info("\t%s: %.6fs", key, value / 1e6)
def getFPGATimestamp() -> float: """Return the system clock time in seconds. Return the time from the FPGA hardware clock in seconds since the FPGA started. :returns: Robot running time in seconds. """ return hal.getFPGATime() / 1000000.0
def setTimeout(self, timeout: float) -> None: """Sets the watchdog's timeout. :param timeout: The watchdog's timeout in seconds with microsecond resolution. """ self._startTime = hal.getFPGATime() self._epochs.clear() timeout = int(timeout * 1e6) # us with self._queueMutex: self._timeout = timeout self._isExpired = False watchdogs = self._watchdogs try: watchdogs.remove(self) except ValueError: pass else: heapq.heapify(watchdogs) self._expirationTime = self._startTime + timeout heapq.heappush(watchdogs, self) self._schedulerWaiter.notify_all()
def printEpochs(self) -> None: """Prints list of epochs added so far and their times.""" now = hal.getFPGATime() if now - self._lastEpochsPrintTime > self.kMinPrintPeriod: self._lastEpochsPrintTime = now log = logger.info for key, value in self._epochs.items(): log("\t%s: %.6fs", key, value / 1e6)
def getFPGATime() -> int: """Read the microsecond timer from the FPGA. .. deprecated:: 2018.0.0 Use :meth:`.RobotController.getFPGATime` instead :returns: The current time in microseconds according to the FPGA. """ return hal.getFPGATime()
def _updateControlWord(self, force): """Updates the data in the control word cache. Updates if the force parameter is set, or if 50ms have passed since the last update. :param force: True to force an update to the cache, otherwise update if 50ms have passed. """ now = hal.getFPGATime() with self.controlWordMutex: if now - self.lastControlWordUpdate > 50 or force: hal.getControlWord(self.controlWordCache) self.lastControlWordUpdate = now
def addEpoch(self, epochName: str) -> None: """ 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. :param epochName: The name to associate with the epoch. """ currentTime = hal.getFPGATime() self._epochs[epochName] = currentTime - self._startTime self._startTime = currentTime
def enable(self) -> None: """Enables the watchdog timer.""" self._startTime = hal.getFPGATime() self._epochs.clear() with self._queueMutex: self._isExpired = False watchdogs = self._watchdogs try: watchdogs.remove(self) except ValueError: pass else: heapq.heapify(watchdogs) self._expirationTime = self._startTime + self._timeout heapq.heappush(watchdogs, self) self._schedulerWaiter.notify_all()
def getMsClock(self): """ :returns: the system clock time in milliseconds. :rtype: int """ return hal.getFPGATime() / 1000
def getMsClock(self) -> int: """ :returns: the system clock time in milliseconds. """ return hal.getFPGATime() / 1000
def getTime(self) -> float: """Returns the time in seconds since the watchdog was last fed.""" return (hal.getFPGATime() - self._startTime) / 1e6