本文整理匯總了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()
示例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()