def idle(self):
"""Updates the QLearning table, retrieves an action to be performed
and checks for dead-ends."""
state = NavigationState(self.perception_)
action = self.learning_model.update(state).action_
if (all(s.imminent_collision for s in self.sensors['proximity']) or
self.sensors['orientation'][0].is_lying_on_the_ground):
# There's nothing left to do. Flag this is a dead-end.
self.behavior_ = self.BEHAVIORS.stuck
else:
move_to = self.INSTRUCTIONS_MAP[action]
if action < ACTIONS.left:
# It's walking straight or backwards. Reduce step size if it's
# going against a close obstacle.
dx = self.sensors['proximity'][action.index].distance
move_to = np.clip(move_to, -dx, dx).tolist()
self.motion.post.moveTo(move_to)
self.behavior_ = self.BEHAVIORS.moving
return self
评论列表
文章目录