forked from ucla-mobility/OpenCDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ucla-mobility#41 from ucla-mobility/feature/code_m…
…inor_optimization Feature/code minor optimization
- Loading branch information
Showing
9 changed files
with
49 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
# Author: Runsheng Xu <[email protected]> | ||
# License: MIT | ||
|
||
import weakref | ||
from collections import deque | ||
|
||
import carla | ||
|
@@ -24,7 +25,7 @@ def __init__(self, vehicle, vehicle_manager, v2x_manager, behavior_yaml, platoon | |
""" | ||
Construct class | ||
:param vehicle: carla actor todo:remove this later | ||
:param vehicle_manager: vehicle manager of this agent. todo: try to avoid such circle reference in future | ||
:param vehicle_manager: vehicle manager of this agent. | ||
:param v2x_manager: communication manager | ||
:param behavior_yaml: configure yaml file for normal behavior agent | ||
:param platoon_yaml: configure yaml file for platoon behavior agent | ||
|
@@ -34,9 +35,9 @@ def __init__(self, vehicle, vehicle_manager, v2x_manager, behavior_yaml, platoon | |
|
||
super(PlatooningBehaviorAgent, self).__init__(vehicle, carla_map, behavior_yaml) | ||
|
||
self.vehicle_manager = vehicle_manager | ||
self.vehicle_manager = weakref.ref(vehicle_manager)() | ||
# communication manager | ||
self.v2x_manager = v2x_manager | ||
self.v2x_manager = weakref.ref(v2x_manager)() | ||
|
||
# used for gap keeping | ||
self.inter_gap = platoon_yaml['inter_gap'] | ||
|
@@ -59,7 +60,8 @@ def __init__(self, vehicle, vehicle_manager, v2x_manager, behavior_yaml, platoon | |
|
||
def run_step(self, target_speed=None, collision_detector_enabled=True, lane_change_allowed=True): | ||
""" | ||
Run a single step for navigation under platooning agent. | ||
Run a single step for navigation under platooning agent. Finite state machine is used to switch between | ||
different platooning states. | ||
Args: | ||
target_speed (float): Target speed in km/h | ||
collision_detector_enabled (bool): Whether collision detection enabled. | ||
|
@@ -206,7 +208,7 @@ def platooning_following_manager(self, inter_gap): | |
else len(frontal_trajectory) | ||
# todo: current not working well on curve | ||
for i in range(tracked_length): | ||
delta_t = 0.25 # todo: this is harded coded | ||
delta_t = self.get_local_planner().dt | ||
# print('previous x :%f, delta t: %f' % (frontal_trajectory[i][0].location.x, delta_t)) | ||
if i == 0: | ||
pos_x = (frontal_trajectory[i][0].location.x + inter_gap / delta_t * ego_loc_x) / \ | ||
|
@@ -304,7 +306,6 @@ def run_step_maintaining(self): | |
|
||
def run_step_cut_in_move2point(self): | ||
""" | ||
TODO: More than 2 lanes not working | ||
The vehicle is trying to get to the move in point | ||
:return: target_speed, target_waypoint, next FSM state | ||
""" | ||
|
@@ -347,7 +348,7 @@ def run_step_cut_in_move2point(self): | |
return (*super().run_step(2.0 * get_speed(frontal_vehicle)), FSM.MOVE_TO_POINT) | ||
|
||
# if the ego vehicle is too close or exceed the frontal vehicle | ||
if distance < self._ego_speed / 3.6 * self.inter_gap / 1.5 or angle >= 80: | ||
if distance < self._ego_speed / 3.6 * self.inter_gap / 1.5 or angle >= 70: | ||
print('too close, step back!') | ||
return (*super().run_step(0.9 * get_speed(frontal_vehicle)), FSM.MOVE_TO_POINT) | ||
|
||
|
@@ -474,7 +475,7 @@ def dist(v): | |
return v.get_location().distance(ego_vehicle_loc) | ||
vehicle_blocking_status = False | ||
for vehicle in self.obstacle_vehicles: | ||
vehicle_blocking_status = vehicle_blocking_status or self._collision_check.is_in_range(self.vehicle, | ||
vehicle_blocking_status = vehicle_blocking_status or self._collision_check.is_in_range(self._ego_pos, | ||
frontal_vehicle, | ||
vehicle, | ||
self._map) | ||
|
@@ -547,7 +548,7 @@ def dist(v): | |
|
||
vehicle_blocking_status = False | ||
for vehicle in self.obstacle_vehicles: | ||
vehicle_blocking_status = vehicle_blocking_status or self._collision_check.is_in_range(self.vehicle, | ||
vehicle_blocking_status = vehicle_blocking_status or self._collision_check.is_in_range(self._ego_pos, | ||
rear_vehicle, | ||
vehicle, | ||
self._map) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters