Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
glopezdiest committed May 3, 2024
2 parents 00a3214 + b1ce704 commit 2416399
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/static_code_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
Expand All @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Static Code Analysis
name: Unit Tests

on:
push:
Expand All @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
Expand Down
4 changes: 4 additions & 0 deletions Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* [CARLA ScenarioRunner 0.9.5](#carla-scenariorunner-095)
* [CARLA ScenarioRunner 0.9.2](#carla-scenariorunner-092)

## Upcoming
* Improvements to the CarlaDataProvider:
- Added `spawn_actor` for a blueprint based actor creation similar to `World.spawn_actor`

## CARLA ScenarioRunner 0.9.15
### :rocket: New Features
* Add waypoint reached threshold so that the precision of the actor reaching to waypoints can be adjusted based on object types.
Expand Down
7 changes: 4 additions & 3 deletions scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class ScenarioRunner(object):
# Tunable parameters
client_timeout = 10.0 # in seconds
wait_for_world = 20.0 # in seconds
frame_rate = 20.0 # in Hz

# CARLA world and scenario handlers
world = None
Expand Down Expand Up @@ -352,7 +351,7 @@ def _load_and_wait_for_world(self, town, ego_vehicles=None):
if self._args.sync:
settings = self.world.get_settings()
settings.synchronous_mode = True
settings.fixed_delta_seconds = 1.0 / self.frame_rate
settings.fixed_delta_seconds = 1.0 / self._args.frameRate
self.world.apply_settings(settings)

CarlaDataProvider.set_client(self.client)
Expand Down Expand Up @@ -582,6 +581,8 @@ def main():
parser.add_argument('--sync', action='store_true',
help='Forces the simulation to run synchronously')
parser.add_argument('--list', action="store_true", help='List all supported scenarios and exit')
parser.add_argument('--frameRate', default='20', type=float,
help='Frame rate (Hz) to use in \'sync\' mode (default: 20)')

parser.add_argument(
'--scenario', help='Name of the scenario to be executed. Use the preposition \'group:\' to run all scenarios of one class, e.g. ControlLoss or FollowLeadingVehicle')
Expand Down Expand Up @@ -662,4 +663,4 @@ def main():


if __name__ == "__main__":
sys.exit(main())
sys.exit(main())
4 changes: 2 additions & 2 deletions srunner/metrics/tools/metrics_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def parse_wheels_control(info):
max_brake_torque=float(info[11]),
max_handbrake_torque=float(info[13]),
position=carla.Vector3D(
x=float(info[17][1:-1]) / 100,
y=float(info[17][:-1]) / 100,
x=float(info[15][1:-1]) / 100,
y=float(info[16][:-1]) / 100,
z=float(info[17][:-1]) / 100)
)
return wheels_control
Expand Down
61 changes: 58 additions & 3 deletions srunner/scenariomanager/carla_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,10 @@ def find_weather_presets():
"""
Get weather presets from CARLA
"""
def name(string):
return ' '.join(m.group(0) for m in rgx.finditer(string))

rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)')
name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x))
presets = [x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x)]
return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets]

Expand Down Expand Up @@ -679,6 +681,59 @@ def handle_actor_batch(batch, tick=True):
actors = list(CarlaDataProvider._world.get_actors(actor_ids))
return actors

@staticmethod
def spawn_actor(bp, spawn_point, must_spawn=False, track_physics=None, attach_to=None, attachment_type=carla.AttachmentType.Rigid):
# type: (carla.ActorBlueprint, carla.Waypoint | carla.Transform, bool, bool | None, carla.Actor | None, carla.AttachmentType) -> carla.Actor | None
"""
The method will spawn and return an actor.
The actor will need an available blueprint to be created.
It can also be attached to a parent with a certain attachment type.
Args:
bp (carla.ActorBlueprint): The blueprint of the actor to spawn.
spawn_point (carla.Transform): The spawn point of the actor.
must_spawn (bool, optional):
If True, the actor will be spawned or an exception will be raised.
If False, the function returns None if the actor could not be spawned.
Defaults to False.
track_physics (bool | None, optional):
If True, `get_location`, `get_transform` and `get_velocity`
can be used for this actor.
If None, the actor will be tracked if it is a Vehicle or Walker.
Defaults to None.
attach_to (carla.Actor | None, optional):
The parent object that the spawned actor will follow around.
Defaults to None.
attachment_type (carla.AttachmentType, optional):
Determines how fixed and rigorous should be the changes in position
according to its parent object.
Defaults to carla.AttachmentType.Rigid.
Returns:
carla.Actor | None: The spawned actor if successful, None otherwise.
Raises:
RuntimeError: if `must_spawn` is True and the actor could not be spawned.
"""
if isinstance(spawn_point, carla.Waypoint):
spawn_point = spawn_point.transform
world = CarlaDataProvider.get_world()
if must_spawn:
actor = world.spawn_actor(bp, spawn_point, attach_to, attachment_type)
else:
actor = world.try_spawn_actor(bp, spawn_point, attach_to, attachment_type)
if actor is None:
return None
# Register for cleanup
CarlaDataProvider._carla_actor_pool[actor.id] = actor
if track_physics is None:
# Decide
track_physics = isinstance(actor, (carla.Vehicle, carla.Walker))
if track_physics:
# Register for physics
CarlaDataProvider.register_actor(actor, spawn_point)
return actor

@staticmethod
def request_new_actor(model, spawn_point, rolename='scenario', autopilot=False,
random_location=False, color=None, actor_category="car",
Expand Down Expand Up @@ -860,11 +915,11 @@ def request_new_batch_actors(model, amount, spawn_points, autopilot=False,
SetAutopilot(FutureActor, autopilot, CarlaDataProvider._traffic_manager_port)))

actors = CarlaDataProvider.handle_actor_batch(batch, tick)
for actor in actors:
for actor, command in zip(actors, batch):
if actor is None:
continue
CarlaDataProvider._carla_actor_pool[actor.id] = actor
CarlaDataProvider.register_actor(actor, spawn_point)
CarlaDataProvider.register_actor(actor, command.transform)

return actors

Expand Down
10 changes: 5 additions & 5 deletions srunner/scenariomanager/scenarioatomics/atomic_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,9 @@ def initialise(self):
# At the moment everything besides "shortest" will use the CARLA GlobalPlanner
grp = CarlaDataProvider.get_global_route_planner()
route = []
for i, _ in enumerate(carla_route_elements):
if carla_route_elements[i][1] == "shortest":
route.append(carla_route_elements[i][0])
for i, element in enumerate(carla_route_elements):
if element[1] == "shortest":
route.append(element[0])
else:
if i == 0:
mmap = CarlaDataProvider.get_map()
Expand All @@ -812,12 +812,12 @@ def initialise(self):
waypoint = ego_next_wp.transform.location
else:
waypoint = carla_route_elements[i - 1][0].location
waypoint_next = carla_route_elements[i][0].location
waypoint_next = element[0].location
try:
interpolated_trace = grp.trace_route(waypoint, waypoint_next)
except networkx.NetworkXNoPath:
print("WARNING: No route from {} to {} - Using direct path instead".format(waypoint, waypoint_next))
route.append(carla_route_elements[i][0])
route.append(element[0])
continue
for wp_tuple in interpolated_trace:
# The router sometimes produces points that go backward, or are almost identical
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def update(self):

velocity = CarlaDataProvider.get_velocity(self._actor)

if velocity > EPSILON:
if velocity > 0.1:
self._start_time = GameTime.get_time()

if GameTime.get_time() - self._start_time > self._duration:
Expand Down
6 changes: 3 additions & 3 deletions srunner/scenarios/open_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ def _create_behavior(self):
for actor in sequence.iter("Actors"):
for entity in actor.iter("EntityRef"):
entity_name = entity.attrib.get('entityRef', None)
for k, _ in enumerate(joint_actor_list):
if (joint_actor_list[k] and
entity_name == joint_actor_list[k].attributes['role_name']):
for k, actor in enumerate(joint_actor_list):
if (actor and
entity_name == actor.attributes['role_name']):
actor_ids.append(k)
break

Expand Down
5 changes: 5 additions & 0 deletions srunner/tests/carla_mocks/carla.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,8 @@ def __init__(self, id):
reponse_list.append(Response(new_actor.id))

return reponse_list

class AttachmentType:
Rigid = 0
SpringArm = 1
SpringArmGhost = 2

0 comments on commit 2416399

Please sign in to comment.