environment.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @author: huiming zhou
  5. """
  6. import numpy as np
  7. col, row = 50, 30 # size of background
  8. motions = [(1, 0), (-1, 0), (0, 1), (0, -1)] # feasible motion sets
  9. def obstacles():
  10. """
  11. Design the obstacles' positions.
  12. :return: the map of obstacles.
  13. """
  14. background = [[[1., 1., 1.]
  15. for x in range(col)] for y in range(row)]
  16. for j in range(col):
  17. background[0][j] = [0., 0., 0.]
  18. background[row - 1][j] = [0., 0., 0.]
  19. for i in range(row):
  20. background[i][0] = [0., 0., 0.]
  21. background[i][col - 1] = [0., 0., 0.]
  22. for i in range(10, 20):
  23. background[15][i] = [0., 0., 0.]
  24. for i in range(15):
  25. background[row - 1 - i][30] = [0., 0., 0.]
  26. background[i + 1][20] = [0., 0., 0.]
  27. background[i + 1][40] = [0., 0., 0.]
  28. return background
  29. def map_obs():
  30. """
  31. Using a matrix to represent the position of obstacles,
  32. which is used for obstacle detection.
  33. :return: a matrix, in which '1' represents obstacle.
  34. """
  35. obs_map = np.zeros((col, row))
  36. pos_map = obstacles()
  37. for i in range(col):
  38. for j in range(row):
  39. if pos_map[j][i] == [0., 0., 0.]:
  40. obs_map[i][j] = 1
  41. return obs_map