@@ -73,8 +73,11 @@ def plan(self):
73
73
74
74
# If the neighbour is not already visited and if not in Obstacle space
75
75
if not self .graph .checkObstacleSpace (nbr_node ) and not check_NodeIn_list (nbr_node ,self .CLOSED ):
76
- movement_cost , new_orientation ,turtlebot_twist = node_values
77
- new_orientation = new_orientation % 360
76
+
77
+ movement_cost = node_values ["cost" ]
78
+ new_orientation = node_values ["orientation" ]% 360
79
+ turtlebot_twist = node_values ["twist" ]
80
+
78
81
if self .V [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]] == 0 :
79
82
80
83
self .V [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]] = 1
@@ -89,7 +92,10 @@ def plan(self):
89
92
90
93
self .OPEN .insert_pq (self .f [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]],(nbr_node ,new_orientation ))
91
94
self .backtrack_node [nbr_node ]= {}
92
- self .backtrack_node [nbr_node ][self .f [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]]] = (current_vtx [0 ],current_vtx [1 ],turtlebot_twist )
95
+ self .backtrack_node [nbr_node ][self .f [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]]] = {"vertex" :current_vtx [0 ],
96
+ "orientation" :current_vtx [1 ],
97
+ "twist" :turtlebot_twist ,
98
+ "intermediate_nodes" :node_values ["intermediate_nodes" ]}
93
99
94
100
if euclidean_heuristic (nbr_node ,self .goal ) <= 1.5 : # Check if goal node is reached
95
101
print ("The goal node is found" )
@@ -99,7 +105,10 @@ def plan(self):
99
105
if self .f [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]] > self .f [int (2 * current_vtx [0 ].x )][int (2 * current_vtx [0 ].y )][self .orientation [current_vtx [1 ]]]:
100
106
self .f [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]] = self .f [int (2 * current_vtx [0 ].x )][int (2 * current_vtx [0 ].y )][self .orientation [current_vtx [1 ]]]
101
107
same_nbr_node = getSameNode (nbr_node ,list (self .backtrack_node .keys ()))
102
- self .backtrack_node [same_nbr_node ][self .f [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]]] = (current_vtx [0 ],current_vtx [1 ],turtlebot_twist )
108
+ self .backtrack_node [same_nbr_node ][self .f [int (2 * nbr_node .x )][int (2 * nbr_node .y )][self .orientation [new_orientation ]]] = {"vertex" :current_vtx [0 ],
109
+ "orientation" :current_vtx [1 ],
110
+ "twist" :turtlebot_twist ,
111
+ "intermediate_nodes" :node_values ["intermediate_nodes" ]}
103
112
104
113
105
114
# If a path Doesn't exit
@@ -114,23 +123,25 @@ def extract_path(self,vertex):
114
123
bkt_list -- List of nodes in the shortest path
115
124
'''
116
125
117
- bkt_list = []
118
- angle_node_list = []
119
- bkt_list .append (self .goal )
126
+ goal_node = {"vertex" :self .goal ,
127
+ "orientation" :None ,
128
+ "twist" :None ,
129
+ "intermediate_nodes" :None }
130
+
131
+ angle_node_list = [goal_node ]
120
132
node = vertex
121
133
# loops till goal is not equal to zero
122
134
while node != 0 :
123
135
for nbr ,values in reversed (list (self .backtrack_node .items ())):
124
136
# if nbr and goal are same
125
- for cost ,parent in values .items ():
137
+ for _ ,parent in values .items ():
126
138
127
139
if check_nodes (nbr ,node ):
128
- if not check_NodeIn_list (parent [0 ],bkt_list ):
129
- bkt_list .append (parent [0 ])
140
+ if not check_NodeIn_list (parent ["vertex" ],[node ["vertex" ] for node in angle_node_list ]):
130
141
angle_node_list .append (parent )
131
- node = parent [0 ]
142
+ node = parent ["vertex" ]
132
143
133
- if check_nodes (parent [0 ],self .start [0 ]):
144
+ if check_nodes (parent ["vertex" ],self .start [0 ]):
134
145
node = 0
135
146
return angle_node_list
136
147
@@ -189,28 +200,28 @@ def get_grid_size(obstacle_list):
189
200
190
201
mp_data = motion_planning ()
191
202
192
- for i in shortest_path :
203
+ for i in shortest_path [ 1 :] :
193
204
194
205
path_pt = Point ()
195
- path_pt .x = i [0 ].x
196
- path_pt .y = i [0 ].y
206
+ path_pt .x = i ["vertex" ].x
207
+ path_pt .y = i ["vertex" ].y
197
208
path_pt .z = 0
198
209
mp_data .path .append (path_pt )
199
210
200
- mp_data .orientation .append (i [1 ])
211
+ mp_data .orientation .append (i ["orientation" ])
201
212
202
213
twist_pt = Twist ()
203
- twist_pt .angular .z = i [- 1 ][0 ]
204
- twist_pt .linear .x = i [- 1 ][1 ]
214
+ twist_pt .angular .z = i ["twist" ][0 ]
215
+ twist_pt .linear .x = i ["twist" ][1 ]
205
216
206
217
mp_data .turtlebot_twist .append (twist_pt )
207
218
208
219
mp_pub .publish (mp_data )
209
220
210
- # plot_result = Visualize(start[0],goal,obs_locations,RPM,grid_size)
211
- # plot_result.animate("Astar",None ,shortest_path)
221
+ plot_result = Visualize (start [0 ],goal ,obs_locations ,RPM ,grid_size )
222
+ plot_result .animate ("Astar" ,shortest_path )
212
223
213
224
for i in shortest_path :
214
- rospy .loginfo (f"The x : { i [0 ].x } and y : { i [0 ].y } and orientation { i [1 ]} " )
225
+ rospy .loginfo (f"The x coordinate : { i ['vertex' ].x } and y coordinate : { i ['vertex' ].y } and orientation : { i ['orientation' ]} " )
215
226
216
227
0 commit comments