-
Notifications
You must be signed in to change notification settings - Fork 50
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 #644 from Qi-Zha0/three_tasks
Three tasks follow_lane, follow_lane_traffic, follow_route
- Loading branch information
Showing
18 changed files
with
881 additions
and
109 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
bag_analysis/ | ||
core | ||
tmp_* | ||
carla_birdeye_view/ | ||
|
||
|
||
### Python ### | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import numpy as np | ||
import carla | ||
|
||
class HighLevelCommandLoader: | ||
def __init__(self, vehicle, map, route=None): | ||
self.vehicle = vehicle | ||
self.map = map | ||
self.prev_hlc = 0 | ||
self.route = route | ||
|
||
def _get_junction(self): | ||
"""determine whether vehicle is at junction""" | ||
junction = None | ||
vehicle_location = self.vehicle.get_transform().location | ||
vehicle_waypoint = self.map.get_waypoint(vehicle_location) | ||
|
||
# check whether vehicle is at junction | ||
for j in range(1, 11): | ||
next_waypoint = vehicle_waypoint.next(j * 1.0)[0] | ||
if next_waypoint.is_junction: | ||
junction = next_waypoint.get_junction() | ||
break | ||
if vehicle_waypoint.is_junction: | ||
junction = vehicle_waypoint.get_junction() | ||
return junction | ||
|
||
def _command_to_int(self, command): | ||
commands = { | ||
'Left': 1, | ||
'Right': 2, | ||
'Straight': 3 | ||
} | ||
return commands[command] | ||
|
||
def get_random_hlc(self): | ||
"""select a random turn at junction""" | ||
junction = self._get_junction() | ||
vehicle_location = self.vehicle.get_transform().location | ||
vehicle_waypoint = self.map.get_waypoint(vehicle_location) | ||
|
||
# randomly select a turning direction | ||
if junction is not None: | ||
if self.prev_hlc == 0: | ||
valid_turns = [] | ||
waypoints = junction.get_waypoints(carla.LaneType.Driving) | ||
for next_wp, _ in waypoints: | ||
yaw_diff = next_wp.transform.rotation.yaw - vehicle_waypoint.transform.rotation.yaw | ||
yaw_diff = (yaw_diff + 180) % 360 - 180 # convert to [-180, 180] | ||
if -15 < yaw_diff < 15: | ||
valid_turns.append(3) # Go Straight | ||
elif 15 < yaw_diff < 165: | ||
valid_turns.append(1) # Turn Left | ||
elif -165 < yaw_diff < -15: | ||
valid_turns.append(2) # Turn Right | ||
hlc = np.random.choice(valid_turns) | ||
else: | ||
hlc = self.prev_hlc | ||
else: | ||
hlc = 0 | ||
|
||
self.prev_hlc = hlc | ||
|
||
return hlc | ||
|
||
|
||
def get_next_hlc(self): | ||
if self.route is not None and len(self.route) > 0: | ||
return self.load_next_hlc() | ||
return self.get_random_hlc() | ||
|
||
def load_next_hlc(self): | ||
"""load the next high level command from pre-defined route""" | ||
if self.prev_hlc is None: | ||
return None | ||
|
||
junction = self._get_junction() | ||
|
||
if junction is not None: | ||
if self.prev_hlc == 0: | ||
if len(self.route) == 0: | ||
hlc = None | ||
hlc = self._command_to_int(self.route.pop(0)) | ||
else: | ||
hlc = self.prev_hlc | ||
else: | ||
hlc = 0 | ||
|
||
self.prev_hlc = hlc | ||
|
||
return hlc | ||
|
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
56 changes: 56 additions & 0 deletions
56
behavior_metrics/configs/CARLA/CARLA_launch_files/test_suite_template.launch
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!-- --> | ||
<launch> | ||
<!-- CARLA connection --> | ||
<arg name='host' default='localhost'/> | ||
<arg name='port' default='2000'/> | ||
<arg name='timeout' default='10'/> | ||
|
||
<!-- Map to load on startup (either a predefined CARLA town (e.g. 'Town01'), or a OpenDRIVE map file) --> | ||
<arg name="town"/> | ||
|
||
<!-- Ego vehicle spawn point --> | ||
<arg name="spawn_point"/> | ||
|
||
<!-- Enable/disable passive mode --> | ||
<arg name='passive' default=''/> | ||
|
||
<!-- Synchronous mode--> | ||
<arg name='synchronous_mode' default='True'/> | ||
<arg name='synchronous_mode_wait_for_vehicle_control_command' default='False'/> | ||
<arg name='fixed_delta_seconds' default='0.05'/> | ||
|
||
<!-- the role names of vehicles that are controllable from within ROS--> | ||
<arg name='ego_vehicles' default='["ego_vehicle"]'/> | ||
|
||
<!-- launch carla ros bridge node --> | ||
<node pkg="carla_ros_bridge" name="carla_ros_bridge" type="bridge.py" output="screen" required="true"> | ||
<param name="host" value="$(arg host)" unless="$(eval host == '')"/> | ||
<param name="port" value="$(arg port)" unless="$(eval port == '')"/> | ||
<param name="timeout" value="$(arg timeout)" unless="$(eval timeout == '')"/> | ||
<param name="passive" value="$(arg passive)"/> | ||
<param name="synchronous_mode" value="$(arg synchronous_mode)"/> | ||
<param name="synchronous_mode_wait_for_vehicle_control_command" value="$(arg synchronous_mode_wait_for_vehicle_control_command)"/> | ||
<param name="fixed_delta_seconds" value="$(arg fixed_delta_seconds)"/> | ||
<param name="register_all_sensors" value="true"/> | ||
<param name="town" value="$(arg town)"/> | ||
<param name="ego_vehicle_role_name" value="$(arg ego_vehicles)"/> | ||
</node> | ||
|
||
<!-- the object json file that configures objects to spawn --> | ||
<arg name="objects_definition_file" default='$(env OBJECT_PATH)/main_car_custom_camera.json'/> | ||
|
||
<!-- Ego Vehicle --> | ||
<arg name='ego_vehicle_role_name' default='ego_vehicle'/> | ||
|
||
<!-- spawn the objects --> | ||
<node pkg="carla_spawn_objects" type="carla_spawn_objects.py" name="$(anon carla_spawn_objects)" output="screen"> | ||
<param name="objects_definition_file" value="$(arg objects_definition_file)"/> | ||
<param name="spawn_point_$(arg ego_vehicle_role_name)" value="$(arg spawn_point)"/> | ||
<param name="spawn_sensors_only" value="false"/> | ||
</node> | ||
|
||
<include file="$(find carla_manual_control)/launch/carla_manual_control.launch"> | ||
<arg name='role_name' value='$(arg ego_vehicle_role_name)'/> | ||
</include> | ||
|
||
</launch> |
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
Oops, something went wrong.