Skip to content

Commit 36f934e

Browse files
committed
Add traffic manager option and Improve README explanation
1 parent 1f726f1 commit 36f934e

File tree

4 files changed

+129
-15
lines changed

4 files changed

+129
-15
lines changed

simulator/carla_autoware/README.md

+81-8
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ This ros package enables communication between Autoware and CARLA for autonomous
2424

2525
1. Download maps (y-axis inverted version) to arbitaly location
2626
2. Change names and create the map folder (example: Town01) inside `autoware_map`. (`point_cloud/Town01.pcd` -> `autoware_map/Town01/pointcloud_map.pcd`, `vector_maps/lanelet2/Town01.osm`-> `autoware_map/Town01/lanelet2_map.osm`)
27-
3. Create `map_projector_info.yaml` and add `projector_type: local` on the first line.
27+
3. Create `map_projector_info.yaml` on the folder and add `projector_type: local` on the first line.
2828

2929
### Build
3030

3131
```bash
32-
cd colcon_ws
33-
colcon build --symlink-install
32+
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release
3433
```
3534

3635
### Run
@@ -53,15 +52,89 @@ colcon build --symlink-install
5352
5. Wait for planning
5453
6. Engage
5554

56-
### Tips
55+
## Inner-workings / Algorithms
56+
57+
The main class responsible for setting up the CARLA world and the ego vehicle is InitializeInterface. The configuration parameters are fetched using the carla_interface.
58+
59+
### Configureable Parameters for World Loading
60+
61+
All the key parameters can be configured in `carla_autoware.launch.xml`.
62+
63+
| Name | Type | Default Value | Description |
64+
| ------------------------- | ------ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
65+
| `host` | string | "localhost" | Hostname for the CARLA server |
66+
| `port` | int | "2000" | Port number for the CARLA server |
67+
| `timeout` | int | 20 | Timeout for the CARLA client |
68+
| `ego_vehicle_role_name` | string | "ego_vehicle" | Role name for the ego vehicle |
69+
| `vehicle_type` | string | "vehicle.toyota.prius" | Blueprint ID of the vehicle to spawn. The Blueprint ID of vehicles can be found in [CARLA Blueprint ID](https://carla.readthedocs.io/en/latest/catalogue_vehicles/) |
70+
| `spawn_point` | string | None | Coordinates for spawning the ego vehicle (None is random). Format = [x, y, z, roll, pitch, yaw] |
71+
| `carla_map` | string | "Town01" | Name of the map to load in CARLA |
72+
| `sync_mode` | bool | True | Boolean flag to set synchronous mode in CARLA |
73+
| `fixed_delta_seconds` | double | 0.05 | Time step for the simulation (related to client FPS) |
74+
| `objects_definition_file` | string | "$(find-pkg-share carla_autoware)/objects.json" | Sensor parameters file that are used for spawning sensor in CARLA |
75+
| `use_traffic_manager` | bool | True | Boolean flag to set traffic manager in CARLA |
76+
77+
### Configurable Parameters for Sensors
78+
79+
Below parameters can be configured in `carla_ros.py`.
80+
81+
| Name | Type | Default Value | Description |
82+
| ------------------------- | ---- | -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
83+
| `self.sensor_frequencies` | dict | {"top": 11, "left": 11, "right": 11, "camera": 11, "imu": 50, "status": 50, "pose": 2} | (line 67) Calculates the time interval since the last publication and checks if this interval meets the minimum required to not exceed the desired frequency. It will only affect ROS publishing frequency not CARLA sensor tick. |
84+
| `self.max_steering_angle` | int | 45 | (Line 74) Maximum steering angle of a vehicle in degrees, used as parameter to compute the mapping from normalized steering input values. |
85+
86+
- CARLA sensor parameters can be configured in `config/objects.json`.
87+
- For more details regarding the parameters that can be modified in CARLA are explained in [Carla Ref Sensor](https://carla.readthedocs.io/en/latest/ref_sensors/).
88+
89+
### World Loading
90+
91+
The `carla_ros.py` sets up the CARLA world:
92+
93+
1. **Client Connection**:
94+
95+
```python
96+
client = carla.Client(self.local_host, self.port)
97+
client.set_timeout(self.timeout)
98+
```
99+
100+
2. **Load the Map**:
101+
102+
Map loaded in CALRA world with map according to `carla_map` parameter.
103+
104+
```python
105+
client.load_world(self.map_name)
106+
self.world = client.get_world()
107+
```
108+
109+
3. **Spawn Ego Vehicle**:
110+
111+
Vehicle are spawn according to `vehicle_type`, `spawn_point`, and `agent_role_name` parameter.
112+
113+
```python
114+
spawn_point = carla.Transform()
115+
point_items = self.spawn_point.split(",")
116+
if len(point_items) == 6:
117+
spawn_point.location.x = float(point_items[0])
118+
spawn_point.location.y = float(point_items[1])
119+
spawn_point.location.z = float(point_items[2]) + 2
120+
spawn_point.rotation.roll = float(point_items[3])
121+
spawn_point.rotation.pitch = float(point_items[4])
122+
spawn_point.rotation.yaw = float(point_items[5])
123+
CarlaDataProvider.request_new_actor(self.vehicle_type, spawn_point, self.agent_role_name)
124+
```
125+
126+
## Tips
57127

58-
- If you want to edit the sensors configuration used in CARLA, edit `objects.json` located in `carla_autoware/config`. Make sure the sensor configuration is the same as the `sensor_kit` description used in Autoware.
59128
- Misalignment might occurs during initialization, pressing `init by gnss` button should fix it.
60-
- Sensor frequency can be changed on `carla_ros.py` Line 67.
61-
- Changing the `fixed_delta_seconds` can increase the simulation tick (clock), some sensors params in `objects.json` need to be adjusted when it is changed (example: LIDAR rotation frequency have to match the FPS).
129+
- Changing the `fixed_delta_seconds` can increase the simulation tick (default 0.05 s), some sensors params in `objects.json` need to be adjusted when it is changed (example: LIDAR rotation frequency have to match the FPS).
62130

63-
### Known Issues and Future Works
131+
## Known Issues and Future Works
64132

65133
- Testing on procedural map (Adv Digital Twin).
134+
- Currently unable to test it due to failing in the creation of the Adv digital twin map.
66135
- Automatic sensor configuration of the CARLA sensors from the Autoware sensor kit.
136+
- Sensor currently not automatically configurated to have the same location as the Autoware Sensor kit. The current work around is to create a new frame of each sensors with (0, 0, 0, 0, 0, 0) coordinate relative to base_link and attach each sensor on the new frame (`carla_autoware.launch.xml` Line 28). This work around is very limited and restrictive, as when the sensor_kit is changed the sensor location will be wrongly attached.
67137
- Traffic light recognition.
138+
- Currently the HDmap of CARLA did not have information regarding the traffic light which is necessary for Autoware to conduct traffic light recognition.
139+
- Ego Vehicle Control.
140+
- Currently during sharp turning the ego-vehicle have large lateral error.

simulator/carla_autoware/launch/carla_autoware.launch.xml

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
<arg name="timeout" default="20"/>
55
<arg name="ego_vehicle_role_name" default="ego_vehicle"/>
66
<arg name="vehicle_type" default="vehicle.toyota.prius"/>
7-
<arg name="spawn_point" default="None"/>
7+
<arg name="spawn_point" default="None" description="location of ego vehicle spawn (default is random), example = [0.2 , 4.1, 0.4, 0., 0., 0.]"/>
88
<arg name="carla_map" default="Town01"/>
9-
<arg name="passive" default="False"/>
109
<arg name="sync_mode" default="True"/>
1110
<arg name="fixed_delta_seconds" default="0.05" description="Timestep for CARLA, FPS=1/value"/>
12-
<arg name="role_name" default="ego_vehicle"/>
13-
<arg name="spawn_point" default="None" description="location of ego vehicle spawn (default is random), example = [0.2 , 4.1, 0.4, 0., 0., 0.]"/>
1411
<arg name="objects_definition_file" default="$(find-pkg-share carla_autoware)/objects.json"/>
12+
<arg name="use_traffic_manager" default="False"/>
1513

1614
<!-- CARLA Interface -->
1715
<node pkg="carla_autoware" exec="carla_autoware" name="carla_autoware" output="screen">
@@ -25,6 +23,7 @@
2523
<param name="spawn_point" value="$(var spawn_point)"/>
2624
<param name="vehicle_type" value="$(var vehicle_type)"/>
2725
<param name="objects_definition_file" value="$(var objects_definition_file)"/>
26+
<param name="use_traffic_manager" value="$(var use_traffic_manager)"/>
2827
</node>
2928

3029
<!-- Awsim configuration frame to CARLA frame -->

simulator/carla_autoware/src/carla_autoware/carla_autoware.py

+44-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.sr/bin/env python
1414

15+
import random
1516
import signal
1617
import time
1718

@@ -66,15 +67,16 @@ def __init__(self):
6667
self.timeout = self.param_["timeout"]
6768
self.sync_mode = self.param_["sync_mode"]
6869
self.fixed_delta_seconds = self.param_["fixed_delta_seconds"]
69-
self.map_name = self.param_["carla_map"]
70+
self.carla_map = self.param_["carla_map"]
7071
self.agent_role_name = self.param_["ego_vehicle_role_name"]
7172
self.vehicle_type = self.param_["vehicle_type"]
7273
self.spawn_point = self.param_["spawn_point"]
74+
self.use_traffic_manager = self.param_["use_traffic_manager"]
7375

7476
def load_world(self):
7577
client = carla.Client(self.local_host, self.port)
7678
client.set_timeout(self.timeout)
77-
client.load_world(self.map_name)
79+
client.load_world(self.carla_map)
7880
self.world = client.get_world()
7981
if self.world is not None:
8082
settings = self.world.get_settings()
@@ -90,7 +92,9 @@ def load_world(self):
9092
if len(point_items) == 6:
9193
spawn_point.location.x = float(point_items[0])
9294
spawn_point.location.y = float(point_items[1])
93-
spawn_point.location.z = float(point_items[2]) + 2
95+
spawn_point.location.z = (
96+
float(point_items[2]) + 2
97+
) # +2 is used so the car did not stuck on the road when spawned.
9498
spawn_point.rotation.roll = float(point_items[3])
9599
spawn_point.rotation.pitch = float(point_items[4])
96100
spawn_point.rotation.yaw = float(point_items[5])
@@ -103,6 +107,43 @@ def load_world(self):
103107
self.sensor_wrapper = SensorWrapper(self.interface)
104108
self.ego_vehicle = CarlaDataProvider.get_actor_by_name(self.agent_role_name)
105109
self.sensor_wrapper.setup_sensors(self.ego_vehicle, False)
110+
##########################################################################################################################################################
111+
# TRAFFIC MANAGER
112+
##########################################################################################################################################################
113+
if self.use_traffic_manager:
114+
traffic_manager = client.get_trafficmanager()
115+
traffic_manager.set_synchronous_mode(True)
116+
traffic_manager.set_random_device_seed(0)
117+
random.seed(0)
118+
spawn_points_tm = self.world.get_map().get_spawn_points()
119+
for i, spawn_point in enumerate(spawn_points_tm):
120+
self.world.debug.draw_string(spawn_point.location, str(i), life_time=10)
121+
models = [
122+
"dodge",
123+
"audi",
124+
"model3",
125+
"mini",
126+
"mustang",
127+
"lincoln",
128+
"prius",
129+
"nissan",
130+
"crown",
131+
"impala",
132+
]
133+
blueprints = []
134+
for vehicle in self.world.get_blueprint_library().filter("*vehicle*"):
135+
if any(model in vehicle.id for model in models):
136+
blueprints.append(vehicle)
137+
max_vehicles = 30
138+
max_vehicles = min([max_vehicles, len(spawn_points_tm)])
139+
vehicles = []
140+
for i, spawn_point in enumerate(random.sample(spawn_points_tm, max_vehicles)):
141+
temp = self.world.try_spawn_actor(random.choice(blueprints), spawn_point)
142+
if temp is not None:
143+
vehicles.append(temp)
144+
145+
for vehicle in vehicles:
146+
vehicle.set_autopilot(True)
106147

107148
else:
108149
print("Carla Interface Couldn't find the world, Carla is not Running")

simulator/carla_autoware/src/carla_autoware/carla_ros.py

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def setup(self):
9393
"spawn_point": rclpy.Parameter.Type.STRING,
9494
"vehicle_type": rclpy.Parameter.Type.STRING,
9595
"objects_definition_file": rclpy.Parameter.Type.STRING,
96+
"use_traffic_manager": rclpy.Parameter.Type.BOOL,
9697
}
9798
self.param_values = {}
9899
for param_name, param_type in self.parameters.items():

0 commit comments

Comments
 (0)