motion_model.py 1.1 KB

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