diff --git a/LibCarla/source/carla/trafficmanager/LocalizationStage.cpp b/LibCarla/source/carla/trafficmanager/LocalizationStage.cpp index e4f893246..3c2ebca42 100644 --- a/LibCarla/source/carla/trafficmanager/LocalizationStage.cpp +++ b/LibCarla/source/carla/trafficmanager/LocalizationStage.cpp @@ -119,8 +119,8 @@ namespace LocalizationConstants { for (auto swp: waypoint_buffer) { RemoveOverlap(swp->GetId(), actor_id); } - uint number_of_pops = waypoint_buffer.size(); - for (uint i = 0; i < number_of_pops; ++i) { + auto number_of_pops = waypoint_buffer.size(); + for (uint j = 0; j < number_of_pops; ++j) { PopWaypoint(waypoint_buffer, actor_id); } diff --git a/LibCarla/source/carla/trafficmanager/TrafficManager.cpp b/LibCarla/source/carla/trafficmanager/TrafficManager.cpp index 783f51b5f..7173e0ef8 100644 --- a/LibCarla/source/carla/trafficmanager/TrafficManager.cpp +++ b/LibCarla/source/carla/trafficmanager/TrafficManager.cpp @@ -177,8 +177,8 @@ namespace traffic_manager { } } - bool TrafficManager::CheckAllFrozen(std::vector tl_to_freeze) { - for (auto elem : tl_to_freeze) { + bool TrafficManager::CheckAllFrozen(TLGroup tl_to_freeze) { + for (auto& elem : tl_to_freeze) { if (!elem->IsFrozen() or elem->GetState() != TLS::Red) { return false; } @@ -188,34 +188,34 @@ namespace traffic_manager { void TrafficManager::ResetAllTrafficLights() { auto world_traffic_lights = world.GetActors()->Filter("*traffic_light*"); - - std::vector> list_of_all_groups; - std::vector tl_to_freeze; + std::vector list_of_all_groups; + TLGroup tl_to_freeze; std::vector list_of_ids; for (auto tl : *world_traffic_lights.get()) { - if (std::find(list_of_ids.begin(), list_of_ids.end(), tl->GetId()) != list_of_ids.end()) { - auto tl_group = boost::static_pointer_cast(tl)->GetGroupTrafficLights(); - list_of_all_groups.push_back(tl_group.at(0).get()); - // tl_group is a std::vector - for (unsigned i=0; i - // tlg->Id is a carla::ActorId - list_of_ids.push_back(tl_group.at(i).get()->GetId()); - if(i!=0) { - tl_to_freeze.push_back(tl_group.at(i).get()); - } + if (std::find(list_of_ids.begin(), list_of_ids.end(), tl->GetId()) != list_of_ids.end()) { + TLGroup tl_group = boost::static_pointer_cast(tl)->GetGroupTrafficLights(); + list_of_all_groups.push_back(tl_group); + // tl_group is a std::vector + for (unsigned i=0; i + // tlg->Id is a carla::ActorId + list_of_ids.push_back(tl_group.at(i).get()->GetId()); + if(i!=0) { + tl_to_freeze.push_back(tl_group.at(i)); } - } - } - for (auto &tl_group : list_of_all_groups) { - tl_group.begin()->SetState(TLS::Green); - for (auto tl = std::next(tl_group.begin(),1); tl != tl_group.end(); ++tl) { - tl->SetState(TLS::Red); + } + } } + + for (TLGroup& tl_group : list_of_all_groups) { + tl_group.front()->SetState(TLS::Green); + std::for_each(tl_group.begin() +1, tl_group.end(), + [] (auto& tl) {tl->SetState(TLS::Red);}); } + while (!CheckAllFrozen(tl_to_freeze)) { - for (auto tln : tl_to_freeze) { + for (auto& tln : tl_to_freeze) { tln->SetState(TLS::Red); tln->Freeze(true); } diff --git a/LibCarla/source/carla/trafficmanager/TrafficManager.h b/LibCarla/source/carla/trafficmanager/TrafficManager.h index 516293d4e..d2f839e71 100644 --- a/LibCarla/source/carla/trafficmanager/TrafficManager.h +++ b/LibCarla/source/carla/trafficmanager/TrafficManager.h @@ -31,6 +31,7 @@ namespace cc = carla::client; using ActorPtr = carla::SharedPtr; using TLS = carla::rpc::TrafficLightState; + using TLGroup = std::vector>; /// The function of this class is to integrate all the various stages of /// the traffic manager appropriately using messengers. @@ -120,7 +121,7 @@ namespace cc = carla::client; void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance); /// Method to check if traffic lights are frozen. - bool CheckAllFrozen(std::vector tl_to_freeze); + bool CheckAllFrozen(TLGroup tl_to_freeze); /// Method to reset all traffic lights. void ResetAllTrafficLights();