Added get function for all car light states

This commit is contained in:
Marc Garcia Puig 2020-05-27 12:20:23 +02:00 committed by Jacopo Bartiromo
parent 923960751f
commit fc133121c7
12 changed files with 86 additions and 3 deletions

View File

@ -6,6 +6,8 @@
* Fixed colors of lane markings when importing a map, they were reversed (white and yellow) * Fixed colors of lane markings when importing a map, they were reversed (white and yellow)
* Fixed missing include directive in file **WheelPhysicsControl.h** * Fixed missing include directive in file **WheelPhysicsControl.h**
* Fixed gravity measurement bug from IMU sensor * 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 * OpenDRIVE ingestion bugfixes
* Added Dynamic Vision Sensor (DVS) camera based on ESIM simulation http://rpg.ifi.uzh.ch/esim.html * 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` * Added API functions `get_right_vector` and `get_up_vector`

View File

@ -26,6 +26,10 @@ namespace client {
return _episode.Lock()->GetBlueprintLibrary(); return _episode.Lock()->GetBlueprintLibrary();
} }
rpc::VehicleLightStateList World::GetVehiclesLightStates() const {
return _episode.Lock()->GetVehiclesLightStates();
}
boost::optional<geom::Location> World::GetRandomLocationFromNavigation() const { boost::optional<geom::Location> World::GetRandomLocationFromNavigation() const {
return _episode.Lock()->GetRandomLocationFromNavigation(); return _episode.Lock()->GetRandomLocationFromNavigation();
} }

View File

@ -20,6 +20,7 @@
#include "carla/rpc/EpisodeSettings.h" #include "carla/rpc/EpisodeSettings.h"
#include "carla/rpc/VehiclePhysicsControl.h" #include "carla/rpc/VehiclePhysicsControl.h"
#include "carla/rpc/WeatherParameters.h" #include "carla/rpc/WeatherParameters.h"
#include "carla/rpc/VehicleLightStateList.h"
#include <boost/optional.hpp> #include <boost/optional.hpp>
@ -59,6 +60,10 @@ namespace client {
/// can be used to spawning actor into the world. /// can be used to spawning actor into the world.
SharedPtr<BlueprintLibrary> GetBlueprintLibrary() const; SharedPtr<BlueprintLibrary> 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 /// Get a random location from the pedestrians navigation mesh
boost::optional<geom::Location> GetRandomLocationFromNavigation() const; boost::optional<geom::Location> GetRandomLocationFromNavigation() const;

View File

@ -315,6 +315,10 @@ namespace detail {
_pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze); _pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze);
} }
rpc::VehicleLightStateList Client::GetVehiclesLightStates() {
return _pimpl->CallAndWait<std::vector<std::pair<carla::ActorId, uint32_t>>>("get_vehicle_light_states");
}
std::vector<ActorId> Client::GetGroupTrafficLights(rpc::ActorId traffic_light) { std::vector<ActorId> Client::GetGroupTrafficLights(rpc::ActorId traffic_light) {
using return_t = std::vector<ActorId>; using return_t = std::vector<ActorId>;
return _pimpl->CallAndWait<return_t>("get_group_traffic_lights", traffic_light); return _pimpl->CallAndWait<return_t>("get_group_traffic_lights", traffic_light);

View File

@ -24,6 +24,7 @@
#include "carla/rpc/VehicleLightState.h" #include "carla/rpc/VehicleLightState.h"
#include "carla/rpc/WeatherParameters.h" #include "carla/rpc/WeatherParameters.h"
#include "carla/rpc/OpendriveGenerationParameters.h" #include "carla/rpc/OpendriveGenerationParameters.h"
#include "carla/rpc/VehicleLightStateList.h"
#include <functional> #include <functional>
#include <memory> #include <memory>
@ -203,6 +204,10 @@ namespace detail {
rpc::ActorId traffic_light, rpc::ActorId traffic_light,
bool freeze); 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<ActorId> GetGroupTrafficLights( std::vector<ActorId> GetGroupTrafficLights(
rpc::ActorId traffic_light); rpc::ActorId traffic_light);

View File

@ -161,6 +161,10 @@ namespace detail {
return MakeShared<BlueprintLibrary>(std::move(defs)); return MakeShared<BlueprintLibrary>(std::move(defs));
} }
rpc::VehicleLightStateList Simulator::GetVehiclesLightStates() {
return _client.GetVehiclesLightStates();
}
SharedPtr<Actor> Simulator::GetSpectator() { SharedPtr<Actor> Simulator::GetSpectator() {
return MakeActor(_client.GetSpectator()); return MakeActor(_client.GetSpectator());
} }

View File

@ -22,6 +22,7 @@
#include "carla/client/detail/WalkerNavigation.h" #include "carla/client/detail/WalkerNavigation.h"
#include "carla/profiler/LifetimeProfiled.h" #include "carla/profiler/LifetimeProfiled.h"
#include "carla/rpc/TrafficLightState.h" #include "carla/rpc/TrafficLightState.h"
#include "carla/rpc/VehicleLightStateList.h"
#include <boost/optional.hpp> #include <boost/optional.hpp>
@ -197,6 +198,10 @@ namespace detail {
SharedPtr<BlueprintLibrary> GetBlueprintLibrary(); SharedPtr<BlueprintLibrary> 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<Actor> GetSpectator(); SharedPtr<Actor> GetSpectator();
rpc::EpisodeSettings GetEpisodeSettings() { rpc::EpisodeSettings GetEpisodeSettings() {

View File

@ -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 <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/rpc/ActorId.h"
#include "carla/rpc/VehicleLightState.h"
#include <cstdint>
#include <vector>
namespace carla {
namespace rpc {
using VehicleLightStateList =
std::vector<std::pair<ActorId, VehicleLightState::flag_type>>;
} // namespace rpc
} // namespace carla

View File

@ -61,6 +61,15 @@ static auto GetActorsById(carla::client::World &self, const boost::python::list
return self.GetActors(ids); 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() { void export_world() {
using namespace boost::python; using namespace boost::python;
namespace cc = carla::client; namespace cc = carla::client;
@ -136,6 +145,7 @@ void export_world() {
.add_property("id", &cc::World::GetId) .add_property("id", &cc::World::GetId)
.add_property("debug", &cc::World::MakeDebugHelper) .add_property("debug", &cc::World::MakeDebugHelper)
.def("get_blueprint_library", CONST_CALL_WITHOUT_GIL(cc::World, GetBlueprintLibrary)) .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_map", CONST_CALL_WITHOUT_GIL(cc::World, GetMap))
.def("get_random_location_from_navigation", CALL_RETURNING_OPTIONAL_WITHOUT_GIL(cc::World, GetRandomLocationFromNavigation)) .def("get_random_location_from_navigation", CALL_RETURNING_OPTIONAL_WITHOUT_GIL(cc::World, GetRandomLocationFromNavigation))
.def("get_spectator", CONST_CALL_WITHOUT_GIL(cc::World, GetSpectator)) .def("get_spectator", CONST_CALL_WITHOUT_GIL(cc::World, GetSpectator))

View File

@ -35,6 +35,7 @@
#include <carla/rpc/VehicleControl.h> #include <carla/rpc/VehicleControl.h>
#include <carla/rpc/VehiclePhysicsControl.h> #include <carla/rpc/VehiclePhysicsControl.h>
#include <carla/rpc/VehicleLightState.h> #include <carla/rpc/VehicleLightState.h>
#include <carla/rpc/VehicleLightStateList.h>
#include <carla/rpc/WalkerBoneControl.h> #include <carla/rpc/WalkerBoneControl.h>
#include <carla/rpc/WalkerControl.h> #include <carla/rpc/WalkerControl.h>
#include <carla/rpc/WeatherParameters.h> #include <carla/rpc/WeatherParameters.h>
@ -256,7 +257,7 @@ void FCarlaServer::FPimpl::BindActions()
return UCarlaStatics::GetGameInstance(Episode->GetWorld())->IsLevelPendingLoad(); return UCarlaStatics::GetGameInstance(Episode->GetWorld())->IsLevelPendingLoad();
}; };
BIND_SYNC(copy_opendrive_to_file) << [this](const std::string &opendrive, carla::rpc::OpendriveGenerationParameters Params) -> R<void> BIND_SYNC(copy_opendrive_to_file) << [this](const std::string &opendrive, cr::OpendriveGenerationParameters Params) -> R<void>
{ {
REQUIRE_CARLA_EPISODE(); REQUIRE_CARLA_EPISODE();
if (!Episode->LoadNewOpendriveEpisode(cr::ToLongFString(opendrive), Params)) if (!Episode->LoadNewOpendriveEpisode(cr::ToLongFString(opendrive), Params))
@ -895,6 +896,27 @@ void FCarlaServer::FPimpl::BindActions()
return R<void>::Success(); return R<void>::Success();
}; };
BIND_SYNC(get_vehicle_light_states) << [this]() -> R<cr::VehicleLightStateList>
{
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<ACarlaWheeledVehicle>(Actor);
List.emplace_back(
It->GetActorId(),
cr::VehicleLightState(Vehicle->GetVehicleLightState()).GetLightStateAsValue());
}
}
return List;
};
BIND_SYNC(get_group_traffic_lights) << [this]( BIND_SYNC(get_group_traffic_lights) << [this](
const cr::ActorId ActorId) -> R<std::vector<cr::ActorId>> const cr::ActorId ActorId) -> R<std::vector<cr::ActorId>>
{ {

View File

@ -289,7 +289,7 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl()
return PhysicsControl; return PhysicsControl;
} }
FVehicleLightState ACarlaWheeledVehicle::GetVehicleLightState() FVehicleLightState ACarlaWheeledVehicle::GetVehicleLightState() const
{ {
return InputControl.LightState; return InputControl.LightState;
} }

View File

@ -113,7 +113,7 @@ public:
FVehiclePhysicsControl GetVehiclePhysicsControl(); FVehiclePhysicsControl GetVehiclePhysicsControl();
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
FVehicleLightState GetVehicleLightState(); FVehicleLightState GetVehicleLightState() const;
void ApplyVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl); void ApplyVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl);