Skip to content

Commit 12873ad

Browse files
committed
Adding new environments
1 parent 2d47c5f commit 12873ad

13 files changed

Lines changed: 306 additions & 62 deletions

File tree

GEMstack/onboard/planning/longitudinal_planning.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ..component import Component
55
from ...state import AllState, VehicleState, EntityRelation, EntityRelationEnum, Path, Trajectory, Route, \
66
ObjectFrameEnum
7-
from ...utils import serialization
7+
from ...utils import serialization, settings
88
from ...mathutils import transforms
99
import numpy as np
1010

@@ -378,10 +378,10 @@ class YieldTrajectoryPlanner(Component):
378378
def __init__(self):
379379
self.route_progress = None
380380
self.t_last = None
381-
self.acceleration = 5
382-
self.desired_speed = 2.0
383-
self.deceleration = 2.0
384-
self.emergency_brake = 8.0
381+
self.acceleration = settings.get("run.drive.planning.motion_planning.largs.acceleration", 5)
382+
self.desired_speed = settings.get("run.drive.planning.motion_planning.largs.desired_speed",2.0)
383+
self.deceleration = settings.get("run.drive.planning.motion_planning.largs.deceleration", 2.0)
384+
self.emergency_brake = settings.get("run.drive.planning.motion_planning.largs.emergency_brake", 8.0)
385385

386386
def state_inputs(self):
387387
return ['all']

GEMstack/onboard/planning/parking_route_planner.py

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,12 @@ def __init__(self, vehicle=None, obstacles=None, actions=None):
220220
self._vehicle = None
221221

222222
# settings
223-
self.T = settings.get("planning.dubins.integrator.time_step", 1.5)
224-
self.dt = settings.get("planning.dubins.integrator.time_step", .25)
225-
self.max_v = settings.get("planning.dubins.actions.max_velocity", 0.75)
226-
self.max_turn_rate = settings.get("planning.dubins.actions.max_turn_rate", 0.3)
223+
self.T = settings.get("run.drive.planning.route_planning_component.dubins.integrator.time_step", 1.5)
224+
self.dt = settings.get("run.drive.planning.route_planning_component.dubins.integrator.dt", .25)
225+
self.max_v = settings.get("run.drive.planning.route_planning_component.dubins.actions.max_velocity", 0.75)
226+
self.max_turn_rate = settings.get("run.drive.planning.route_planning_component.dubins.actions.max_turn_rate", 0.3)
227+
self.tolerance = settings.get("run.drive.planning.route_planning_component.dubins.tolerance", 0.5)
228+
self.heuristic_string = settings.get("run.drive.planning.route_planning_component.astar.heuristic", "reeds_shepp")
227229

228230
self.vehicle = DubinsCar() #x = (tx,ty,theta) and u = (fwd_velocity,turnRate).
229231
self.vehicle_sim = DubinsCarIntegrator(self.vehicle, self.T, self.dt)
@@ -260,19 +262,24 @@ def is_goal_reached(self, current: List[float], goal: List[float]):
260262
# @TODO Currently, the threshold is just a random number, get rid of magic constants
261263
# print(f"Current Pose: {current}")
262264
# print(f"Goal Pose: {goal}")
263-
# if np.abs(current[3]) > 1: return False # car must be stopped, this equality will only work in simulation
265+
# if np.abs(current[3]) > 1: return False # car must be stopped, this equality will only work in simulation np.linalg.norm(np.array([current[0], current[1]]) - np.array([goal[0], goal[1]])) < 0.5
266+
# if np.abs(current[3] - goal[3]) > .25: return False
264267
return np.linalg.norm(np.array([current[0], current[1]]) - np.array([goal[0], goal[1]])) < 0.5
265268

266269
def heuristic_cost_estimate(self, state_1, state_2):
267-
"""computes the 'direct' distance between two (x,y) tuples"""
268-
# Extract position and orientation from states
269-
(x1, y1, theta1, t) = state_1
270-
(x2, y2, theta2, t) = state_2
271-
272-
return self.reed_shepp(state_1, state_2) # Using turning radius of 1.0
270+
"""run the correct heuristic function based on the heuristic_string"""
273271

274-
return self.approx_reeds_shepp(state_1, state_2) # Using turning radius of 1.0
275-
return math.hypot(x2 - x1, y2 - y1, theta2 - theta1)
272+
if self.heuristic_string == "reeds_shepp":
273+
return self.reed_shepp(state_1, state_2) # Using turning radius of 1.0
274+
275+
elif self.heuristic_string == "approx_reeds_shepp":
276+
return self.approx_reeds_shepp(state_1, state_2) # Using turning radius of 1.0
277+
278+
elif self.heuristic_string == "euclidian":
279+
return self.euclidian_cost_esimate(state_1, state_2)
280+
281+
else:
282+
raise Exception(f"Unknown heuristic function: {self.heuristic_string}")
276283

277284
def euclidian_cost_esimate(self, state_1, state_2):
278285
"""computes the 'direct' distance between two (x,y) tuples"""
@@ -432,7 +439,7 @@ def __init__(self):
432439
# self.planner = ParkingSolverSecondOrderDubins()
433440
self.planner = ParkingSolverFirstOrderDubins()
434441

435-
self.iterations = settings.get("planning.astar.iterations", 200)
442+
self.iterations = settings.get("run.drive.planning.route_planning_component.astar.iterations", 50000)
436443

437444
def state_inputs(self):
438445
return ['all']
@@ -479,6 +486,22 @@ def vehicle_state_to_first_order(self, vehicle_state: VehicleState) -> Tuple[flo
479486
t = 0
480487

481488
return (x,y,theta,t)
489+
490+
def pose_to_first_order(self, pose: ObjectPose) -> Tuple[float, float]:
491+
"""Takes a vehicle state and outputs the state of a second order dubins car
492+
493+
Args:
494+
vehicle_state (VehicleState): _description_
495+
496+
Returns:
497+
Tuple[float, float]: _description_
498+
"""
499+
x = pose.x
500+
y = pose.y
501+
theta = pose.yaw # check that this is correct
502+
t = 0
503+
504+
return (x,y,theta,t)
482505

483506
def update(self, state : AllState) -> Route:
484507
"""_summary_
@@ -496,34 +519,36 @@ def update(self, state : AllState) -> Route:
496519
all_obstacles = {**agents, **obstacles}
497520
# print(f"Obstacles {obstacles}")
498521
print(f"Agents {agents}")
499-
# goal= state.goal
500-
# print(goal.frame)
501-
# assert goal.frame == ObjectFrameEnum.ABSOLUTE_CARTESIAN
502-
# assert goal.v == 0
503-
# print(f"Goal {goal}")
504-
goal_pose = ObjectPose(frame=ObjectFrameEnum.CURRENT, t=15, x=state.mission_plan.goal_x,y=state.mission_plan.goal_y,z=0,yaw=state.mission_plan.goal_orientation)
522+
goal_pose = state.goal
523+
assert goal_pose.frame == ObjectFrameEnum.CURRENT
505524
print("Checking VALUE: ", state.start_vehicle_pose)
506-
start_pose = state.vehicle.pose.to_frame(ObjectFrameEnum.CURRENT, current_pose = state.vehicle.pose,start_pose_abs = state.start_vehicle_pose)
507-
start_cur = VehicleState.zero()
508-
start_cur.pose = start_pose
509-
goal = VehicleState.zero()
510-
goal.pose = goal_pose
511-
goal.v = 0
525+
print("Checking VALUE: ", state.vehicle)
526+
start_state = state.vehicle.to_frame(ObjectFrameEnum.CURRENT, current_pose = state.vehicle.pose,start_pose_abs = state.start_vehicle_pose)
527+
# start_pose = state.vehicle.pose.to_frame(ObjectFrameEnum.CURRENT, current_pose = state.vehicle.pose,start_pose_abs = state.start_vehicle_pose)
528+
# start_cur = VehicleState.zero()
529+
# start_cur.pose = start_pose # goal.pose = goal_pose
530+
# goal.v = 0
531+
print("Checking VALUE: ", start_state)
532+
533+
534+
512535

513536
# # Need to parse and create second order dubin car states
514537
# start_state = self.vehicle_state_to_dynamics(vehicle)
515538
# goal_state = self.vehicle_state_to_dynamics(goal)
516539

517540
# Need to parse and create second order dubin car states
518-
start_state = self.vehicle_state_to_first_order(start_cur)
519-
goal_state = self.vehicle_state_to_first_order(goal)
541+
start = self.vehicle_state_to_first_order(start_state)
542+
# goal = self.vehicle_state_to_first_order(goal_state)
543+
goal = self.pose_to_first_order(goal_pose)
520544

521545
# Update the planner
522546
self.planner.obstacles = list(all_obstacles.values())
523547
self.planner.vehicle = vehicle
524548

525549
# Compute the new trajectory and return it
526-
res = list(self.planner.astar(start_state, goal_state, reversePath=False, iterations=self.iterations))
550+
print(f"Iteartions ------------------------------ {self.iterations}")
551+
res = list(self.planner.astar(start, goal, reversePath=False, iterations=self.iterations))
527552
# points = [state[:2] for state in res] # change here to return the theta as well
528553
points = []
529554
for state in res:

launch/parking_detection.yaml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ variants:
9191
vehicle_interface:
9292
type: gem_simulator.GEMDoubleIntegratorSimulationInterface
9393
args:
94-
scene: !relative_path '../scenes/parking_demo.yaml'
94+
scene: !relative_path '../scenes/parking/demo_2.yaml'
9595
# visualization: !include "klampt_visualization.yaml"
9696

9797
drive:
@@ -130,7 +130,7 @@ variants:
130130
vehicle_interface:
131131
type: gem_simulator.GEMDoubleIntegratorSimulationInterface
132132
args:
133-
scene: !relative_path '../scenes/parking_demo.yaml'
133+
scene: !relative_path '../scenes/parking/demo_3.yaml'
134134
visualization: !include "klampt_visualization.yaml"
135135

136136
drive:
@@ -145,10 +145,28 @@ variants:
145145
type: ParkingSim
146146
route_planning_component:
147147
type: RoutePlanningComponent
148+
dubins:
149+
integrator:
150+
timestep: 1
151+
dt: .25
152+
max_velocity: 0.75
153+
max_turning_rate: 0.3
154+
tolerance: 0.25
155+
astar:
156+
iterations: 5000 # We should have some sort of max iterations/timeout
157+
heuristic: reeds_shepp
158+
159+
148160
# route_planning:
149161
# type: StaticRoutePlanner
150162
# args: [!relative_path '../GEMstack/knowledge/routes/forward_15m.csv'] #forward_15m
151-
motion_planning: longitudinal_planning.YieldTrajectoryPlanner
163+
motion_planning:
164+
type: longitudinal_planning.YieldTrajectoryPlanner
165+
largs:
166+
acceleration: 1
167+
deceleration: 2
168+
desired_speed: 1
169+
152170
trajectory_tracking:
153171
type: pure_pursuit.PurePursuitTrajectoryTracker
154172
print: False

scenes/parking/demo_1.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
vehicle_state: [5.0, 5.0, 0.0, 0.0, 0.0]
2+
agents:
3+
cone1:
4+
type: cone
5+
position: [50.0, 8.0]
6+
nominal_velocity: 0.0
7+
target: [60.0, 8.0]
8+
behavior: loop
9+
yaw: 0
10+
11+
cone2:
12+
type: cone
13+
position: [56.0, 8.0]
14+
nominal_velocity: 0.0
15+
target: [60.0, 8.0]
16+
behavior: loop
17+
yaw: 0
18+
19+
cone3:
20+
type: cone
21+
position: [50.0, 4.0]
22+
nominal_velocity: 0.0
23+
target: [60.0, 8.0]
24+
behavior: loop
25+
yaw: 0
26+
27+
cone4:
28+
type: cone
29+
position: [56.0, 4.0]
30+
nominal_velocity: 0.0
31+
target: [60.0, 8.0]
32+
behavior: loop
33+
yaw: 0

scenes/parking/demo_10.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
vehicle_state: [0.0, 0.0, 0.0, 0.0, 0.0]
2+
agents:
3+
ped1:
4+
type: medium_truck
5+
position: [2.5, 8.0]
6+
nominal_velocity: 0.0
7+
target: [20.0, 8.0]
8+
behavior: loop
9+
yaw: 1.5708
10+
11+
ped2:
12+
type: medium_truck
13+
position: [7.5, 8.0]
14+
nominal_velocity: 0.0
15+
target: [15.0, 4.0]
16+
behavior: loop
17+
yaw: 1.5708
18+
19+
Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
1-
vehicle_state: [5.0, 5.0, 0.0, 0.0, 0.0]
2-
agents:
3-
# ped1:
4-
# type: medium_truck
5-
# position: [20.0, 8.0]
6-
# nominal_velocity: 0.0
7-
# target: [20.0, 8.0]
8-
# behavior: loop
9-
# yaw: 1.5708
1+
vehicle_state: [-1.0, -2.0, 0.0, 0.0, 0.0]
102

11-
# ped2:
12-
# type: medium_truck
13-
# position: [30.0, 8.0]
14-
# nominal_velocity: 0.0
15-
# target: [15.0, 4.0]
16-
# behavior: loop
17-
# yaw: 1.5708
18-
3+
agents:
194
cone1:
205
type: cone
21-
position: [50.0, 8.0]
6+
position: [3, 10.0]
227
nominal_velocity: 0.0
238
target: [60.0, 8.0]
249
behavior: loop
2510
yaw: 0
2611

2712
cone2:
2813
type: cone
29-
position: [56.0, 8.0]
14+
position: [7, 10.0]
3015
nominal_velocity: 0.0
3116
target: [60.0, 8.0]
3217
behavior: loop
3318
yaw: 0
3419

3520
cone3:
3621
type: cone
37-
position: [50.0, 4.0]
22+
position: [3, 4.0]
3823
nominal_velocity: 0.0
3924
target: [60.0, 8.0]
4025
behavior: loop
4126
yaw: 0
4227

43-
# cone4:
44-
# type: cone
45-
# position: [56.0, 4.0]
28+
cone4:
29+
type: cone
30+
position: [7, 4.0]
31+
nominal_velocity: 0.0
32+
target: [60.0, 8.0]
33+
behavior: loop
34+
yaw: 0
35+
36+
# ped1:
37+
# type: medium_truck
38+
# position: [2.25, 8.0]
4639
# nominal_velocity: 0.0
47-
# target: [60.0, 8.0]
40+
# target: [20.0, 8.0]
4841
# behavior: loop
49-
# yaw: 0
42+
# yaw: 1.5708
43+
44+
# ped2:
45+
# type: medium_truck
46+
# position: [7.75, 8.0]
47+
# nominal_velocity: 0.0
48+
# target: [15.0, 4.0]
49+
# behavior: loop
50+
# yaw: 1.5708

scenes/parking/demo_3.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
vehicle_state: [-1.0, -2.0, 0.0, 0.0, 0.0]
2+
3+
agents:
4+
cone1:
5+
type: cone
6+
position: [6, 9.0]
7+
nominal_velocity: 0.0
8+
target: [60.0, 8.0]
9+
behavior: loop
10+
yaw: 0
11+
12+
cone2:
13+
type: cone
14+
position: [10, 9.0]
15+
nominal_velocity: 0.0
16+
target: [60.0, 8.0]
17+
behavior: loop
18+
yaw: 0
19+
20+
cone3:
21+
type: cone
22+
position: [3, 4.0]
23+
nominal_velocity: 0.0
24+
target: [60.0, 8.0]
25+
behavior: loop
26+
yaw: 0
27+
28+
cone4:
29+
type: cone
30+
position: [7, 4.0]
31+
nominal_velocity: 0.0
32+
target: [60.0, 8.0]
33+
behavior: loop
34+
yaw: 0

scenes/parking/demo_4.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
vehicle_state: [0.0, 0.0, 0.0, 0.0, 0.0]
2+
agents:
3+
ped1:
4+
type: medium_truck
5+
position: [2.5, 8.0]
6+
nominal_velocity: 0.0
7+
target: [20.0, 8.0]
8+
behavior: loop
9+
yaw: 1.5708
10+
11+
ped2:
12+
type: medium_truck
13+
position: [7.5, 8.0]
14+
nominal_velocity: 0.0
15+
target: [15.0, 4.0]
16+
behavior: loop
17+
yaw: 1.5708
18+
19+

0 commit comments

Comments
 (0)