本文整理汇总了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()