diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c76ea01b..0b2a0e600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * Fixed colors of lane markings when importing a map, they were reversed (white and yellow) * Fixed missing include directive in file **WheelPhysicsControl.h** * Fixed gravity measurement bug from IMU sensor + * Added PythonAPI command to set multiple car light states at once + * Added PythonAPI `carla.world.get_vehicles_light_state` to get all the car light states at once * OpenDRIVE ingestion bugfixes * Added Dynamic Vision Sensor (DVS) camera based on ESIM simulation http://rpg.ifi.uzh.ch/esim.html * Added API functions `get_right_vector` and `get_up_vector` diff --git a/LibCarla/source/carla/client/World.cpp b/LibCarla/source/carla/client/World.cpp index 274548fc0..1133d1138 100644 --- a/LibCarla/source/carla/client/World.cpp +++ b/LibCarla/source/carla/client/World.cpp @@ -26,6 +26,10 @@ namespace client { return _episode.Lock()->GetBlueprintLibrary(); } + rpc::VehicleLightStateList World::GetVehiclesLightStates() const { + return _episode.Lock()->GetVehiclesLightStates(); + } + boost::optional World::GetRandomLocationFromNavigation() const { return _episode.Lock()->GetRandomLocationFromNavigation(); } diff --git a/LibCarla/source/carla/client/World.h b/LibCarla/source/carla/client/World.h index ce9d00f80..6833cd8bc 100644 --- a/LibCarla/source/carla/client/World.h +++ b/LibCarla/source/carla/client/World.h @@ -20,6 +20,7 @@ #include "carla/rpc/EpisodeSettings.h" #include "carla/rpc/VehiclePhysicsControl.h" #include "carla/rpc/WeatherParameters.h" +#include "carla/rpc/VehicleLightStateList.h" #include @@ -59,6 +60,10 @@ namespace client { /// can be used to spawning actor into the world. SharedPtr GetBlueprintLibrary() const; + /// Returns a list of pairs where the firts element is the vehicle ID + /// and the second one is the light state + rpc::VehicleLightStateList GetVehiclesLightStates() const; + /// Get a random location from the pedestrians navigation mesh boost::optional GetRandomLocationFromNavigation() const; diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index 992c88d2b..b14981b80 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -315,6 +315,10 @@ namespace detail { _pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze); } + rpc::VehicleLightStateList Client::GetVehiclesLightStates() { + return _pimpl->CallAndWait>>("get_vehicle_light_states"); + } + std::vector Client::GetGroupTrafficLights(rpc::ActorId traffic_light) { using return_t = std::vector; return _pimpl->CallAndWait("get_group_traffic_lights", traffic_light); diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 8ff62c501..9b687665f 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -24,6 +24,7 @@ #include "carla/rpc/VehicleLightState.h" #include "carla/rpc/WeatherParameters.h" #include "carla/rpc/OpendriveGenerationParameters.h" +#include "carla/rpc/VehicleLightStateList.h" #include #include @@ -203,6 +204,10 @@ namespace detail { rpc::ActorId traffic_light, bool freeze); + /// Returns a list of pairs where the firts element is the vehicle ID + /// and the second one is the light state + rpc::VehicleLightStateList GetVehiclesLightStates(); + std::vector GetGroupTrafficLights( rpc::ActorId traffic_light); diff --git a/LibCarla/source/carla/client/detail/Simulator.cpp b/LibCarla/source/carla/client/detail/Simulator.cpp index 2b543c31a..4b83bcc0e 100644 --- a/LibCarla/source/carla/client/detail/Simulator.cpp +++ b/LibCarla/source/carla/client/detail/Simulator.cpp @@ -161,6 +161,10 @@ namespace detail { return MakeShared(std::move(defs)); } + rpc::VehicleLightStateList Simulator::GetVehiclesLightStates() { + return _client.GetVehiclesLightStates(); + } + SharedPtr Simulator::GetSpectator() { return MakeActor(_client.GetSpectator()); } diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index 99fcd8743..cb24dd75e 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -22,6 +22,7 @@ #include "carla/client/detail/WalkerNavigation.h" #include "carla/profiler/LifetimeProfiled.h" #include "carla/rpc/TrafficLightState.h" +#include "carla/rpc/VehicleLightStateList.h" #include @@ -197,6 +198,10 @@ namespace detail { SharedPtr GetBlueprintLibrary(); + /// Returns a list of pairs where the firts element is the vehicle ID + /// and the second one is the light state + rpc::VehicleLightStateList GetVehiclesLightStates(); + SharedPtr GetSpectator(); rpc::EpisodeSettings GetEpisodeSettings() { diff --git a/LibCarla/source/carla/rpc/VehicleLightStateList.h b/LibCarla/source/carla/rpc/VehicleLightStateList.h new file mode 100644 index 000000000..78969888d --- /dev/null +++ b/LibCarla/source/carla/rpc/VehicleLightStateList.h @@ -0,0 +1,22 @@ +// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "carla/rpc/ActorId.h" +#include "carla/rpc/VehicleLightState.h" + +#include +#include + +namespace carla { +namespace rpc { + + using VehicleLightStateList = + std::vector>; + +} // namespace rpc +} // namespace carla diff --git a/PythonAPI/carla/source/libcarla/World.cpp b/PythonAPI/carla/source/libcarla/World.cpp index 038a4942a..09aac49ec 100644 --- a/PythonAPI/carla/source/libcarla/World.cpp +++ b/PythonAPI/carla/source/libcarla/World.cpp @@ -61,6 +61,15 @@ static auto GetActorsById(carla::client::World &self, const boost::python::list return self.GetActors(ids); } +static auto GetVehiclesLightStates(carla::client::World &self) { + boost::python::dict dict; + auto list = self.GetVehiclesLightStates(); + for (auto &vehicle : list) { + dict[vehicle.first] = vehicle.second; + } + return dict; +} + void export_world() { using namespace boost::python; namespace cc = carla::client; @@ -136,6 +145,7 @@ void export_world() { .add_property("id", &cc::World::GetId) .add_property("debug", &cc::World::MakeDebugHelper) .def("get_blueprint_library", CONST_CALL_WITHOUT_GIL(cc::World, GetBlueprintLibrary)) + .def("get_vehicles_light_states", &GetVehiclesLightStates) .def("get_map", CONST_CALL_WITHOUT_GIL(cc::World, GetMap)) .def("get_random_location_from_navigation", CALL_RETURNING_OPTIONAL_WITHOUT_GIL(cc::World, GetRandomLocationFromNavigation)) .def("get_spectator", CONST_CALL_WITHOUT_GIL(cc::World, GetSpectator)) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index cca410efc..9c8631795 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -256,7 +257,7 @@ void FCarlaServer::FPimpl::BindActions() return UCarlaStatics::GetGameInstance(Episode->GetWorld())->IsLevelPendingLoad(); }; - BIND_SYNC(copy_opendrive_to_file) << [this](const std::string &opendrive, carla::rpc::OpendriveGenerationParameters Params) -> R + BIND_SYNC(copy_opendrive_to_file) << [this](const std::string &opendrive, cr::OpendriveGenerationParameters Params) -> R { REQUIRE_CARLA_EPISODE(); if (!Episode->LoadNewOpendriveEpisode(cr::ToLongFString(opendrive), Params)) @@ -895,6 +896,27 @@ void FCarlaServer::FPimpl::BindActions() return R::Success(); }; + BIND_SYNC(get_vehicle_light_states) << [this]() -> R + { + REQUIRE_CARLA_EPISODE(); + cr::VehicleLightStateList List; + + auto It = Episode->GetActorRegistry().begin(); + for (; It != Episode->GetActorRegistry().end(); ++It) + { + auto Actor = It->GetActor(); + if (!Actor->IsPendingKill() and It->GetActorType() == FActorView::ActorType::Vehicle) + { + const ACarlaWheeledVehicle *Vehicle = Cast(Actor); + List.emplace_back( + It->GetActorId(), + cr::VehicleLightState(Vehicle->GetVehicleLightState()).GetLightStateAsValue()); + } + } + + return List; + }; + BIND_SYNC(get_group_traffic_lights) << [this]( const cr::ActorId ActorId) -> R> { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index 96a23bac1..ded31841f 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -289,7 +289,7 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl() return PhysicsControl; } -FVehicleLightState ACarlaWheeledVehicle::GetVehicleLightState() +FVehicleLightState ACarlaWheeledVehicle::GetVehicleLightState() const { return InputControl.LightState; } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h index 0c1d4f2e6..1baa3473d 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h @@ -113,7 +113,7 @@ public: FVehiclePhysicsControl GetVehiclePhysicsControl(); UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) - FVehicleLightState GetVehicleLightState(); + FVehicleLightState GetVehicleLightState() const; void ApplyVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl);