40 using U = std::underlying_type_t<LaneChange>;
41 return (
static_cast<U
>(value) &
static_cast<U
>(flag)) ==
static_cast<U
>(flag);
65 _behavior(BehaviorParamsFor(behavior)) {
100 auto actor_list =
_world->GetActors();
101 auto lights_list = actor_list ? actor_list->Filter(
"*traffic_light*") :
nullptr;
115 auto left_marking = waypoint->GetLeftLaneMarking();
116 auto right_marking = waypoint->GetRightLaneMarking();
117 auto left_wpt = waypoint->GetLeft();
118 auto right_wpt = waypoint->GetRight();
122 auto vehicles_alist =
_world->GetActors()
123 ?
_world->GetActors()->Filter(
"*vehicle*")
126 const float behind_max =
135 if (!(behind.affected && behind.actor))
return;
138 const int wp_lane_id = waypoint->GetLaneId();
141 if (right_marking.has_value() && right_wpt &&
142 (HasLaneChange(right_marking->lane_change, LaneChange::Right) ||
143 HasLaneChange(right_marking->lane_change, LaneChange::Both)) &&
144 (wp_lane_id * right_wpt->GetLaneId() > 0) &&
151 if (!check.affected) {
152 std::cout <<
"Tailgating, moving to the right!" << std::endl;
157 right_wpt->GetTransform().location);
164 if (left_marking.has_value() && left_wpt &&
165 HasLaneChange(left_marking->lane_change, LaneChange::Left) &&
166 (wp_lane_id * left_wpt->GetLaneId() > 0) &&
173 if (!check.affected) {
174 std::cout <<
"Tailgating, moving to the left!" << std::endl;
179 left_wpt->GetTransform().location);
191 auto vehicles_alist =
_world->GetActors()
192 ?
_world->GetActors()->Filter(
"*vehicle*")
224 !waypoint->IsJunction() &&
236 auto walkers_alist =
_world->GetActors()
237 ?
_world->GetActors()->Filter(
"*walker.pedestrian*")
276 const float vehicle_speed =
GetSpeed(vehicle);
277 const float delta_v = std::max(1.0f, (
_speed - vehicle_speed) / 3.6f);
278 const float ttc = (delta_v != 0.0f)
280 :
distance / std::nextafter(0.0f, 1.0f);
282 float target_speed = 0.0f;
284 target_speed = std::min({
289 target_speed = std::min({
294 target_speed = std::min({
313 const auto ego_vehicle_loc =
_vehicle->GetLocation();
314 auto ego_vehicle_wp =
_map->GetWaypoint(ego_vehicle_loc);
323 if (walker_obs.affected && walker_obs.actor) {
324 const auto &walker_extent = walker_obs.actor->GetBoundingBox().extent;
325 const auto &ego_extent =
_vehicle->GetBoundingBox().extent;
326 const float distance = walker_obs.distance
327 - std::max(walker_extent.y, walker_extent.x)
328 - std::max(ego_extent.y, ego_extent.x);
337 if (vehicle_obs.affected && vehicle_obs.actor) {
338 const auto &v_extent = vehicle_obs.actor->GetBoundingBox().extent;
339 const auto &ego_extent =
_vehicle->GetBoundingBox().extent;
340 const float distance = vehicle_obs.distance
341 - std::max(v_extent.y, v_extent.x)
342 - std::max(ego_extent.y, ego_extent.x);
375 control.hand_brake =
false;
C++ port of agents.navigation.basic_agent.BasicAgent.
SharedPtr< client::Map > _map
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.
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.
SharedPtr< client::World > _world
SharedPtr< client::Vehicle > _vehicle
float _sampling_resolution
std::unique_ptr< LocalPlanner > _local_planner
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 plan...
rpc::VehicleControl CarFollowingManager(SharedPtr< client::Actor > vehicle, float distance, bool debug=false)
Car-following control law applied when there is a vehicle in front.
rpc::VehicleControl EmergencyStop() const
Build an emergency-stop control: throttle=0, brake=_max_brake, hand_brake=false, steer left untouched...
VehicleObstacle PedestrianAvoidManager(SharedPtr< client::Waypoint > waypoint)
Detect pedestrians ahead.
rpc::VehicleControl RunStep() override
Polymorphic entry point: keeps dispatch through BasicAgent* correct.
VehicleObstacle CollisionAndCarAvoidManager(SharedPtr< client::Waypoint > waypoint)
Detect collision/car-avoidance opportunities ahead.
void Tailgating(SharedPtr< client::Waypoint > waypoint)
Tailgating-avoidance lane change, called from CollisionAndCarAvoidManager.
BehaviorAgent(SharedPtr< client::Vehicle > vehicle, Behavior behavior=Behavior::Normal, const Options &opts=BasicAgent::DefaultOptions(), SharedPtr< client::Map > map=nullptr, SharedPtr< GlobalRoutePlanner > grp=nullptr)
bool TrafficLightManager()
Returns true if the agent is affected by a traffic light.
SharedPtr< client::Waypoint > _incoming_waypoint
RoadOption _incoming_direction
BehaviorParameters _behavior
void UpdateInformation()
Refresh cached scene information consumed by RunStep.
float Positive(float v)
Clamp v at zero. Inline because it's tiny.
float GetSpeed(SharedPtr< client::Actor > actor)
Compute speed of an actor in km/h.
road::element::LaneMarking::LaneChange LaneChange
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
static constexpr BehaviorParameters Aggressive()
float min_proximity_threshold
static constexpr BehaviorParameters Cautious()
static constexpr BehaviorParameters Normal()
LaneChange
Can be used as flags.