当前位置: 首页>>代码示例>>Python>>正文


Python Fysom.started方法代码示例

本文整理汇总了Python中fysom.Fysom.started方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.started方法的具体用法?Python Fysom.started怎么用?Python Fysom.started使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fysom.Fysom的用法示例。


在下文中一共展示了Fysom.started方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FidoTail

# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import started [as 别名]
class FidoTail(FSMClient):
    def __init__(self, inputs, outputs):
        self.inputs = inputs
        self.outputs = outputs
        self.fsm = Fysom({'initial': 'Idle',
                          'events': [
                              {'name': 'start_wagging', 'src': ['Idle', 'Stopping'], 'dst': 'StartingWagging'},
                              {'name': 'started', 'src': 'StartingWagging', 'dst': 'WaggingRight'},
                              {'name': 'timeout', 'src': 'WaggingLeft', 'dst': 'WaggingRight'},
                              {'name': 'timeout', 'src': 'WaggingRight', 'dst': 'WaggingLeft'},
                              {'name': 'stop_wagging', 'src': ['WaggingLeft', 'WaggingRight'], 'dst': 'Stopping'},
                              {'name': 'stop_wagging', 'src': 'Idle', 'dst': 'Idle'},
                              {'name': 'stopped', 'src': 'Stopping', 'dst': 'Idle'}],
                          'callbacks': {
                              'onenterStartingWagging': self._enterStartingWagging,
                              'onenterWaggingRight': self._enterWaggingRight,
                              'doWaggingRight': self._doWaggingRight,
                              'onenterWaggingLeft': self._enterWaggingLeft,
                              'doWaggingLeft': self._doWaggingLeft,
                              'onenterStopping': self._enterStopping}})

    #
    # fsm action methods (private)
    #
    def _enterStartingWagging(self, event):
        self.delay = event.delay
        self.count = event.count
        self.fsm.started()
        
    def _enterWaggingRight(self, event):
        #servo_if.set_servo_reliably(servo_if.TAIL, servo_if.TAIL_RIGHT)
        self.outputs['tail'] = servo_if.TAIL_RIGHT
        self.timeout_time = time.time() + self.delay

    def _doWaggingRight(self):
        if time.time() >= self.timeout_time:
            self.fsm.timeout()

    def _enterWaggingLeft(self, event):
        #servo_if.set_servo_reliably(servo_if.TAIL, servo_if.TAIL_LEFT)
        self.outputs['tail'] = servo_if.TAIL_LEFT
        self.timeout_time = time.time() + self.delay

    def _doWaggingLeft(self):
        if time.time() >= self.timeout_time:
            self.count -= 1
            if self.count > 0:
                self.fsm.timeout()
            else:
                self.fsm.stop_wagging()
            
    def _enterStopping(self, event):
        #servo_if.set_servo(servo_if.TAIL, servo_if.TAIL_CENTER)
        self.outputs['tail'] = servo_if.TAIL_CENTER
        self.fsm.stopped()

    #
    # public interface methods
    #
    def start_wagging(self, delay=0.25, count=5):
        self.fsm.start_wagging(delay=delay, count=count)

    def stop_wagging(self):
        self.fsm.stop_wagging()

    def is_wagging(self):
        return self.fsm.current != 'Idle'
开发者ID:nomad2012,项目名称:fido-ros,代码行数:69,代码来源:fido_fsm.py


注:本文中的fysom.Fysom.started方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。