Added the instances
This commit is contained in:
parent
843ac4b38e
commit
49223437b2
|
@ -1,5 +1,6 @@
|
||||||
## Latest
|
## Latest
|
||||||
|
|
||||||
|
* Python agents now accept a carla.Map and GlobalRoutePlanner instances as inputs, avoiding the need to recompute them.
|
||||||
* Fix a bug at `Map.get_topology()`, causing lanes with no successors to not be part of it.
|
* Fix a bug at `Map.get_topology()`, causing lanes with no successors to not be part of it.
|
||||||
* Added new ConstantVelocityAgent
|
* Added new ConstantVelocityAgent
|
||||||
* Added new parameter to the TrafficManager, `set_desired_speed`, to set a vehicle's speed.
|
* Added new parameter to the TrafficManager, `set_desired_speed`, to set a vehicle's speed.
|
||||||
|
|
|
@ -26,7 +26,7 @@ class BasicAgent(object):
|
||||||
as well as to change its parameters in case a different driving mode is desired.
|
as well as to change its parameters in case a different driving mode is desired.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, vehicle, target_speed=20, opt_dict={}):
|
def __init__(self, vehicle, target_speed=20, opt_dict={}, map_inst=None, grp_inst=None):
|
||||||
"""
|
"""
|
||||||
Initialization the agent paramters, the local and the global planner.
|
Initialization the agent paramters, the local and the global planner.
|
||||||
|
|
||||||
|
@ -34,9 +34,19 @@ class BasicAgent(object):
|
||||||
:param target_speed: speed (in Km/h) at which the vehicle will move
|
:param target_speed: speed (in Km/h) at which the vehicle will move
|
||||||
:param opt_dict: dictionary in case some of its parameters want to be changed.
|
:param opt_dict: dictionary in case some of its parameters want to be changed.
|
||||||
This also applies to parameters related to the LocalPlanner.
|
This also applies to parameters related to the LocalPlanner.
|
||||||
|
:param map_inst: carla.Map instance to avoid the expensive call of getting it.
|
||||||
|
:param grp_inst: GlobalRoutePlanner instance to avoid the expensive call of getting it.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._vehicle = vehicle
|
self._vehicle = vehicle
|
||||||
self._world = self._vehicle.get_world()
|
self._world = self._vehicle.get_world()
|
||||||
|
if map_inst:
|
||||||
|
if isinstance(map_inst, carla.Map):
|
||||||
|
self._map = map_inst
|
||||||
|
else:
|
||||||
|
print("Warning: Ignoring the given map as it is not a 'carla.Map'")
|
||||||
|
self._map = self._world.get_map()
|
||||||
|
else:
|
||||||
self._map = self._world.get_map()
|
self._map = self._world.get_map()
|
||||||
self._last_traffic_light = None
|
self._last_traffic_light = None
|
||||||
|
|
||||||
|
@ -68,7 +78,14 @@ class BasicAgent(object):
|
||||||
self._max_steering = opt_dict['max_brake']
|
self._max_steering = opt_dict['max_brake']
|
||||||
|
|
||||||
# Initialize the planners
|
# Initialize the planners
|
||||||
self._local_planner = LocalPlanner(self._vehicle, opt_dict=opt_dict)
|
self._local_planner = LocalPlanner(self._vehicle, opt_dict=opt_dict, map_inst=self._map)
|
||||||
|
if grp_inst:
|
||||||
|
if isinstance(grp_inst, GlobalRoutePlanner):
|
||||||
|
self._global_planner = grp_inst
|
||||||
|
else:
|
||||||
|
print("Warning: Ignoring the given map as it is not a 'carla.Map'")
|
||||||
|
self._global_planner = GlobalRoutePlanner(self._map, self._sampling_resolution)
|
||||||
|
else:
|
||||||
self._global_planner = GlobalRoutePlanner(self._map, self._sampling_resolution)
|
self._global_planner = GlobalRoutePlanner(self._map, self._sampling_resolution)
|
||||||
|
|
||||||
def add_emergency_stop(self, control):
|
def add_emergency_stop(self, control):
|
||||||
|
|
|
@ -30,7 +30,7 @@ class BehaviorAgent(BasicAgent):
|
||||||
are encoded in the agent, from cautious to a more aggressive ones.
|
are encoded in the agent, from cautious to a more aggressive ones.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, vehicle, behavior='normal', opt_dict={}):
|
def __init__(self, vehicle, behavior='normal', opt_dict={}, map_inst=None, grp_inst=None):
|
||||||
"""
|
"""
|
||||||
Constructor method.
|
Constructor method.
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class BehaviorAgent(BasicAgent):
|
||||||
:param behavior: type of agent to apply
|
:param behavior: type of agent to apply
|
||||||
"""
|
"""
|
||||||
|
|
||||||
super(BehaviorAgent, self).__init__(vehicle, opt_dict=opt_dict)
|
super().__init__(vehicle, opt_dict=opt_dict, map_inst=map_inst, grp_inst=grp_inst)
|
||||||
self._look_ahead_steps = 0
|
self._look_ahead_steps = 0
|
||||||
|
|
||||||
# Vehicle information
|
# Vehicle information
|
||||||
|
|
|
@ -22,7 +22,7 @@ class ConstantVelocityAgent(BasicAgent):
|
||||||
wait for a bit, and then start again.
|
wait for a bit, and then start again.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, vehicle, target_speed=20, opt_dict={}):
|
def __init__(self, vehicle, target_speed=20, opt_dict={}, map_inst=None, grp_inst=None):
|
||||||
"""
|
"""
|
||||||
Initialization the agent parameters, the local and the global planner.
|
Initialization the agent parameters, the local and the global planner.
|
||||||
|
|
||||||
|
@ -30,8 +30,10 @@ class ConstantVelocityAgent(BasicAgent):
|
||||||
:param target_speed: speed (in Km/h) at which the vehicle will move
|
:param target_speed: speed (in Km/h) at which the vehicle will move
|
||||||
:param opt_dict: dictionary in case some of its parameters want to be changed.
|
:param opt_dict: dictionary in case some of its parameters want to be changed.
|
||||||
This also applies to parameters related to the LocalPlanner.
|
This also applies to parameters related to the LocalPlanner.
|
||||||
|
:param map_inst: carla.Map instance to avoid the expensive call of getting it.
|
||||||
|
:param grp_inst: GlobalRoutePlanner instance to avoid the expensive call of getting it.
|
||||||
"""
|
"""
|
||||||
super(ConstantVelocityAgent, self).__init__(vehicle, target_speed, opt_dict=opt_dict)
|
super().__init__(vehicle, target_speed, opt_dict=opt_dict, map_inst=map_inst, grp_inst=grp_inst)
|
||||||
|
|
||||||
self._use_basic_behavior = False # Whether or not to use the BasicAgent behavior when the constant velocity is down
|
self._use_basic_behavior = False # Whether or not to use the BasicAgent behavior when the constant velocity is down
|
||||||
self._target_speed = target_speed / 3.6 # [m/s]
|
self._target_speed = target_speed / 3.6 # [m/s]
|
||||||
|
|
|
@ -40,7 +40,7 @@ class LocalPlanner(object):
|
||||||
unless a given global plan has already been specified.
|
unless a given global plan has already been specified.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, vehicle, opt_dict={}):
|
def __init__(self, vehicle, opt_dict={}, map_inst=None):
|
||||||
"""
|
"""
|
||||||
:param vehicle: actor to apply to local planner logic onto
|
:param vehicle: actor to apply to local planner logic onto
|
||||||
:param opt_dict: dictionary of arguments with different parameters:
|
:param opt_dict: dictionary of arguments with different parameters:
|
||||||
|
@ -53,9 +53,17 @@ class LocalPlanner(object):
|
||||||
max_brake: maximum brake applied to the vehicle
|
max_brake: maximum brake applied to the vehicle
|
||||||
max_steering: maximum steering applied to the vehicle
|
max_steering: maximum steering applied to the vehicle
|
||||||
offset: distance between the route waypoints and the center of the lane
|
offset: distance between the route waypoints and the center of the lane
|
||||||
|
:param map_inst: carla.Map instance to avoid the expensive call of getting it.
|
||||||
"""
|
"""
|
||||||
self._vehicle = vehicle
|
self._vehicle = vehicle
|
||||||
self._world = self._vehicle.get_world()
|
self._world = self._vehicle.get_world()
|
||||||
|
if map_inst:
|
||||||
|
if isinstance(map_inst, carla.Map):
|
||||||
|
self._map = map_inst
|
||||||
|
else:
|
||||||
|
print("Warning: Ignoring the given map as it is not a 'carla.Map'")
|
||||||
|
self._map = self._world.get_map()
|
||||||
|
else:
|
||||||
self._map = self._world.get_map()
|
self._map = self._world.get_map()
|
||||||
|
|
||||||
self._vehicle_controller = None
|
self._vehicle_controller = None
|
||||||
|
|
Loading…
Reference in New Issue