From 5cbde4d5a937ad40b45e8e86e6446e5afe8845ba Mon Sep 17 00:00:00 2001 From: Aidan Clear Date: Thu, 31 Jan 2019 16:46:35 +0100 Subject: [PATCH 1/5] Updating api to allow retrieval of traffic pole index and the other traffic lights in a group from a traffic light --- LibCarla/source/carla/client/TrafficLight.cpp | 17 +++++++++++- LibCarla/source/carla/client/TrafficLight.h | 7 +++++ .../source/carla/client/detail/Client.cpp | 5 ++++ LibCarla/source/carla/client/detail/Client.h | 2 ++ .../source/carla/client/detail/Simulator.h | 4 +++ .../carla/sensor/data/ActorDynamicState.h | 1 + PythonAPI/source/libcarla/Actor.cpp | 12 +++++++++ .../Source/Carla/Sensor/WorldObserver.cpp | 1 + .../Source/Carla/Server/TheNewCarlaServer.cpp | 26 +++++++++++++++++++ .../Source/Carla/Traffic/TrafficLightBase.cpp | 26 ++++++++++++++++--- .../Source/Carla/Traffic/TrafficLightBase.h | 16 ++++++++++-- 11 files changed, 110 insertions(+), 7 deletions(-) diff --git a/LibCarla/source/carla/client/TrafficLight.cpp b/LibCarla/source/carla/client/TrafficLight.cpp index ca3716e0e..6b5dc8a63 100644 --- a/LibCarla/source/carla/client/TrafficLight.cpp +++ b/LibCarla/source/carla/client/TrafficLight.cpp @@ -5,8 +5,8 @@ // For a copy, see . #include "carla/client/TrafficLight.h" - #include "carla/client/detail/Simulator.h" +#include "carla/client/ActorList.h" namespace carla { namespace client { @@ -55,5 +55,20 @@ namespace client { return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.time_is_frozen; } + uint32_t TrafficLight::GetPoleIndex() + { + return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.pole_index; + } + + std::vector> TrafficLight::GetGroupTrafficLights() { + std::vector> result; + auto ids = GetEpisode().Lock()->GetGroupTrafficLights(*this); + for (auto id : ids) { + SharedPtr actor = GetWorld().GetActors()->Find(id); + result.push_back(boost::static_pointer_cast(actor)); + } + return result; + } + } // namespace client } // namespace carla diff --git a/LibCarla/source/carla/client/TrafficLight.h b/LibCarla/source/carla/client/TrafficLight.h index b5beab046..158d2a39a 100644 --- a/LibCarla/source/carla/client/TrafficLight.h +++ b/LibCarla/source/carla/client/TrafficLight.h @@ -52,6 +52,13 @@ namespace client { /// @note This function does not call the simulator, it returns the data /// received in the last tick. bool IsFrozen() const; + + uint32_t GetPoleIndex(); + + /// Return all traffic lights in the group this one belongs to. + /// + /// @note This function calls the simulator + std::vector> GetGroupTrafficLights(); }; } // namespace client diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index 94c882297..8a93ab64e 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -247,6 +247,11 @@ namespace detail { _pimpl->AsyncCall("add_actor_impulse", actor, vector); } + std::vector Client::GetGroupTrafficLights(const rpc::Actor &trafficLight) { + using return_t = std::vector; + return _pimpl->CallAndWait("get_group_traffic_lights", trafficLight); + } + void Client::SubscribeToStream( const streaming::Token &token, std::function callback) { diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 74e74f207..ddd9d58b6 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -164,6 +164,8 @@ namespace detail { void DrawDebugShape(const rpc::DebugShape &shape); + std::vector GetGroupTrafficLights(const rpc::Actor &trafficLight); + private: class Pimpl; diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index 421f04b21..b57044274 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -266,6 +266,10 @@ namespace detail { _client.FreezeTrafficLight(trafficLight.Serialize(), freeze); } + std::vector GetGroupTrafficLights(TrafficLight &trafficLight) { + return _client.GetGroupTrafficLights(trafficLight.Serialize()); + } + /// @} // ========================================================================= /// @name Debug diff --git a/LibCarla/source/carla/sensor/data/ActorDynamicState.h b/LibCarla/source/carla/sensor/data/ActorDynamicState.h index f0b75b116..d02a8bf36 100644 --- a/LibCarla/source/carla/sensor/data/ActorDynamicState.h +++ b/LibCarla/source/carla/sensor/data/ActorDynamicState.h @@ -99,6 +99,7 @@ namespace detail { float red_time; float elapsed_time; bool time_is_frozen; + uint32_t pole_index; }; #pragma pack(pop) } // namespace detail diff --git a/PythonAPI/source/libcarla/Actor.cpp b/PythonAPI/source/libcarla/Actor.cpp index 43d57fb92..e1b055456 100644 --- a/PythonAPI/source/libcarla/Actor.cpp +++ b/PythonAPI/source/libcarla/Actor.cpp @@ -33,6 +33,16 @@ static auto GetSemanticTags(const carla::client::Actor &self) { return boost::python::list(iter); } +static auto GetGroupTrafficLights(carla::client::TrafficLight &self) { + namespace py = boost::python; + auto values = self.GetGroupTrafficLights(); + py::list result; + for (auto value : values) { + result.append(value); + } + return result; +} + void export_actor() { using namespace boost::python; namespace cc = carla::client; @@ -123,6 +133,8 @@ void export_actor() { .def("get_elapsed_time", &cc::TrafficLight::GetElapsedTime) .def("freeze", &cc::TrafficLight::Freeze, (arg("freeze"))) .def("is_frozen", &cc::TrafficLight::IsFrozen) + .def("get_pole_index", &cc::TrafficLight::GetPoleIndex) + .def("get_group_traffic_lights", &GetGroupTrafficLights) .def(self_ns::str(self_ns::self)) ; } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/WorldObserver.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/WorldObserver.cpp index 5f437b299..05c50ba75 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/WorldObserver.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/WorldObserver.cpp @@ -71,6 +71,7 @@ static auto AWorldObserver_GetActorState(const FActorView &View, const FActorReg state.traffic_light_data.red_time = TrafficLight->GetRedTime(); state.traffic_light_data.elapsed_time = TrafficLight->GetElapsedTime(); state.traffic_light_data.time_is_frozen = TrafficLight->GetTimeIsFrozen(); + state.traffic_light_data.pole_index = TrafficLight->GetPoleIndex(); } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/TheNewCarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/TheNewCarlaServer.cpp index 364e01351..bc15d84dd 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/TheNewCarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/TheNewCarlaServer.cpp @@ -589,6 +589,32 @@ void FTheNewCarlaServer::FPimpl::BindActions() return R::Success(); }); + Server.BindSync("get_group_traffic_lights", [this]( + const cr::Actor Actor) -> R> + { + REQUIRE_CARLA_EPISODE(); + auto ActorView = Episode->GetActorRegistry().Find(Actor.id); + if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) + { + RESPOND_ERROR("unable to get group traffic lights: actor not found"); + } + auto TrafficLight = Cast(ActorView.GetActor()); + if (TrafficLight == nullptr) + { + RESPOND_ERROR("unable to get group traffic lights: actor is not a traffic light"); + } + std::vector Result; + for (auto TLight : TrafficLight->GetGroupTrafficLights()) + { + auto View = Episode->FindActor(TLight); + if (View.IsValid()) + { + Result.push_back(View.GetActorId()); + } + } + return Result; + }); + Server.BindSync("draw_debug_shape", [this](const cr::DebugShape &shape) -> R { REQUIRE_CARLA_EPISODE(); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightBase.cpp index a9f4f954c..e00503906 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightBase.cpp @@ -79,6 +79,11 @@ void ATrafficLightBase::Tick(float DeltaSeconds) if (ElapsedTime > ChangeTime) { + // Freeze if part of a group and about to turn red + if (GroupTrafficLights.Num() > 0 && State == ETrafficLightState::Yellow) + { + SetTimeIsFrozen(true); + } SwitchTrafficLightState(); } } @@ -98,7 +103,6 @@ void ATrafficLightBase::PostEditChangeProperty(FPropertyChangedEvent &Event) void ATrafficLightBase::SetTrafficLightState(const ETrafficLightState InState) { - NumChanges++; ElapsedTime = 0.0f; State = InState; SetTrafficSignState(ToTrafficSignState(State)); @@ -197,7 +201,6 @@ void ATrafficLightBase::SetTimeIsFrozen(bool InTimeIsFrozen) TimeIsFrozen = InTimeIsFrozen; if (!TimeIsFrozen) { - NumChanges = 0; ElapsedTime = 0.0f; } } @@ -207,7 +210,22 @@ bool ATrafficLightBase::GetTimeIsFrozen() const return TimeIsFrozen; } -int ATrafficLightBase::GetNumChanges() const +void ATrafficLightBase::SetPoleIndex(int InPoleIndex) { - return NumChanges; + PoleIndex = InPoleIndex; +} + +int ATrafficLightBase::GetPoleIndex() const +{ + return PoleIndex; +} + +TArray ATrafficLightBase::GetGroupTrafficLights() const +{ + return GroupTrafficLights; +} + +void ATrafficLightBase::SetGroupTrafficLights(TArray InGroupTrafficLights) +{ + GroupTrafficLights = InGroupTrafficLights; } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightBase.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightBase.h index 765790016..8caf88fbf 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightBase.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightBase.h @@ -82,7 +82,16 @@ public: bool GetTimeIsFrozen() const; UFUNCTION(Category = "Traffic Light", BlueprintCallable) - int GetNumChanges() const; + void SetPoleIndex(int InPoleIndex); + + UFUNCTION(Category = "Traffic Light", BlueprintCallable) + int GetPoleIndex() const; + + UFUNCTION(Category = "Traffic Light", BlueprintCallable) + TArray GetGroupTrafficLights() const; + + UFUNCTION(Category = "Traffic Light", BlueprintCallable) + void SetGroupTrafficLights(TArray InGroupTrafficLights); protected: @@ -113,5 +122,8 @@ private: bool TimeIsFrozen = false; UPROPERTY(Category = "Traffic Light", VisibleAnywhere) - int NumChanges = 0; + int PoleIndex = 0; + + UPROPERTY(Category = "Traffic Light", VisibleAnywhere) + TArray GroupTrafficLights; }; From f3eeb2ffa341f8c969e3d7843a0b0a943776fd9e Mon Sep 17 00:00:00 2001 From: Aidan Clear Date: Thu, 31 Jan 2019 17:02:15 +0100 Subject: [PATCH 2/5] Updating changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d60ee0e3f..0bd394cce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * Fixed BP_MultipleFloor, tweaked offset in BaseFloor to adjust meshes between them * New traffic signs assets: one-way, no-turn, more speed limits, do not enter, arrow floors, Michigan left, and lane end * Expose traffic sign's trigger volumes on Python API + * Updated the Python API to enable the user to acquire a traffic light's pole index and all traffic lights in it's group ## CARLA 0.9.3 From a4aa8ef5dd6e7a716604c74fbdc43808e82ef121 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Wed, 27 Feb 2019 18:54:03 +0100 Subject: [PATCH 3/5] Update python_api.md --- Docs/python_api.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Docs/python_api.md b/Docs/python_api.md index 8c0238dc7..d66448cd7 100644 --- a/Docs/python_api.md +++ b/Docs/python_api.md @@ -127,6 +127,8 @@ - `get_elapsed_time()` - `freeze(True)` - `is_frozen()` +- `get_pole_index()` +- `get_group_traffic_lights()` ## `carla.Sensor(carla.Actor)` From 10ea15d859fd6f1a8591fc079a1554fd6555a017 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Wed, 27 Feb 2019 19:29:13 +0100 Subject: [PATCH 4/5] Update content link --- Util/ContentVersions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Util/ContentVersions.txt b/Util/ContentVersions.txt index f9d0096f0..96f905224 100644 --- a/Util/ContentVersions.txt +++ b/Util/ContentVersions.txt @@ -17,4 +17,4 @@ 0.9.1: 1IZDzNQNVL67h8UlGyKuGegLH612Ifd7H 0.9.2: 1RKRGB22U5t80q4zwYXBJvxQXhzNjaaDf 0.9.3: 1jJlStNHpey62CrMkWVfmtQcJGO7PaD0R -Latest: 1Rr30x4BDCDLM7QfAFsQYhduy6De976qQ +Latest: 1LA1dLOozATCaJryqT7U_nOBR_nPVnBC8 From 2c6bc252d208523f3f81b4b33031841c46d97957 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Wed, 27 Feb 2019 22:59:45 +0100 Subject: [PATCH 5/5] Fix compilation on Windows --- .../Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index 635171fbe..696513cd6 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -218,7 +218,7 @@ void ACarlaWheeledVehicle::ApplyVehiclePhysicsControl(const FVehiclePhysicsContr Vehicle4W->SteeringCurve.EditorCurveData = PhysicsControl.SteeringCurve; // Wheels Setup - for (uint32 i = 0; i < PhysicsControl.Wheels.Num(); ++i) + for (int32 i = 0; i < PhysicsControl.Wheels.Num(); ++i) { Vehicle4W->Wheels[i]->DampingRate = PhysicsControl.Wheels[i].DampingRate; Vehicle4W->Wheels[i]->SteerAngle = PhysicsControl.Wheels[i].SteerAngle;