Skip to content

Commit 95a274d

Browse files
change action sets, right now it does not stuck in the middle of the first obstacle
1 parent 1ae44af commit 95a274d

2 files changed

Lines changed: 64 additions & 15 deletions

File tree

GEMstack/onboard/planning/parking_planning.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ def __init__(self, vehicle=None, obstacles=None, actions=None):
2727
self._vehicle = None
2828

2929
# SecondOrderDubinsCar() #x = (tx,ty,theta,v,dtheta) and u = (fwd_accel,wheel_angle_rate)
30-
self.vehicle_sim = IntegratorControlSpace(SecondOrderDubinsCar(), T=2, dt=0.1)
31-
#@TODO create a more standardized way to define the actions
32-
self._actions = [(2, -0.5), (2, -0.25), (2,0), (2, 0.25), (2,0.5),
33-
(0,0), (-1, -0.5), (-1,0), (-1, 0.5)]
30+
# self.vehicle_sim = IntegratorControlSpace(SecondOrderDubinsCar(), T=2, dt=0.1)
31+
self.vehicle_sim = IntegratorControlSpace(SecondOrderDubinsCar(), T=0.5, dt=0.2)
32+
# #@TODO create a more standardized way to define the actions
33+
# self._actions = [(2, -0.5), (2, -0.25), (2,0), (2, 0.25), (2,0.5),
34+
# (0,0), (-1, -0.5), (-1,0), (-1, 0.5)]
35+
self._actions = generate_action_set()
36+
37+
@staticmethod
38+
def generate_action_set():
39+
return [
40+
(1.0, -0.3), (1.0, 0.0), (1.0, 0.3),
41+
(-1.0, -0.3), (-1.0, 0.0), (-1.0, 0.3)
42+
]
3443

3544
@property
3645
def vehicle(self):
@@ -77,7 +86,7 @@ def heuristic_cost_estimate(self, state_1, state_2):
7786
goal = (x2, y2, theta2)
7887

7988
# Calculate Reeds-Shepp path length
80-
path_length_cost = path_length(start, goal, 1.0) # Using turning radius of 1.0
89+
path_length_cost = path_length(start, goal, 0.5) # Using turning radius of 1.0
8190

8291
# Add penalties for velocity and time differences
8392
velocity_penalty = abs(v2 - v1) * 0.1
@@ -98,7 +107,7 @@ def terminal_cost_estimate(self, state_1, state_2):
98107
goal = (x2, y2, theta2)
99108

100109
# Calculate Reeds-Shepp path length
101-
path_length_cost = path_length(start, goal, 1.0) # Using turning radius of 1.0
110+
path_length_cost = path_length(start, goal, 0.5) # Using turning radius of 1.0
102111

103112
# Add penalties for velocity, angular velocity, and time differences
104113
velocity_penalty = abs(v2 - v1) * 0.1
@@ -128,7 +137,10 @@ def neighbors(self, node):
128137
next_state = np.append(next_state, node[5] + self.vehicle_sim.T)
129138
next_state = np.round(next_state, 3)
130139
if self.is_valid_neighbor([next_state]):
140+
print(f"Accepted: {next_state}")
131141
neighbors.append(tuple(next_state))
142+
else:
143+
print(f"Rejected (collision): {next_state}")
132144
return neighbors
133145

134146
def is_valid_neighbor(self, path):
@@ -181,7 +193,12 @@ def state_to_polygon(self, state):
181193
outline=self.vehicle.to_object().outline)
182194

183195
return temp_obj.polygon()
184-
196+
197+
def generate_action_set():
198+
return [
199+
(1.0, -0.3), (1.0, 0.0), (1.0, 0.3),
200+
(-1.0, -0.3), (-1.0, 0.0), (-1.0, 0.3)
201+
]
185202
# @TODO Need to change the functions here to use VehicleState
186203
class ParkingSolverFirstOrderDubins(AStar):
187204
"""sample use of the astar algorithm. In this exemple we work on a maze made of ascii characters,
@@ -194,10 +211,9 @@ def __init__(self, vehicle=None, obstacles=None, actions=None):
194211
self._vehicle = None
195212

196213
self.vehicle = DubinsCar() #x = (tx,ty,theta) and u = (fwd_velocity,turnRate).
197-
self.vehicle_sim = DubinsCarIntegrator(self.vehicle, 1.5, 0.25)
214+
self.vehicle_sim = DubinsCarIntegrator(self.vehicle, 1, 0.25)
198215
#@TODO create a more standardized way to define the actions
199-
self.actions = [(1, -1), (1, -0.5), (1,0), (1, 0.5), (1,1),
200-
(-1, -1), (-1, -0.5), (-1,0), (-1, 0.5), (-1,1)]
216+
self._actions = generate_action_set()
201217

202218

203219
@property
@@ -260,6 +276,7 @@ def neighbors(self, node):
260276
""" for a given configuration of the car in the maze, returns up to 4 adjacent(north,east,south,west)
261277
nodes that can be reached (=any adjacent coordinate that is not a wall)
262278
"""
279+
print(f"[DEBUG] neighbors() called on node {node}")
263280
neighbors = []
264281
# print(f"Node: {node}")
265282
for control in self.actions:
@@ -268,7 +285,10 @@ def neighbors(self, node):
268285
next_state = np.append(next_state, node[3] + self.vehicle_sim.T)
269286
next_state = np.round(next_state, 3)
270287
if self.is_valid_neighbor([next_state]):
288+
print(f"Accepted: {next_state}")
271289
neighbors.append(tuple(next_state))
290+
else:
291+
print(f"Rejected first order (collision): {next_state}")
272292
return neighbors
273293

274294
def is_valid_neighbor(self, path):
@@ -414,7 +434,7 @@ def update(self, state : AllState) -> Trajectory:
414434
obstacles = state.obstacles # type: Dict[str, Obstacle]
415435
agents = state.agents # type: Dict[str, AgentState]
416436
# print(f"Obstacles {obstacles}")
417-
# print(f"Agents {agents}")
437+
print(f"Agents {agents}")
418438
route = state.route
419439
goal_point = route.points[-1] # I might need to change this to the same frame as the car?
420440
goal_pose = ObjectPose(frame=ObjectFrameEnum.ABSOLUTE_CARTESIAN, t=15, x=goal_point[0],y=goal_point[1],z=0,yaw=0)

launch/parking.yaml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ variants:
8383
drive:
8484
perception:
8585
agent_detection : pedestrian_detection.FakePedestrianDetector2D
86-
86+
8787
fake_sim:
8888
run:
8989
description: "Run the yielding trajectory planner in simulation with faked perception"
@@ -93,7 +93,36 @@ variants:
9393
args:
9494
scene: !relative_path '../scenes/parking_demo.yaml'
9595
visualization: !include "klampt_visualization.yaml"
96-
drive:
96+
drive:
9797
perception:
98-
agent_detection : OmniscientAgentDetector #this option reads agents from the simulator
99-
state_estimation : OmniscientStateEstimator
98+
agent_detection : OmniscientAgentDetector
99+
state_estimation : OmniscientStateEstimator
100+
planning:
101+
route_planning:
102+
type: StaticRoutePlanner
103+
args: [!relative_path '../GEMstack/knowledge/routes/parking.csv','start']
104+
motion_planning:
105+
type: parking_planning.ParkingPlanner
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
# fake_sim:
117+
# run:
118+
# description: "Run the yielding trajectory planner in simulation with faked perception"
119+
# mode: simulation
120+
# vehicle_interface:
121+
# type: gem_simulator.GEMDoubleIntegratorSimulationInterface
122+
# args:
123+
# scene: !relative_path '../scenes/parking_demo.yaml'
124+
# visualization: !include "klampt_visualization.yaml"
125+
# drive:
126+
# perception:
127+
# agent_detection : OmniscientAgentDetector #this option reads agents from the simulator
128+
# state_estimation : OmniscientStateEstimator

0 commit comments

Comments
 (0)