Skip to content

Commit

Permalink
Enabled controlling actor physics via OSC properties
Browse files Browse the repository at this point in the history
Change-Id: Iad688753bfb25f0396e0a9bc687fdcf1b14d1f53
  • Loading branch information
fabianoboril authored and fpasch committed Feb 26, 2020
1 parent 94f5b8a commit ed4be41
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- Added support for a default actor model, in case the stated model is not available
- Added support for MiscObjects (besides vehicles and pedestrians)
- Reworked traffic signal handling: The name has to start now either with "id=" or "pos=" depending on whether the position or id is used as unique identifier
- Actor physics can now be set via Object Properties (<Property name="physics" value="off" />)
### :bug: Bug Fixes
* Fixed wrong handling of OpenSCENARIO ConditionGroups, which should be handled as parallel composites, not sequences
* Fixed #443: Repetitions in OpenSCENARIO were not properly working
Expand Down
13 changes: 10 additions & 3 deletions srunner/scenarioconfigs/openscenario_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def _set_actor_information(self):
for entity in self.xml_tree.iter("Entities"):
for obj in entity.iter("Object"):
rolename = obj.attrib.get('name', 'simulation')
args = dict()
for prop in obj.iter("Property"):
key = prop.get('name')
value = prop.get('value')
args[key] = value

for vehicle in obj.iter("Vehicle"):
color = None
model = vehicle.attrib.get('name', "vehicle.*")
Expand All @@ -185,7 +191,7 @@ def _set_actor_information(self):

speed = self._get_actor_speed(rolename)
new_actor = ActorConfigurationData(
model, carla.Transform(), rolename, speed, color=color, category=category)
model, carla.Transform(), rolename, speed, color=color, category=category, args=args)
new_actor.transform = self._get_actor_transform(rolename)

if ego_vehicle:
Expand All @@ -196,7 +202,8 @@ def _set_actor_information(self):
for pedestrian in obj.iter("Pedestrian"):
model = pedestrian.attrib.get('model', "walker.*")

new_actor = ActorConfigurationData(model, carla.Transform(), rolename, category="pedestrian")
new_actor = ActorConfigurationData(
model, carla.Transform(), rolename, category="pedestrian", args=args)
new_actor.transform = self._get_actor_transform(rolename)

self.other_actors.append(new_actor)
Expand All @@ -209,7 +216,7 @@ def _set_actor_information(self):
model = "static.prop.chainbarrier"
else:
model = misc.attrib.get('name')
new_actor = ActorConfigurationData(model, carla.Transform(), rolename)
new_actor = ActorConfigurationData(model, carla.Transform(), rolename, category="misc", args=args)
new_actor.transform = self._get_actor_transform(rolename)

self.other_actors.append(new_actor)
Expand Down
3 changes: 2 additions & 1 deletion srunner/scenarioconfigs/scenario_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ActorConfigurationData(object):
"""

def __init__(self, model, transform, rolename='other', speed=0, autopilot=False,
random=False, amount=1, color=None, category="car"):
random=False, amount=1, color=None, category="car", args=None):
self.model = model
self.rolename = rolename
self.transform = transform
Expand All @@ -29,6 +29,7 @@ def __init__(self, model, transform, rolename='other', speed=0, autopilot=False,
self.amount = amount
self.color = color
self.category = category
self.args = args


class ActorConfiguration(ActorConfigurationData):
Expand Down
17 changes: 12 additions & 5 deletions srunner/scenariomanager/carla_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def handle_actor_batch(batch):
if not response.error:
actor_ids.append(response.actor_id)
else:
print("WARNING: Could not spawn an actor")
raise RuntimeError("Error: Unable to spawn actor")

carla_actors = CarlaActorPool._world.get_actors(actor_ids)
for actor in carla_actors:
Expand Down Expand Up @@ -551,7 +551,10 @@ def setup_actors(actor_list):
Function to setup a complete list of actors
"""

SpawnActor = carla.command.SpawnActor # pylint: disable=invalid-name
SpawnActor = carla.command.SpawnActor # pylint: disable=invalid-name
PhysicsCommand = carla.command.SetSimulatePhysics # pylint: disable=invalid-name
FutureActor = carla.command.FutureActor # pylint: disable=invalid-name
ApplyTransform = carla.command.ApplyTransform # pylint: disable=invalid-name
batch = []
actors = []
for actor in actor_list:
Expand All @@ -567,7 +570,13 @@ def setup_actors(actor_list):
_spawn_point.location.x = actor.transform.location.x
_spawn_point.location.y = actor.transform.location.y
_spawn_point.location.z = actor.transform.location.z + 0.2
batch.append(SpawnActor(blueprint, _spawn_point))

if 'physics' in actor.args and actor.args['physics'] == "off":
command = SpawnActor(blueprint, _spawn_point).then(
ApplyTransform(FutureActor, actor.transform)).then(PhysicsCommand(FutureActor, False))
else:
command = SpawnActor(blueprint, _spawn_point).then(PhysicsCommand(FutureActor, True))
batch.append(command)

actors = CarlaActorPool.handle_actor_batch(batch)

Expand Down Expand Up @@ -654,7 +663,6 @@ def request_new_actor(model, spawn_point, rolename='scenario', hero=False, autop
return None

CarlaActorPool._carla_actor_pool[actor.id] = actor
actor.set_simulate_physics(True)
return actor

@staticmethod
Expand All @@ -670,7 +678,6 @@ def request_new_actors(actor_list):

for actor in actors:
CarlaActorPool._carla_actor_pool[actor.id] = actor
actor.set_simulate_physics(True)
return actors

@staticmethod
Expand Down

0 comments on commit ed4be41

Please sign in to comment.