Added the instances
This commit is contained in:
parent
843ac4b38e
commit
49223437b2
|
@ -1,5 +1,6 @@
|
|||
## 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.
|
||||
* Added new ConstantVelocityAgent
|
||||
* 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.
|
||||
"""
|
||||
|
||||
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.
|
||||
|
||||
|
@ -34,10 +34,20 @@ class BasicAgent(object):
|
|||
: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.
|
||||
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._world = self._vehicle.get_world()
|
||||
self._map = self._world.get_map()
|
||||
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._last_traffic_light = None
|
||||
|
||||
# Base parameters
|
||||
|
@ -68,8 +78,15 @@ class BasicAgent(object):
|
|||
self._max_steering = opt_dict['max_brake']
|
||||
|
||||
# Initialize the planners
|
||||
self._local_planner = LocalPlanner(self._vehicle, opt_dict=opt_dict)
|
||||
self._global_planner = GlobalRoutePlanner(self._map, self._sampling_resolution)
|
||||
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)
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
def __init__(self, vehicle, behavior='normal', opt_dict={}):
|
||||
def __init__(self, vehicle, behavior='normal', opt_dict={}, map_inst=None, grp_inst=None):
|
||||
"""
|
||||
Constructor method.
|
||||
|
||||
|
@ -38,7 +38,7 @@ class BehaviorAgent(BasicAgent):
|
|||
: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
|
||||
|
||||
# Vehicle information
|
||||
|
|
|
@ -22,7 +22,7 @@ class ConstantVelocityAgent(BasicAgent):
|
|||
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.
|
||||
|
||||
|
@ -30,8 +30,10 @@ class ConstantVelocityAgent(BasicAgent):
|
|||
: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.
|
||||
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._target_speed = target_speed / 3.6 # [m/s]
|
||||
|
|
|
@ -40,7 +40,7 @@ class LocalPlanner(object):
|
|||
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 opt_dict: dictionary of arguments with different parameters:
|
||||
|
@ -53,10 +53,18 @@ class LocalPlanner(object):
|
|||
max_brake: maximum brake applied to the vehicle
|
||||
max_steering: maximum steering applied to the vehicle
|
||||
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._world = self._vehicle.get_world()
|
||||
self._map = self._world.get_map()
|
||||
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._vehicle_controller = None
|
||||
self.target_waypoint = None
|
||||
|
|
Loading…
Reference in New Issue