Skip to content

Commit 631485c

Browse files
authored
Merge pull request #17 from CesarLiu/dev_2_new
adapted carla-interface to conform to latest release of carla and BARK
2 parents a34a45d + 051db23 commit 631485c

22 files changed

+19260
-234
lines changed

.bazelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ test --test_output=errors --action_env="GTEST_COLOR=1"
33
# Force bazel output to use colors (good for jenkins) and print useful errors.
44
common --color=yes
55

6-
build --cxxopt='-std=c++14'
6+
build --cxxopt='-std=c++17'

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.linting.flake8Enabled": false,
3+
"python.linting.pylintEnabled": true,
4+
"python.linting.enabled": true
5+
}

README.md

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
# carla-interface
2-
2+
The carla-interface is adapted to the latest release of carla (0.9.13) and master branch of BARK.
33
## Screenshot
44

55
![example](https://github.com/bark-simulator/carla-interface/blob/master/doc/npc_example.png)
66

77
## Requirement
8-
- Ubuntu 16.04 or later (recommended)
9-
- Nvidia driver v384.11 or later
8+
This repository has the same environment with BARK. If you haven't yet used BARK, check here to [install BARK](https://github.com/bark-simulator/bark/blob/master/docs/source/installation.md)
9+
- Ubuntu 18.04 or later
10+
- Nvidia driver
1011
- OpenGL (to run with CPU only)
11-
- Bazel 0.25.0 or later (requires Java)
12+
- Bazel
1213
- virtualenv
1314

1415
## Installation
15-
[bazel install instruction](https://docs.bazel.build/versions/master/install-ubuntu.html)
16-
16+
[bazel install instruction](https://docs.bazel.build/versions/master/install-ubuntu.html)\
17+
[Install carla latest version or (0.9.13) using deb installation](https://carla.readthedocs.io/en/latest/start_quickstart/#a-debian-carla-installation)\
1718
Install dependencies
1819
```python
1920
sudo apt-get update
2021
sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev
21-
sudo apt-get install python3.5-dev
22-
sudo apt-get install python3-pip
23-
sudo pip3.5 install virtualenv
22+
sudo apt-get install python3.7 python3.7-dev python3.7-tk
23+
pip3 install virtualenv==16.7.8
2424
```
2525

2626
We then call the install script, that will install a virtual environment with all required dependencies. (Only once!)
@@ -36,19 +36,14 @@ source dev_into.sh
3636

3737
```python
3838
# Execute at project root directory
39-
# Carla will be downloaded at the first time
4039
bazel run //examples:fill_world_with_npc
4140
```
4241

4342
### Examples
44-
- fill_world_with_npc: spawn npc agents in Carla and Bark simultaneously, which controlled by Carla autopilot, the actions are mirrored into Bark
45-
- fill_world_with_bark_ego: spawn npc agents and one ego agent simultaneously, ego agent is controlled from Bark
46-
- simulate_on_Crossing8Course & : simulate on custom opendrive map
47-
48-
## TODO
49-
- Install Carla using deb installation
43+
- fill_world_with_npc: spawn npc agents in Carla and Bark simultaneously, which controlled by Carla autopilot, the states/actions are mirrored into Bark
44+
- fill_world_with_bark_ego: spawn npc agents and one ego agent simultaneously, ego agent is controlled/palnned from Bark
45+
- simulate_on_Crossing8Course : simulate on custom opendrive map
46+
- simulate_on_city_highway_straight: simulate on custom opendrive map, with limited range
5047

5148
## Known issue
52-
- Simulation crash when driving into some junction (possible bug releated to Bark)
53-
- Carla autopilot mode does not support custom opendrive map without junction (simulate_on_city_highway_straight)
54-
- Spawn agents with default spawn location on custom opendrive may lead to error
49+
- Ego agent cannot drive through some junction

WORKSPACE

+21-51
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,36 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file"
44
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
55

66
git_repository(
7-
name = "com_github_bark_simulator_bark",
7+
name = "bark_project",
8+
branch = "carla_adaptation",
89
remote = "https://github.com/bark-simulator/bark",
9-
commit = "0ab20e65aa6f328d61f7aab56e407ebdb4c7857e",
10-
)
11-
12-
git_repository(
13-
name = "com_github_nelhage_rules_boost",
14-
commit = "8a084196b14a396b6d4ff7c928ffbb6621f0d32c",
15-
remote = "https://github.com/patrickhart/rules_boost",
10+
# commit = "0ab20e65aa6f328d61f7aab56e407ebdb4c7857e",
1611
)
12+
# local_repository(
13+
# name = "bark_project",
14+
# path = "/home/xliu/fortiss_bark/bark",
15+
# )
16+
load("@bark_project//tools:deps.bzl", "bark_dependencies")
17+
bark_dependencies()
1718

1819
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
1920
boost_deps()
2021

22+
load("@pybind11_bazel//:python_configure.bzl", "python_configure")
23+
python_configure(name = "local_config_python")
2124

22-
23-
http_archive(
24-
name = "com_google_protobuf",
25-
sha256 = "cef7f1b5a7c5fba672bec2a319246e8feba471f04dcebfe362d55930ee7c1c30",
26-
strip_prefix = "protobuf-3.5.0",
27-
urls = ["https://github.com/google/protobuf/archive/v3.5.0.zip"],
28-
)
29-
30-
http_archive(
31-
name = "pybind11",
32-
strip_prefix = "pybind11-2.3.0",
33-
urls = ["https://github.com/pybind/pybind11/archive/v2.3.0.zip"],
34-
build_file = "@com_github_bark_simulator_bark//tools/pybind11:pybind.BUILD",
25+
git_repository(
26+
name = "com_github_nelhage_rules_boost",
27+
commit = "8a084196b14a396b6d4ff7c928ffbb6621f0d32c",
28+
remote = "https://github.com/patrickhart/rules_boost",
3529
)
3630

37-
# External dependency: Eigen; has no Bazel build.
38-
http_archive(
39-
name = "com_github_eigen_eigen",
40-
build_file = "@com_github_bark_simulator_bark//tools/eigen:eigen.BUILD",
41-
sha256 = "dd254beb0bafc695d0f62ae1a222ff85b52dbaa3a16f76e781dce22d0d20a4a6",
42-
strip_prefix = "eigen-eigen-5a0156e40feb",
43-
urls = [
44-
"http://bitbucket.org/eigen/eigen/get/3.3.4.tar.bz2",
45-
],
46-
)
4731

4832
http_archive(
4933
name = "com_google_ceres_solver",
5034
strip_prefix = "ceres-solver-1.14.0",
5135
sha256 = "1296330fcf1e09e6c2f926301916f64d4a4c5c0ff12d460a9bc5d4c48411518f",
52-
build_file = "@com_github_bark_simulator_bark//tools/ceres:ceres.BUILD",
36+
build_file = "@bark_project//tools/ceres:ceres.BUILD",
5337
urls = ["https://github.com/ceres-solver/ceres-solver/archive/1.14.0.tar.gz"],
5438
)
5539

@@ -63,17 +47,6 @@ http_archive(
6347
],
6448
)
6549

66-
# External dependency: Google Flags; has Bazel build already.
67-
http_archive(
68-
name = "com_github_gflags_gflags",
69-
sha256 = "6e16c8bc91b1310a44f3965e616383dbda48f83e8c1eaa2370a215057b00cabe",
70-
strip_prefix = "gflags-77592648e3f3be87d6c7123eb81cbad75f9aef5a",
71-
urls = [
72-
"https://mirror.bazel.build/github.com/gflags/gflags/archive/77592648e3f3be87d6c7123eb81cbad75f9aef5a.tar.gz",
73-
"https://github.com/gflags/gflags/archive/77592648e3f3be87d6c7123eb81cbad75f9aef5a.tar.gz",
74-
],
75-
)
76-
7750
new_local_repository(
7851
name = "python_linux",
7952
path = "./python/venv/",
@@ -87,17 +60,14 @@ cc_library(
8760
)
8861
"""
8962
)
90-
91-
http_archive(
92-
name = "carla",
93-
url= "https://carla-releases.s3.eu-west-3.amazonaws.com/Linux/CARLA_0.9.8.tar.gz",
94-
# sha256 = "ddccb35682e8387f4f413f69d1577c1cc012e0e1474e69e20d0daf7f826a673f",
95-
build_file_content = """
63+
new_local_repository(
64+
name = "carla",
65+
path = "/opt/carla-simulator",
66+
build_file_content = """
9667
filegroup(
9768
name="carla_python_lib",
9869
srcs= select({
99-
"@bazel_tools//src/conditions:linux_x86_64": glob(["PythonAPI/carla/dist/carla-*-py3.5-linux-x86_64.egg"]),
100-
"@bazel_tools//src/conditions:windows": glob(["PythonAPI/carla/dist/carla-*-py3.5-win-amd64.egg"])
70+
"@bazel_tools//src/conditions:linux_x86_64": glob(["PythonAPI/carla/dist/carla-*-py3.7-linux-x86_64.egg"])
10171
}),
10272
visibility = ["//visibility:public"],
10373
)

cosimulation_modules/client/carla_client.py

+33-14
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ def __init__(self):
2424
self.active_actors = dict()
2525

2626
def __del__(self):
27-
if self.active_actors:
28-
for actor in self.active_actors.values():
29-
if self.world.get_actor(actor.id) is not None:
30-
actor.destroy()
27+
print('destroying actors')
28+
self.client.apply_batch([carla.command.DestroyActor(x) for x in self.active_actors.values()])
29+
self.active_actors.clear()
30+
# if self.active_actors:
31+
# for actor in self.active_actors.values():
32+
# if self.world.get_actor(actor.id) is not None:
33+
# actor.destroy()
3134
if self.world is not None:
3235
self.set_synchronous_mode(False)
3336

@@ -62,18 +65,30 @@ def set_synchronous_mode(self, mode, delta_seconds=0.05):
6265

6366
def tick(self):
6467
return self.world.tick()
65-
68+
def get_current_time(self):
69+
curr_snapshot = self.world.get_snapshot()
70+
return curr_snapshot.timestamp.elapsed_seconds
6671
def get_world(self):
6772
return self.world
6873

6974
def get_blueprint_library(self):
7075
return self.bp_lib
7176

7277
def get_spawn_points(self):
73-
return self.world.get_map().get_spawn_points()
78+
ava_spawn_pts = self.world.get_map().get_spawn_points()
79+
if not ava_spawn_pts:
80+
print("Spawn Point List is empty! Generating way points")
81+
waypoint_list = self.world.get_map().generate_waypoints(10.0)
82+
# ava_spawn_pts = [wp.transform for wp in waypoint_list]
83+
for wp in waypoint_list:
84+
tmp_tf = wp.transform
85+
tmp_tf.location.z += 0.3
86+
ava_spawn_pts.append(tmp_tf)
87+
return ava_spawn_pts
7488

7589
def spawn_random_vehicle(self, num_retries=10, transform=None):
76-
blueprint = random.choice(self.bp_lib.filter('vehicle'))
90+
vehicle_bp = self.bp_lib.filter('vehicle')
91+
blueprint = random.choice(vehicle_bp)
7792

7893
id = None
7994
for _ in range(num_retries):
@@ -129,16 +144,15 @@ def set_autopilot(self, actor_id, mode=True):
129144

130145
def get_vehicle_state(self, id):
131146
if id in self.active_actors:
132-
snapshot = self.world.get_snapshot()
133147
vehicle = self.active_actors[id]
134-
135148
t = vehicle.get_transform()
136149
v = vehicle.get_velocity()
137150
# c = vehicle.get_control()
138151
# a = vehicle.get_acceleration()
139152
# av = vehicle.get_angular_velocity()
153+
snapshot = self.world.get_snapshot()
140154
return np.array([snapshot.timestamp.elapsed_seconds, t.location.x, -t.location.y,
141-
math.radians(-t.rotation.yaw), math.sqrt(v.x**2 + v.y**2 + v.z**2)])
155+
math.radians(-t.rotation.yaw), math.sqrt(v.x**2 + v.y**2 + v.z**2)])
142156
else:
143157
logging.error("Actor {} not found".format(id))
144158
return None
@@ -148,10 +162,15 @@ def get_vehicles_state(self, carla_2_bark_idx):
148162
# Should be called in synchronous mode
149163

150164
actor_state_map = dict()
151-
for id, vehicle in self.active_actors.items():
152-
if vehicle.type_id.split(".")[0] == "vehicle":
153-
actor_state_map[carla_2_bark_idx[id]
154-
] = self.get_vehicle_state(id)
165+
for id in self.active_actors.copy():
166+
if self.active_actors[id].is_alive:
167+
if self.active_actors[id].type_id.split(".")[0] == "vehicle":
168+
actor_state_map[carla_2_bark_idx[id]
169+
] = self.get_vehicle_state(id)
170+
else:
171+
del self.active_actors[id]
172+
logging.error("Actor {} is already destroyed!".format(id))
173+
155174

156175
return actor_state_map
157176

cosimulation_modules/client/controller.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class Controller:
2121
def __init__(self, client):
2222
self.client = client
2323

24-
def control(self, vehicle, last_location, location, velocity, steer_dir):
24+
def control(self, vehicle, location, velocity, steer_dir):
2525
# TODO: use raw control instead of setting the state directly
2626
transform = carla.Transform(carla.Location(x=float(location[0]), y=-float(location[1])),
2727
carla.Rotation(yaw=math.degrees(-steer_dir)))
2828
vehicle.set_transform(transform)
2929
# velocity=10
3030

31-
v_x, v_y = rotate_2d_vector(0, 1, -steer_dir)
31+
v_x, v_y = rotate_2d_vector(0, 1, steer_dir)
3232
v_x *= velocity
3333
v_y *= velocity
3434
velocity_vec = carla.Vector3D(x=v_x, y=v_y, z=0)
35-
vehicle.set_velocity(velocity_vec)
35+
vehicle.set_target_velocity(velocity_vec)

0 commit comments

Comments
 (0)