Skip to content

Commit 2978ad6

Browse files
author
Karan
committed
tree implementation and node id stuff
1 parent a21f5af commit 2978ad6

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 51,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import numpy as np\n",
10+
"def ConfigurationToGridCoord(config):\n",
11+
" \n",
12+
" # TODO:\n",
13+
" # This function maps a configuration in the full configuration space\n",
14+
" # to a grid coordinate in discrete space\n",
15+
" #\n",
16+
" coord = [0] * 2\n",
17+
" lower_lims = [0, 0]\n",
18+
" for i in range(0, len(coord)):\n",
19+
" start = lower_lims[i] # start of the configuration space\n",
20+
" coord[i] = np.around((config[i] - start)/ 1)\n",
21+
" return coord"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 52,
27+
"metadata": {},
28+
"outputs": [
29+
{
30+
"data": {
31+
"text/plain": [
32+
"[2.0, 1.0]"
33+
]
34+
},
35+
"execution_count": 52,
36+
"metadata": {},
37+
"output_type": "execute_result"
38+
}
39+
],
40+
"source": [
41+
"coord = ConfigurationToGridCoord([2,1])\n",
42+
"coord"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": 158,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"def GridCoordToNodeId(coord):\n",
52+
" upper_limits = [4, 3]\n",
53+
" lower_limits = [0, 0]\n",
54+
" num_cells = []\n",
55+
" for idx in range(2):\n",
56+
" num_cells.append(np.ceil((upper_limits[idx] - lower_limits[idx])/1))\n",
57+
" node_id = 0\n",
58+
" print(\"num_cells \", num_cells)\n",
59+
" for i in range(len(coord) - 1, -1, -1):\n",
60+
" # Get product of the grid space maximums\n",
61+
" prod = 1\n",
62+
" for j in range(0, i):\n",
63+
" print(\"j: \", j)\n",
64+
" prod = prod * num_cells[j]\n",
65+
" print(\"prod: \", prod)\n",
66+
" # Add the product to the sum\n",
67+
" node_id = node_id + coord[i] * prod\n",
68+
" print(\"n: \", node_id)\n",
69+
" return int(node_id)"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": 159,
75+
"metadata": {},
76+
"outputs": [
77+
{
78+
"name": "stdout",
79+
"output_type": "stream",
80+
"text": [
81+
"num_cells [4.0, 3.0]\n",
82+
"j: 0\n",
83+
"prod: 4.0\n",
84+
"n: 8.0\n",
85+
"n: 10.0\n"
86+
]
87+
},
88+
{
89+
"data": {
90+
"text/plain": [
91+
"10"
92+
]
93+
},
94+
"execution_count": 159,
95+
"metadata": {},
96+
"output_type": "execute_result"
97+
}
98+
],
99+
"source": [
100+
"GridCoordToNodeId([2, 2])"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"metadata": {},
107+
"outputs": [],
108+
"source": []
109+
}
110+
],
111+
"metadata": {
112+
"kernelspec": {
113+
"display_name": "Python 3",
114+
"language": "python",
115+
"name": "python3"
116+
},
117+
"language_info": {
118+
"codemirror_mode": {
119+
"name": "ipython",
120+
"version": 3
121+
},
122+
"file_extension": ".py",
123+
"mimetype": "text/x-python",
124+
"name": "python",
125+
"nbconvert_exporter": "python",
126+
"pygments_lexer": "ipython3",
127+
"version": "3.6.3"
128+
}
129+
},
130+
"nbformat": 4,
131+
"nbformat_minor": 2
132+
}

PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,43 @@
1515

1616
show_animation = True
1717

18+
class Tree(object):
19+
20+
def __init__(self, start, lowerLimit, upperLimit, resolution):
21+
self.vertices = dict()
22+
vertex_id = self.gridCoordinateToNodeId(start)
23+
self.vertices[vid] = []
24+
self.edges = []
25+
self.start = start
26+
self.lowerLimit = lowerLimit
27+
self.upperLimit = upperLimit
28+
for idx in range(len(lowerLimit)):
29+
self.num_cells[idx] = np.ceil((upperLimit[idx] - lowerLimit[idx])/resolution)
30+
31+
def getRootId(self):
32+
return 0
33+
34+
def addVertex(self, vertex):
35+
vertex_id = self.gridCoordinateToNodeId(vertex)
36+
self.vertices[vertex_id] = []
37+
return vertex_id
38+
39+
def addEdge(self, v, x):
40+
if (v, x) not in self.edges:
41+
self.edges.append((v,x))
42+
self.vertices[v].append(x)
43+
self.vertices[x].append(v)
44+
45+
def gridCoordinateToNodeId(self, coord):
46+
nodeId = 0
47+
for i in range(len(coord) - 1, -1, -1):
48+
product = 1
49+
for j in range(0 , i):
50+
product *= product * self.num_cells[j]
51+
node_id = node_id + coord[i] * product
52+
return node_id
53+
54+
1855
class Node():
1956

2057
def __init__(self, x, y):
@@ -72,11 +109,16 @@ def plan(self, animation=True):
72109
C = np.dot(np.dot(U, np.diag(
73110
[1.0, 1.0, np.linalg.det(U) * np.linalg.det(np.transpose(Vh))])), Vh)
74111

112+
foundGoal = False
113+
# run until done
75114
while (iterations < self.maxIter):
76115
if len(self.vertex_queue) == 0 and len(self.edge_queue) == 0:
77116
samples = self.informedSample(100, cBest, cMin, xCenter, C)
78117
# prune the tree
79118

119+
120+
121+
80122
if animation:
81123
self.drawGraph(xCenter=xCenter, cBest=cBest,
82124
cMin=cMin, etheta=etheta, samples=samples)

0 commit comments

Comments
 (0)