motion_model.py 1021 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import env
  2. class Motion_model():
  3. def __init__(self, xI, xG):
  4. self.env = env.Env(xI, xG)
  5. self.obs = self.env.obs_map()
  6. def move_next(self, x, u, eta=0.2):
  7. """
  8. Motion model of robots,
  9. :param x: current state (node)
  10. :param u: input
  11. :param obs: obstacle map
  12. :param eta: noise in motion model
  13. :return: next states and corresponding probability
  14. """
  15. p_next = [1 - eta, eta / 2, eta / 2]
  16. x_next = []
  17. if u == (0, 1):
  18. u_real = [(0, 1), (-1, 0), (1, 0)]
  19. elif u == (0, -1):
  20. u_real = [(0, -1), (-1, 0), (1, 0)]
  21. elif u == (-1, 0):
  22. u_real = [(-1, 0), (0, 1), (0, -1)]
  23. else:
  24. u_real = [(1, 0), (0, 1), (0, -1)]
  25. for act in u_real:
  26. x_check = (x[0] + act[0], x[1] + act[1])
  27. if x_check in self.obs:
  28. x_next.append(x)
  29. else:
  30. x_next.append(x_check)
  31. return x_next, p_next