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