motion_model.py 950 B

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