本文整理汇总了Python中fysom.Fysom.at_ball方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.at_ball方法的具体用法?Python Fysom.at_ball怎么用?Python Fysom.at_ball使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fysom.Fysom
的用法示例。
在下文中一共展示了Fysom.at_ball方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FidoBrain
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import at_ball [as 别名]
class FidoBrain(FSMClient):
def __init__(self, inputs, outputs):
self.inputs = inputs
self.outputs = outputs
self.fsm = Fysom({'initial': 'SeekingBall',
'events': [
{'name': 'found_ball', 'src': 'SeekingBall', 'dst': 'TrackingBall'},
{'name': 'lost_ball', 'src': ['TrackingBall', 'ApproachingBall'], 'dst': 'SeekingBall'},
{'name': 'ball_on_ground', 'src': 'TrackingBall', 'dst': 'ApproachingBall'},
{'name': 'ball_above_ground', 'src': 'ApproachingBall', 'dst': 'TrackingBall'},
{'name': 'near_ball', 'src': 'ApproachingBall', 'dst': 'FinalApproach'},
{'name': 'at_ball', 'src': 'FinalApproach', 'dst': 'PickingUpBall'},
{'name': 'have_ball', 'src': 'PickingUpBall', 'dst': 'TurningAround'},
{'name': 'turned_around', 'src': 'TurningAround', 'dst': 'SeekingFace'},
{'name': 'check_for_face', 'src': 'SeekingFace', 'dst': 'CheckingForFace'},
{'name': 'no_face', 'src': 'CheckingForFace', 'dst': 'SeekingFace'},
{'name': 'found_face', 'src': 'CheckingForFace', 'dst': 'ApproachingFace'},
{'name': 'lost_face', 'src': 'ApproachingFace', 'dst': 'SeekingFace'},
{'name': 'at_face', 'src': ['SeekingFace', 'ApproachingFace'], 'dst': 'DroppingBall'},
{'name': 'dropped_ball', 'src': 'DroppingBall', 'dst': 'SeekingBall'},
{'name': 'posed_for_play', 'src': 'PosingForPlay', 'dst': 'SeekingBall'}],
'callbacks': {
'onenterSeekingBall': self._enterSeekingBall,
'doSeekingBall': self._doSeekingBall,
'onenterTrackingBall': self._enterTrackingBall,
'doTrackingBall': self._doTrackingBall,
'onenterApproachingBall': self._enterApproachingBall,
'doApproachingBall': self._doApproachingBall,
'onenterFinalApproach': self._enterFinalApproach,
'doFinalApproach': self._doFinalApproach,
'onenterPickingUpBall': self._enterPickingUpBall,
'doPickingUpBall': self._doPickingUpBall,
'onenterTurningAround': self._enterTurningAround,
'doTurningAround': self._doTurningAround,
'onenterSeekingFace': self._enterSeekingFace,
'doSeekingFace': self._doSeekingFace,
'onenterCheckingForFace': self._enterCheckingForFace,
'doCheckingForFace': self._doCheckingForFace,
'onenterApproachingFace': self._enterApproachingFace,
'doApproachingFace': self._doApproachingFace,
'onenterDroppingBall': self._enterDroppingBall,
'doDroppingBall': self._doDroppingBall,
'onenterPosingForPlay': self._enterPosingForPlay,
'doPosingForPlay': self._doPosingForPlay}})
def should_find_ball(self):
return self.fsm.current in ['SeekingBall', 'TrackingBall', 'ApproachingBall', 'FinalApproach']
def should_find_face(self):
return self.fsm.current in ['SeekingFace', 'CheckingForFace', 'ApproachingFace']
#
# fsm action methods (private)
#
def _enterSeekingBall(self, event):
pass
def _doSeekingBall(self):
self.outputs['left_wheel'] = -100
self.outputs['right_wheel'] = 100
self.outputs['legs'] = servo_if.LEGS_UP
self.outputs['neck'] = servo_if.NECK_START
self.outputs['head'] = servo_if.HEAD_CENTER
if self.inputs['ball_area'] > 50:
self.fsm.found_ball()
def _enterTrackingBall(self, event):
pass
def _doTrackingBall(self):
#if we lose the ball, go back to seeking; if it's on the ground, approach it.
if self.inputs['ball_area'] <= 40:
self.fsm.lost_ball()
elif self.inputs['ball_area'] >= 50 and self.inputs['ball_y'] >= 120 and self.outputs['neck'] < servo_if.NECK_CENTER:
self.fsm.ball_on_ground()
elif random.random() > 0.95:
self.outputs['jaw'] = (servo_if.JAW_OPEN + servo_if.JAW_CLOSED_EMPTY) / 2
play_sound("bark03.mp3")
def _enterApproachingBall(self, event):
self.outputs['legs'] = servo_if.LEGS_UP
def _doApproachingBall(self):
if self.inputs['ball_area'] <= 40:
self.fsm.lost_ball()
elif self.inputs['ball_y'] < 240 and self.outputs['neck'] > servo_if.NECK_CENTER:
self.fsm.ball_above_ground()
elif self.inputs['avg_ball_area'] > NEAR_BALL_AREA:
#self.outputs['left_wheel'] = 0
#self.outputs['right_wheel'] = 0
self.fsm.near_ball()
def _enterFinalApproach(self, event):
self.last_ir_l = self.inputs['ir_l']
self.last_ir_m = self.inputs['ir_m']
self.last_ir_r = self.inputs['ir_r']
def _doFinalApproach(self):
ir_l = self.inputs['ir_l']
ir_m = self.inputs['ir_m']
#.........这里部分代码省略.........