From 3eb9a76263ff347002b6aa69f767e7778c486fc1 Mon Sep 17 00:00:00 2001 From: javiergrCS <139075626+javiergrCS@users.noreply.github.com> Date: Wed, 13 Mar 2024 23:02:00 +0100 Subject: [PATCH] Javiergr cs/get socket names (#7170) * Added new function to obtain the name of all actor sockets * Updating CHANGELOG.md * Simplifying code of get_actor_socket_names function --------- Co-authored-by: Blyron <53337103+Blyron@users.noreply.github.com> --- CHANGELOG.md | 1 + LibCarla/source/carla/client/Actor.cpp | 4 ++ LibCarla/source/carla/client/Actor.h | 2 + .../source/carla/client/detail/Client.cpp | 5 ++ LibCarla/source/carla/client/detail/Client.h | 3 ++ .../source/carla/client/detail/Simulator.h | 4 ++ PythonAPI/carla/source/libcarla/Actor.cpp | 3 +- .../Carla/Source/Carla/Server/CarlaServer.cpp | 49 ++++++++++++++++--- 8 files changed, 63 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 001a45805..c2f8e8152 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Added functions to get actor' bones and components names * Added functions to get actor' sockets transforms * make PythonAPI Windows: Fixed incompatibility issue with Anaconda due `py` command. + * Added function to get actor' sockets names * Fixed bug in python agents when vehicle list was empty causing a check on all vehicles (BasicAgent.py) and detected pedestrians as vehicles if no pedestrains are present (BehaviourAgent.py) * Added possibility to change gravity variable in imui sensor for the accelerometer diff --git a/LibCarla/source/carla/client/Actor.cpp b/LibCarla/source/carla/client/Actor.cpp index 0d2b7f962..497c99b02 100644 --- a/LibCarla/source/carla/client/Actor.cpp +++ b/LibCarla/source/carla/client/Actor.cpp @@ -64,6 +64,10 @@ namespace client { return GetEpisode().Lock()->GetActorSocketRelativeTransforms(*this); } + std::vector Actor::GetSocketNames() const { + return GetEpisode().Lock()->GetActorSocketNames(*this); + } + void Actor::SetLocation(const geom::Location &location) { GetEpisode().Lock()->SetActorLocation(*this, location); } diff --git a/LibCarla/source/carla/client/Actor.h b/LibCarla/source/carla/client/Actor.h index 4afd48d4a..c84d59798 100644 --- a/LibCarla/source/carla/client/Actor.h +++ b/LibCarla/source/carla/client/Actor.h @@ -76,6 +76,8 @@ namespace client { std::vector GetSocketRelativeTransforms() const; + std::vector GetSocketNames() const; + /// Teleport the actor to @a location. void SetLocation(const geom::Location &location); diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index b5e60293d..b2715fcd9 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -456,6 +456,11 @@ namespace detail { return _pimpl->CallAndWait("get_actor_socket_relative_transforms", actor); } + std::vector Client::GetActorSocketNames(rpc::ActorId actor) { + using return_t = std::vector; + return _pimpl->CallAndWait("get_actor_socket_names", actor); + } + void Client::SetActorSimulatePhysics(rpc::ActorId actor, const bool enabled) { _pimpl->CallAndWait("set_actor_simulate_physics", actor, enabled); } diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index a542163dd..f77644182 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -263,6 +263,9 @@ namespace detail { std::vector GetActorSocketRelativeTransforms( rpc::ActorId actor); + std::vector GetActorSocketNames( + rpc::ActorId actor); + void SetActorSimulatePhysics( rpc::ActorId actor, bool enabled); diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index 07b617b1c..c6d529347 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -479,6 +479,10 @@ namespace detail { return _client.GetActorSocketRelativeTransforms(actor.GetId()); } + std::vector GetActorSocketNames(const Actor &actor) { + return _client.GetActorSocketNames(actor.GetId()); + } + void SetActorLocation(Actor &actor, const geom::Location &location) { _client.SetActorLocation(actor.GetId(), location); } diff --git a/PythonAPI/carla/source/libcarla/Actor.cpp b/PythonAPI/carla/source/libcarla/Actor.cpp index dda9d58a4..3f9b4ef7e 100644 --- a/PythonAPI/carla/source/libcarla/Actor.cpp +++ b/PythonAPI/carla/source/libcarla/Actor.cpp @@ -120,7 +120,8 @@ void export_actor() { .def("get_component_names", CALL_RETURNING_LIST(cc::Actor,GetComponentNames)) .def("get_bone_names", CALL_RETURNING_LIST(cc::Actor,GetBoneNames)) .def("get_socket_world_transforms", CALL_RETURNING_LIST(cc::Actor,GetSocketWorldTransforms)) - .def("get_socket_relative_transforms", CALL_RETURNING_LIST(cc::Actor,GetSocketRelativeTransforms)) + .def("get_socket_relative_transforms", CALL_RETURNING_LIST(cc::Actor,GetSocketRelativeTransforms)) + .def("get_socket_names", CALL_RETURNING_LIST(cc::Actor,GetSocketNames)) .def("set_location", &cc::Actor::SetLocation, (arg("location"))) .def("set_transform", &cc::Actor::SetTransform, (arg("transform"))) .def("set_target_velocity", &cc::Actor::SetTargetVelocity, (arg("velocity"))) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index a579771ae..6d945ccf5 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -1402,7 +1402,7 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ if (!CarlaActor) { return RespondError( - "get_actor_bone_world_transform", + "get_actor_bone_world_transforms", ECarlaServerResponse::ActorNotFound, " Actor Id: " + FString::FromInt(ActorId)); } @@ -1414,7 +1414,7 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ if(!SkinnedMeshComponents[0]) { return RespondError( - "get_actor_bone_relative_transforms", + "get_actor_bone_world_transforms", ECarlaServerResponse::ComponentNotFound, " Component Name: SkinnedMeshComponent "); } @@ -1443,7 +1443,7 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ if (!CarlaActor) { return RespondError( - "get_actor_bone_relative_transform", + "get_actor_bone_relative_transforms", ECarlaServerResponse::ActorNotFound, " Actor Id: " + FString::FromInt(ActorId)); } @@ -1509,7 +1509,7 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ if (!CarlaActor) { return RespondError( - "get_actor_component_relative_transform", + "get_actor_bone_names", ECarlaServerResponse::ActorNotFound, " Actor Id: " + FString::FromInt(ActorId)); } @@ -1519,7 +1519,7 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ if(!SkinnedMeshComponent) { return RespondError( - "get_actor_bone_relative_transforms", + "get_actor_bone_names", ECarlaServerResponse::ComponentNotFound, " Component Name: SkinnedMeshComponent "); } @@ -1547,7 +1547,7 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ if (!CarlaActor) { return RespondError( - "get_actor_component_relative_transform", + "get_actor_socket_world_transforms", ECarlaServerResponse::ActorNotFound, " Actor Id: " + FString::FromInt(ActorId)); } @@ -1580,7 +1580,7 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ if (!CarlaActor) { return RespondError( - "get_actor_component_relative_transform", + "get_actor_socket_relative_transforms", ECarlaServerResponse::ActorNotFound, " Actor Id: " + FString::FromInt(ActorId)); } @@ -1605,6 +1605,41 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ } }; + BIND_SYNC(get_actor_socket_names) << [this]( + cr::ActorId ActorId) -> R> + { + REQUIRE_CARLA_EPISODE(); + FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId); + if (!CarlaActor) + { + return RespondError( + "get_actor_socket_names", + ECarlaServerResponse::ActorNotFound, + " Actor Id: " + FString::FromInt(ActorId)); + } + else + { + TArray SocketNames; + std::vector StringSocketNames; + TArray Components; + CarlaActor->GetActor()->GetComponents(Components); + for(UActorComponent* ActorComponent : Components) + { + if(USceneComponent* SceneComponent = Cast(ActorComponent)) + { + SocketNames = SceneComponent->GetAllSocketNames(); + for (const FName& Name : SocketNames) + { + FString FSocketName = Name.ToString(); + std::string StringSocketName = TCHAR_TO_UTF8(*FSocketName); + StringSocketNames.push_back(StringSocketName); + } + } + } + return StringSocketNames; + } + }; + BIND_SYNC(get_physics_control) << [this]( cr::ActorId ActorId) -> R {