當前位置: 首頁>>代碼示例>>Python>>正文


Python Stopwatch.elapsed_time_in_secs方法代碼示例

本文整理匯總了Python中stopwatch.Stopwatch.elapsed_time_in_secs方法的典型用法代碼示例。如果您正苦於以下問題:Python Stopwatch.elapsed_time_in_secs方法的具體用法?Python Stopwatch.elapsed_time_in_secs怎麽用?Python Stopwatch.elapsed_time_in_secs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在stopwatch.Stopwatch的用法示例。


在下文中一共展示了Stopwatch.elapsed_time_in_secs方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: DriveTime

# 需要導入模塊: from stopwatch import Stopwatch [as 別名]
# 或者: from stopwatch.Stopwatch import elapsed_time_in_secs [as 別名]
class DriveTime(Command):
    '''
    classdocs
    '''
    _stopwatch = None
    _start_time = None
    _duration = None
    _speed = None
    _ramp_threshold = None

    def __init__(self, robot, duration, speed, ramp_threshold, name=None, timeout=None):
        '''
        Constructor
        '''
        super().__init__(name, timeout)
        self.robot = robot;
        self.requires(robot.drivetrain)
        self._stopwatch = Stopwatch()
        self._duration = duration
        self._speed = speed
        self._ramp_threshold = ramp_threshold

    def initialize(self):
        """Called before the Command is run for the first time."""
        # Start stopwatch
        self._stopwatch.start()
        return Command.initialize(self)

    def execute(self):
        """Called repeatedly when this Command is scheduled to run"""
        speed = self._speed
        time_left = self._duration - self._stopwatch.elapsed_time_in_secs()
        if (time_left < self._ramp_threshold):
            speed = speed * time_left / self._ramp_threshold
        self.robot.drivetrain.arcade_drive(speed, 0.0)
        return Command.execute(self)

    def isFinished(self):
        """Returns true when the Command no longer needs to be run"""
        # If elapsed time is more than duration
        return self._stopwatch.elapsed_time_in_secs() >= self._duration

    def end(self):
        """Called once after isFinished returns true"""
        self._stopwatch.stop()
        # Stop driving
        self.robot.drivetrain.arcade_drive(0.0, 0.0)

    def interrupted(self):
        """Called when another command which requires one or more of the same subsystems is scheduled to run"""
        self.end()
開發者ID:TechnoJays,項目名稱:robot2016,代碼行數:53,代碼來源:drive_time.py

示例2: RaisArmTime

# 需要導入模塊: from stopwatch import Stopwatch [as 別名]
# 或者: from stopwatch.Stopwatch import elapsed_time_in_secs [as 別名]
class RaisArmTime(Command):

    def __init__(self, robot, raise_speed, stop_time, name=None, timeout=None):
        '''
        Constructor
        '''
        super().__init__(name, timeout)
        self._robot = robot
        self._raise_speed = raise_speed
        self._stop_time = stop_time
        self.requires(robot.arm)
        self._stopwatch = Stopwatch()

    def initialize(self):
        """Called before the Command is run for the first time."""
        self._stopwatch.start()

    def execute(self):
        """Called repeatedly when this Command is scheduled to run"""
        self._robot.arm.move_arm(self._raise_speed)

    def isFinished(self):
        """Returns true when the Command no longer needs to be run"""
        return self._stopwatch.elapsed_time_in_secs() >= self._stop_time

    def end(self):
        """Called once after isFinished returns true"""
        self._robot.arm.move_arm(0)

    def interrupted(self):
        """Called when another command which requires one or more of the same subsystems is scheduled to run"""
        self.end()
開發者ID:TechnoJays,項目名稱:robot2016,代碼行數:34,代碼來源:raise_arm_time.py


注:本文中的stopwatch.Stopwatch.elapsed_time_in_secs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。