CARLA
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
carla::agents::navigation::LocalPlanner Class Reference

LocalPlanner reproduces agents.navigation.local_planner.LocalPlanner. More...

#include <LocalPlanner.h>

Classes

struct  Options
 Aggregated configuration. Mirrors the opt_dict in local_planner.py. More...
 

Public Types

using PlanItem = std::pair< SharedPtr< client::Waypoint >, RoadOption >
 

Public Member Functions

bool Done () const
 True when the queue is empty.
 
void FollowSpeedLimits (bool value=true)
 Toggle automatic following of road speed limits.
 
std::pair< SharedPtr< client::Waypoint >, RoadOption > GetIncomingWaypointAndDirection (int steps=3) const
 Peek steps ahead in the queue, falling back to the last entry if the queue is too short.
 
const std::deque< PlanItem > & GetPlan () const
 Read-only view of the queued plan.
 
 LocalPlanner (SharedPtr< client::Vehicle > vehicle, const Options &opt=DefaultOptions(), SharedPtr< client::Map > map=nullptr)
 
void ResetVehicle ()
 Drop the vehicle reference (mirrors reset_vehicle).
 
rpc::VehicleControl RunStep (bool debug=false)
 Drive one tick. Returns the VehicleControl to apply.
 
void SetGlobalPlan (const std::vector< PlanItem > &plan, bool stop_waypoint_creation=true, bool clean_queue=true)
 Replace (or append to) the waypoint queue.
 
void SetOffset (float offset)
 Apply a lateral offset to the underlying PID controller.
 
void SetSpeed (float speed_kmh)
 Override the target speed in km/h.
 
RoadOption TargetRoadOption () const
 Currently active target RoadOption (mirrors target_road_option).
 
SharedPtr< client::Waypoint > TargetWaypoint () const
 Currently active target waypoint (mirrors target_waypoint).
 

Static Public Member Functions

static Options DefaultOptions ()
 Construct a LocalPlanner.
 

Private Member Functions

void ComputeNextWaypoints (std::size_t k)
 Append up to k waypoints to the back of the queue, branching with random choice on intersections (mirrors _compute_next_waypoints).
 
void InitController ()
 Build the VehiclePIDController and seed the queue with the vehicle's current waypoint.
 

Private Attributes

float _base_min_distance
 
float _distance_ratio
 
float _dt
 
bool _follow_speed_limits
 
VehiclePIDController::LateralArgs _lateral_args
 
VehiclePIDController::LongitudinalArgs _longitudinal_args
 
SharedPtr< client::Map > _map
 
float _max_brake
 
std::size_t _max_queue_size = 10000
 
float _max_steering
 
float _max_throttle
 
std::size_t _min_queue_length = 100
 
float _offset
 
std::mt19937 _rng
 
float _sampling_radius
 
bool _stop_waypoint_creation = false
 
RoadOption _target_road_option = RoadOption::Void
 
float _target_speed
 
SharedPtr< client::Waypoint > _target_waypoint
 
SharedPtr< client::Vehicle > _vehicle
 
std::unique_ptr< VehiclePIDController > _vehicle_controller
 
std::deque< PlanItem > _waypoints_queue
 

Detailed Description

LocalPlanner reproduces agents.navigation.local_planner.LocalPlanner.

It maintains a queue of (waypoint, RoadOption) pairs, refills it as needed, and drives the vehicle along it via a VehiclePIDController.

Definition at line 33 of file LocalPlanner.h.

Member Typedef Documentation

◆ PlanItem

Definition at line 35 of file LocalPlanner.h.

Constructor & Destructor Documentation

◆ LocalPlanner()

carla::agents::navigation::LocalPlanner::LocalPlanner ( SharedPtr< client::Vehicle >  vehicle,
const Options &  opt = DefaultOptions(),
SharedPtr< client::Map >  map = nullptr 
)

Definition at line 80 of file LocalPlanner.cpp.

References _map, _vehicle, and InitController().

Member Function Documentation

◆ ComputeNextWaypoints()

void carla::agents::navigation::LocalPlanner::ComputeNextWaypoints ( std::size_t  k)
private

Append up to k waypoints to the back of the queue, branching with random choice on intersections (mirrors _compute_next_waypoints).

Definition at line 141 of file LocalPlanner.cpp.

References _max_queue_size, _rng, _sampling_radius, _waypoints_queue, and carla::agents::navigation::LaneFollow.

Referenced by RunStep().

◆ DefaultOptions()

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

Construct a LocalPlanner.

If map is null we pull the map from the vehicle's world (matches the Python map_inst fallback). Returns a value-initialized Options. Defined out-of-line because GCC's default-arg parser refuses = {} / = Options() when the struct inherits from another aggregate with default member initializers.

Definition at line 148 of file LocalPlanner.h.

Referenced by TEST().

◆ Done()

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

True when the queue is empty.

Definition at line 285 of file LocalPlanner.cpp.

References _waypoints_queue.

◆ FollowSpeedLimits()

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

Toggle automatic following of road speed limits.

Definition at line 137 of file LocalPlanner.cpp.

References _follow_speed_limits.

◆ GetIncomingWaypointAndDirection()

std::pair< SharedPtr< client::Waypoint >, RoadOption > carla::agents::navigation::LocalPlanner::GetIncomingWaypointAndDirection ( int  steps = 3) const

Peek steps ahead in the queue, falling back to the last entry if the queue is too short.

Returns (nullptr, RoadOption::Void) when the queue is empty.

Definition at line 270 of file LocalPlanner.cpp.

References _waypoints_queue, and carla::agents::navigation::Void.

◆ GetPlan()

const std::deque< LocalPlanner::PlanItem > & carla::agents::navigation::LocalPlanner::GetPlan ( ) const

Read-only view of the queued plan.

Definition at line 281 of file LocalPlanner.cpp.

References _waypoints_queue.

◆ InitController()

void carla::agents::navigation::LocalPlanner::InitController ( )
private

Build the VehiclePIDController and seed the queue with the vehicle's current waypoint.

Called from the constructor.

Definition at line 107 of file LocalPlanner.cpp.

References _lateral_args, _longitudinal_args, _map, _max_brake, _max_steering, _max_throttle, _offset, _target_road_option, _target_waypoint, _vehicle, _vehicle_controller, _waypoints_queue, and carla::agents::navigation::LaneFollow.

Referenced by LocalPlanner().

◆ ResetVehicle()

void carla::agents::navigation::LocalPlanner::ResetVehicle ( )

Drop the vehicle reference (mirrors reset_vehicle).

Definition at line 125 of file LocalPlanner.cpp.

References _vehicle.

◆ RunStep()

rpc::VehicleControl carla::agents::navigation::LocalPlanner::RunStep ( bool  debug = false)

◆ SetGlobalPlan()

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

Replace (or append to) the waypoint queue.

Definition at line 183 of file LocalPlanner.cpp.

References _max_queue_size, _stop_waypoint_creation, and _waypoints_queue.

◆ SetOffset()

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

Apply a lateral offset to the underlying PID controller.

Definition at line 205 of file LocalPlanner.cpp.

References _offset, and _vehicle_controller.

◆ SetSpeed()

void carla::agents::navigation::LocalPlanner::SetSpeed ( float  speed_kmh)

Override the target speed in km/h.

Definition at line 129 of file LocalPlanner.cpp.

References _follow_speed_limits, and _target_speed.

◆ TargetRoadOption()

RoadOption carla::agents::navigation::LocalPlanner::TargetRoadOption ( ) const

Currently active target RoadOption (mirrors target_road_option).

Definition at line 293 of file LocalPlanner.cpp.

References _target_road_option.

◆ TargetWaypoint()

SharedPtr< client::Waypoint > carla::agents::navigation::LocalPlanner::TargetWaypoint ( ) const

Currently active target waypoint (mirrors target_waypoint).

Definition at line 289 of file LocalPlanner.cpp.

References _target_waypoint.

Member Data Documentation

◆ _base_min_distance

float carla::agents::navigation::LocalPlanner::_base_min_distance
private

Definition at line 140 of file LocalPlanner.h.

Referenced by RunStep().

◆ _distance_ratio

float carla::agents::navigation::LocalPlanner::_distance_ratio
private

Definition at line 141 of file LocalPlanner.h.

Referenced by RunStep().

◆ _dt

float carla::agents::navigation::LocalPlanner::_dt
private

Definition at line 131 of file LocalPlanner.h.

◆ _follow_speed_limits

bool carla::agents::navigation::LocalPlanner::_follow_speed_limits
private

Definition at line 142 of file LocalPlanner.h.

Referenced by FollowSpeedLimits(), RunStep(), and SetSpeed().

◆ _lateral_args

VehiclePIDController::LateralArgs carla::agents::navigation::LocalPlanner::_lateral_args
private

Definition at line 134 of file LocalPlanner.h.

Referenced by InitController().

◆ _longitudinal_args

VehiclePIDController::LongitudinalArgs carla::agents::navigation::LocalPlanner::_longitudinal_args
private

Definition at line 135 of file LocalPlanner.h.

Referenced by InitController().

◆ _map

SharedPtr<client::Map> carla::agents::navigation::LocalPlanner::_map
private

Definition at line 118 of file LocalPlanner.h.

Referenced by InitController(), and LocalPlanner().

◆ _max_brake

float carla::agents::navigation::LocalPlanner::_max_brake
private

Definition at line 137 of file LocalPlanner.h.

Referenced by InitController().

◆ _max_queue_size

std::size_t carla::agents::navigation::LocalPlanner::_max_queue_size = 10000
private

Definition at line 126 of file LocalPlanner.h.

Referenced by ComputeNextWaypoints(), and SetGlobalPlan().

◆ _max_steering

float carla::agents::navigation::LocalPlanner::_max_steering
private

Definition at line 138 of file LocalPlanner.h.

Referenced by InitController().

◆ _max_throttle

float carla::agents::navigation::LocalPlanner::_max_throttle
private

Definition at line 136 of file LocalPlanner.h.

Referenced by InitController().

◆ _min_queue_length

std::size_t carla::agents::navigation::LocalPlanner::_min_queue_length = 100
private

Definition at line 127 of file LocalPlanner.h.

Referenced by RunStep().

◆ _offset

float carla::agents::navigation::LocalPlanner::_offset
private

Definition at line 139 of file LocalPlanner.h.

Referenced by InitController(), and SetOffset().

◆ _rng

std::mt19937 carla::agents::navigation::LocalPlanner::_rng
mutableprivate

Definition at line 145 of file LocalPlanner.h.

Referenced by ComputeNextWaypoints().

◆ _sampling_radius

float carla::agents::navigation::LocalPlanner::_sampling_radius
private

Definition at line 133 of file LocalPlanner.h.

Referenced by ComputeNextWaypoints().

◆ _stop_waypoint_creation

bool carla::agents::navigation::LocalPlanner::_stop_waypoint_creation = false
private

Definition at line 128 of file LocalPlanner.h.

Referenced by RunStep(), and SetGlobalPlan().

◆ _target_road_option

RoadOption carla::agents::navigation::LocalPlanner::_target_road_option = RoadOption::Void
private

Definition at line 123 of file LocalPlanner.h.

Referenced by InitController(), RunStep(), and TargetRoadOption().

◆ _target_speed

float carla::agents::navigation::LocalPlanner::_target_speed
private

Definition at line 132 of file LocalPlanner.h.

Referenced by RunStep(), and SetSpeed().

◆ _target_waypoint

SharedPtr<client::Waypoint> carla::agents::navigation::LocalPlanner::_target_waypoint
private

Definition at line 122 of file LocalPlanner.h.

Referenced by InitController(), RunStep(), and TargetWaypoint().

◆ _vehicle

SharedPtr<client::Vehicle> carla::agents::navigation::LocalPlanner::_vehicle
private

Definition at line 117 of file LocalPlanner.h.

Referenced by InitController(), LocalPlanner(), ResetVehicle(), and RunStep().

◆ _vehicle_controller

std::unique_ptr<VehiclePIDController> carla::agents::navigation::LocalPlanner::_vehicle_controller
private

Definition at line 120 of file LocalPlanner.h.

Referenced by InitController(), RunStep(), and SetOffset().

◆ _waypoints_queue

std::deque<PlanItem> carla::agents::navigation::LocalPlanner::_waypoints_queue
private

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