utils¶
BasicPlanner¶
- class core.utils.planner.basic_planner.BasicPlanner(cfg: Dict)[source]¶
Basic local planner for Carla simulator. It can set route with a pair of start and end waypoints, or directly set with a waypoint list. The planner will provide target waypoint and road option in current route position, and record current route distance and end timeout. The planner will also judge agent state by checking surrounding vehicles, walkers and traffic lights.
The route’s element consists of a waypoint and a road option. Local planner uses a waypoint queue to store all the unreached waypoints, and a waypoint buffer to store some of the near waypoints to speed up searching. In short, node waypoint is the waypoint in route that farthest from hero vehicle and within
min_distance
, and target waypoint is the next waypoint of node waypoint.- Arguments:
cfg (Dict): Config dict.
- Interfaces:
set_destination, set_route, run_step, get_waypoints_list, clean_up
- get_incoming_waypoint_and_direction(steps: int = 3) Tuple[Waypoint, RoadOption] [source]¶
Returns direction and waypoint at a distance ahead defined by the user.
- Arguments:
steps (int): Number of steps to get the incoming waypoint.
- Returns:
Tuple[carla.Waypoint, RoadOption]: Waypoint and road option ahead.
- get_waypoints_list(waypoint_num: int) List[Waypoint] [source]¶
Return a list of wapoints from the end of waypoint buffer.
- Arguments:
waypoint_num (int): Num of waypoint in list.
- Returns:
List[carla.Waypoint]: List of waypoint.
- run_step() None [source]¶
Run one step of local planner. It will update node and target waypoint and road option, and check agent states.
- set_destination(start_location: Location, end_location: Location, clean: bool = False) None [source]¶
This method creates a route of a list of waypoints from start location to destination location based on the route traced by the global router. If
clean
is set true, it will clean current route and waypoint queue.- Arguments:
start_location (carla.Location): initial position.
end_location (carla.Location): final position.
clean (bool): Whether to clean current route. Defaults to False.
BehaviorPlanner¶
- class core.utils.planner.behavior_planner.BehaviorPlanner(cfg: Dict)[source]¶
Behavior local planner for Carla simulator. It can set route the same way as
BasicPlanner
. BehaviorPlanner can check the speed limitations, traffic lights in evironment, and also take nearby vehicles into account. Lane changing decisions can be taken by analyzing the surrounding environment, such as overtaking or tailgating avoidance. Besides, it can also keep safety distance from a car in front of it by tracking the instantaneous time to collision and keeping it in a certain range. Different sets of behaviors are encoded in the agent, from cautious to a more aggressive ones.- Arguments:
cfg (Dict): Config dict.
- Interfaces:
set_destination, set_route, run_step, get_waypoints_list, clean_up
Visualizer¶
- class core.utils.others.visualizer.Visualizer(cfg: Dict)[source]¶
Visualizer is used to visualize sensor data and print info during running. It can be used to show a sensor image on screen, save a gif or video file.
- Arguments:
cfg (Dict): Config dict.
- Interfaces:
init, paint, run_visualize, done
- init(name: str) None [source]¶
Initlaize visualizer with provided name.
- Arguments:
name (str): Name for window or file.
StuckDetector¶
- class core.utils.env_utils.stuck_detector.StuckDetector(len_thresh: int = 200, speed_thresh: float = 0.1)[source]¶
Stuck detector used to detect vehicle stuck in simulator. It takes speed as input in each tick.
- Arguments:
len_thresh (int, optional): Speed history length to calculate thresh. Defaults to 200.
speed_thresh (float, optional): Speed thresh value. Defaults to 0.1.
- Interfaces:
tick, clear
SensorHelper¶
- class core.utils.simulator_utils.sensor_utils.SensorHelper(obs_cfg: Dict, aug_cfg: Optional[Dict] = None)[source]¶
Interfaces for sensors required for vehicles and data buffer for all sensor data in Carla. The updating for Carla sensors are not synchronous. In each tick, the newest sensor data is obtained from sensor data buffer and returned to the simulator. This class provides an interface that can easily create, receive data and destroy all kinds of sensors in Carla according to config, and apply the same sensor augmantation to all camera sensors.
- Arguments:
obs_cfg (Dict): Config dict for sensor
aug_cfg (Dict, optional): Config dict for sensor augmentation. Defaults to None.
- Interfaces:
setup_sensors, get_sensors_data, clear_up
CollisionSensor¶
- class core.utils.simulator_utils.sensor_utils.CollisionSensor(parent_actor: Actor, col_threshold: float)[source]¶
Carla sensor interface used to detect collision info in simulator. Once created, it will automatically update every tick.
- Arguments:
parent_actor (carla.Actor): Actor to detect collision
col_threshold (float): Threshold value of collided impulse
- Interfaces:
clear
TrafficLightHelper¶
- class core.utils.simulator_utils.sensor_utils.TrafficLightHelper(hero_vehicle: Actor, debug: bool = False)[source]¶
Interface of traffic light detector and recorder. It detects next traffic light state, calculates distance from hero vehicle to the end of this road, and if hero vehicle crosses this line when correlated light is red, it will record running a red light
- Arguments:
hero_vehicle (carla.Actor): Hero vehicle
- Interfaces:
tick