CARLA
Loading...
Searching...
No Matches
carla::agents::navigation::BasicAgent Class Reference

C++ port of agents.navigation.basic_agent.BasicAgent. More...

#include <BasicAgent.h>

Inheritance diagram for carla::agents::navigation::BasicAgent:

Classes

struct  Options
 Tunable knobs. More...
struct  VehicleObstacle

Public Member Functions

rpc::VehicleControl AddEmergencyStop (rpc::VehicleControl c) const
 Overwrites throttle/brake to perform an emergency stop.
 BasicAgent (SharedPtr< client::Vehicle > vehicle, float target_speed_kmh=20.0f, const Options &options=DefaultOptions(), SharedPtr< client::Map > map=nullptr, SharedPtr< GlobalRoutePlanner > grp=nullptr)
bool Done () const
void FollowSpeedLimits (bool value=true)
GlobalRoutePlanner * GetGlobalPlanner ()
LocalPlanner * GetLocalPlanner ()
void IgnoreStopSigns (bool active=true)
void IgnoreTrafficLights (bool active=true)
void IgnoreVehicles (bool active=true)
void LaneChange (const std::string &direction, float same_lane_time=0.0f, float other_lane_time=0.0f, float lane_change_time=2.0f)
 Replaces the current plan with one that performs a lane change.
virtual rpc::VehicleControl RunStep ()
void SetDestination (const geom::Location &end, std::optional< geom::Location > start=std::nullopt)
 Computes a route from start (or the current target waypoint) to end and forwards it to the local planner.
void SetGlobalPlan (const std::vector< LocalPlanner::PlanItem > &plan, bool stop_waypoint_creation=true, bool clean_queue=true)
void SetOffset (float offset)
void SetTargetSpeed (float speed_kmh)
std::vector< LocalPlanner::PlanItem > TraceRoute (SharedPtr< client::Waypoint > start, SharedPtr< client::Waypoint > end)
virtual ~BasicAgent ()=default

Static Public Member Functions

static Options DefaultOptions ()
 Out-of-line default factory; see LocalPlanner::DefaultOptions().

Protected Member Functions

std::pair< bool, SharedPtr< client::TrafficLight > > AffectedByTrafficLight (SharedPtr< client::ActorList > lights=nullptr, std::optional< float > max_distance=std::nullopt)
 Returns (affected, light) similar to Python _affected_by_traffic_light.
std::vector< LocalPlanner::PlanItem > GenerateLaneChangePath (SharedPtr< client::Waypoint > waypoint, const std::string &direction="left", float distance_same_lane=10.0f, float distance_other_lane=25.0f, float lane_change_distance=25.0f, bool check=true, int lane_changes=1, float step_distance=2.0f)
 Mirrors Python _generate_lane_change_path.
VehicleObstacle VehicleObstacleDetected (SharedPtr< client::ActorList > vehicles=nullptr, std::optional< float > max_distance=std::nullopt, float up_angle_th=90.0f, float low_angle_th=0.0f, int lane_offset=0)
 Mirrors Python _vehicle_obstacle_detected.

Protected Attributes

float _base_tlight_threshold
float _base_vehicle_threshold
SharedPtr< GlobalRoutePlanner > _global_planner
bool _ignore_stop_signs
bool _ignore_traffic_lights
bool _ignore_vehicles
SharedPtr< client::TrafficLight > _last_traffic_light
SharedPtr< client::ActorList > _lights_list
std::unordered_map< uint32_t, SharedPtr< client::Waypoint > > _lights_map
std::unique_ptr< LocalPlanner > _local_planner
SharedPtr< client::Map > _map
float _max_brake
float _offset
float _sampling_resolution
float _speed_ratio
float _target_speed
bool _use_bbs_detection
SharedPtr< client::Vehicle > _vehicle
SharedPtr< client::World > _world

Detailed Description

C++ port of agents.navigation.basic_agent.BasicAgent.

Roams the scene following random or scripted waypoints while obeying traffic lights and avoiding other vehicles. Stop signs are ignored.

Definition at line 44 of file BasicAgent.h.

Constructor & Destructor Documentation

◆ BasicAgent()

◆ ~BasicAgent()

Member Function Documentation

◆ AddEmergencyStop()

rpc::VehicleControl carla::agents::navigation::BasicAgent::AddEmergencyStop ( rpc::VehicleControl c) const

Overwrites throttle/brake to perform an emergency stop.

Steering is left intact so the agent doesn't drift mid-turn.

Definition at line 108 of file BasicAgent.cpp.

References _max_brake, carla::rpc::VehicleControl::brake, carla::rpc::VehicleControl::hand_brake, and carla::rpc::VehicleControl::throttle.

Referenced by RunStep(), and ~BasicAgent().

◆ AffectedByTrafficLight()

std::pair< bool, SharedPtr< client::TrafficLight > > carla::agents::navigation::BasicAgent::AffectedByTrafficLight ( SharedPtr< client::ActorList > lights = nullptr,
std::optional< float > max_distance = std::nullopt )
protected

Returns (affected, light) similar to Python _affected_by_traffic_light.

lights may be null — in which case all traffic_light actors are pulled from the world. max_distance defaults to _base_tlight_threshold.

Definition at line 242 of file BasicAgent.cpp.

References _base_tlight_threshold, _ignore_traffic_lights, _last_traffic_light, _lights_map, _map, _vehicle, _world, carla::agents::navigation::GetTrafficLightTriggerLocation(), carla::agents::navigation::IsWithinDistance(), and carla::rpc::Red.

Referenced by RunStep(), carla::agents::navigation::ConstantVelocityAgent::RunStep(), carla::agents::navigation::BehaviorAgent::TrafficLightManager(), and ~BasicAgent().

◆ DefaultOptions()

BasicAgent::Options carla::agents::navigation::BasicAgent::DefaultOptions ( )
inlinestatic

Out-of-line default factory; see LocalPlanner::DefaultOptions().

Definition at line 171 of file BasicAgent.h.

Referenced by TEST().

◆ Done()

bool carla::agents::navigation::BasicAgent::Done ( ) const

Definition at line 206 of file BasicAgent.cpp.

References _local_planner.

Referenced by ~BasicAgent().

◆ FollowSpeedLimits()

void carla::agents::navigation::BasicAgent::FollowSpeedLimits ( bool value = true)

Definition at line 120 of file BasicAgent.cpp.

References _local_planner.

Referenced by ~BasicAgent().

◆ GenerateLaneChangePath()

std::vector< LocalPlanner::PlanItem > carla::agents::navigation::BasicAgent::GenerateLaneChangePath ( SharedPtr< client::Waypoint > waypoint,
const std::string & direction = "left",
float distance_same_lane = 10.0f,
float distance_other_lane = 25.0f,
float lane_change_distance = 25.0f,
bool check = true,
int lane_changes = 1,
float step_distance = 2.0f )
protected

Mirrors Python _generate_lane_change_path.

Returns an empty vector if no valid path exists.

Definition at line 487 of file BasicAgent.cpp.

References carla::agents::navigation::ChangeLaneLeft, carla::agents::navigation::ChangeLaneRight, and carla::agents::navigation::LaneFollow.

Referenced by LaneChange().

◆ GetGlobalPlanner()

GlobalRoutePlanner * carla::agents::navigation::BasicAgent::GetGlobalPlanner ( )

Definition at line 128 of file BasicAgent.cpp.

References _global_planner.

Referenced by ~BasicAgent().

◆ GetLocalPlanner()

LocalPlanner * carla::agents::navigation::BasicAgent::GetLocalPlanner ( )

Definition at line 124 of file BasicAgent.cpp.

References _local_planner.

Referenced by ~BasicAgent().

◆ IgnoreStopSigns()

void carla::agents::navigation::BasicAgent::IgnoreStopSigns ( bool active = true)

Definition at line 211 of file BasicAgent.cpp.

References _ignore_stop_signs.

Referenced by ~BasicAgent().

◆ IgnoreTrafficLights()

void carla::agents::navigation::BasicAgent::IgnoreTrafficLights ( bool active = true)

Definition at line 210 of file BasicAgent.cpp.

References _ignore_traffic_lights.

Referenced by ~BasicAgent().

◆ IgnoreVehicles()

void carla::agents::navigation::BasicAgent::IgnoreVehicles ( bool active = true)

Definition at line 212 of file BasicAgent.cpp.

References _ignore_vehicles.

Referenced by ~BasicAgent().

◆ LaneChange()

void carla::agents::navigation::BasicAgent::LaneChange ( const std::string & direction,
float same_lane_time = 0.0f,
float other_lane_time = 0.0f,
float lane_change_time = 2.0f )

Replaces the current plan with one that performs a lane change.

direction must be "left" or "right".

Definition at line 218 of file BasicAgent.cpp.

References _map, _sampling_resolution, _vehicle, GenerateLaneChangePath(), and SetGlobalPlan().

Referenced by ~BasicAgent().

◆ RunStep()

◆ SetDestination()

void carla::agents::navigation::BasicAgent::SetDestination ( const geom::Location & end,
std::optional< geom::Location > start = std::nullopt )

Computes a route from start (or the current target waypoint) to end and forwards it to the local planner.

Definition at line 132 of file BasicAgent.cpp.

References _local_planner, _map, _vehicle, and TraceRoute().

Referenced by carla::agents::navigation::BehaviorAgent::Tailgating(), and ~BasicAgent().

◆ SetGlobalPlan()

void carla::agents::navigation::BasicAgent::SetGlobalPlan ( const std::vector< LocalPlanner::PlanItem > & plan,
bool stop_waypoint_creation = true,
bool clean_queue = true )

Definition at line 160 of file BasicAgent.cpp.

References _local_planner.

Referenced by LaneChange(), and ~BasicAgent().

◆ SetOffset()

void carla::agents::navigation::BasicAgent::SetOffset ( float offset)

Definition at line 214 of file BasicAgent.cpp.

References _local_planner.

Referenced by ~BasicAgent().

◆ SetTargetSpeed()

void carla::agents::navigation::BasicAgent::SetTargetSpeed ( float speed_kmh)

Definition at line 115 of file BasicAgent.cpp.

References _local_planner, and _target_speed.

Referenced by ~BasicAgent().

◆ TraceRoute()

std::vector< LocalPlanner::PlanItem > carla::agents::navigation::BasicAgent::TraceRoute ( SharedPtr< client::Waypoint > start,
SharedPtr< client::Waypoint > end )

Definition at line 167 of file BasicAgent.cpp.

References _global_planner.

Referenced by SetDestination(), and ~BasicAgent().

◆ VehicleObstacleDetected()

Member Data Documentation

◆ _base_tlight_threshold

float carla::agents::navigation::BasicAgent::_base_tlight_threshold
protected

◆ _base_vehicle_threshold

float carla::agents::navigation::BasicAgent::_base_vehicle_threshold
protected

◆ _global_planner

SharedPtr<GlobalRoutePlanner> carla::agents::navigation::BasicAgent::_global_planner
protected

Definition at line 154 of file BasicAgent.h.

Referenced by BasicAgent(), GetGlobalPlanner(), and TraceRoute().

◆ _ignore_stop_signs

bool carla::agents::navigation::BasicAgent::_ignore_stop_signs
protected

Definition at line 159 of file BasicAgent.h.

Referenced by BasicAgent(), and IgnoreStopSigns().

◆ _ignore_traffic_lights

bool carla::agents::navigation::BasicAgent::_ignore_traffic_lights
protected

Definition at line 158 of file BasicAgent.h.

Referenced by AffectedByTrafficLight(), BasicAgent(), and IgnoreTrafficLights().

◆ _ignore_vehicles

bool carla::agents::navigation::BasicAgent::_ignore_vehicles
protected

Definition at line 160 of file BasicAgent.h.

Referenced by BasicAgent(), IgnoreVehicles(), and VehicleObstacleDetected().

◆ _last_traffic_light

SharedPtr<client::TrafficLight> carla::agents::navigation::BasicAgent::_last_traffic_light
protected

Definition at line 152 of file BasicAgent.h.

Referenced by AffectedByTrafficLight(), and BasicAgent().

◆ _lights_list

SharedPtr<client::ActorList> carla::agents::navigation::BasicAgent::_lights_list
protected

Definition at line 155 of file BasicAgent.h.

Referenced by BasicAgent(), and RunStep().

◆ _lights_map

std::unordered_map<uint32_t, SharedPtr<client::Waypoint> > carla::agents::navigation::BasicAgent::_lights_map
protected

Definition at line 156 of file BasicAgent.h.

Referenced by AffectedByTrafficLight().

◆ _local_planner

◆ _map

SharedPtr<client::Map> carla::agents::navigation::BasicAgent::_map
protected

◆ _max_brake

float carla::agents::navigation::BasicAgent::_max_brake
protected

◆ _offset

float carla::agents::navigation::BasicAgent::_offset
protected

Definition at line 168 of file BasicAgent.h.

Referenced by BasicAgent(), and VehicleObstacleDetected().

◆ _sampling_resolution

float carla::agents::navigation::BasicAgent::_sampling_resolution
protected

◆ _speed_ratio

float carla::agents::navigation::BasicAgent::_speed_ratio
protected

Definition at line 166 of file BasicAgent.h.

Referenced by BasicAgent(), and RunStep().

◆ _target_speed

float carla::agents::navigation::BasicAgent::_target_speed
protected

Definition at line 162 of file BasicAgent.h.

Referenced by BasicAgent(), and SetTargetSpeed().

◆ _use_bbs_detection

bool carla::agents::navigation::BasicAgent::_use_bbs_detection
protected

Definition at line 161 of file BasicAgent.h.

Referenced by BasicAgent(), and VehicleObstacleDetected().

◆ _vehicle

◆ _world


The documentation for this class was generated from the following files: