Add get_actor_name & get_actor_class_name. (#8165)

* Add initial GetUnrealName & GetUnrealClassName code.

* Remove snapshot-based code.

* Code cleanup.
This commit is contained in:
MarcelPiNacy-CVC 2024-09-19 11:07:46 +02:00 committed by GitHub
parent 001604da6b
commit 73a716e24d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 80 additions and 2 deletions

View File

@ -32,6 +32,16 @@ namespace client {
return GetEpisode().Lock()->GetActorAcceleration(*this);
}
std::string Actor::GetActorName() const
{
return GetEpisode().Lock()->GetActorName(*this);
}
std::string Actor::GetActorClassName() const
{
return GetEpisode().Lock()->GetActorClassName(*this);
}
void Actor::SetLocation(const geom::Location &location) {
GetEpisode().Lock()->SetActorLocation(*this, location);
}

View File

@ -60,6 +60,18 @@ namespace client {
/// acceleration calculated after the actor's velocity.
geom::Vector3D GetAcceleration() const;
/// Return the name of the underlying Unreal actor.
///
/// @note This function does not call the simulator, it returns the
/// acceleration calculated after the actor's velocity.
std::string GetActorName() const;
/// Return the name of the underlying actor's Unreal class.
///
/// @note This function does not call the simulator, it returns the
/// acceleration calculated after the actor's velocity.
std::string GetActorClassName() const;
/// Teleport the actor to @a location.
void SetLocation(const geom::Location &location);

View File

@ -710,6 +710,16 @@ namespace detail {
return _pimpl->CallAndWait<return_t>("cast_ray", start_location, end_location);
}
std::string Client::GetActorName(rpc::ActorId actor) const
{
return _pimpl->CallAndWait<std::string>("get_actor_name", actor);
}
std::string Client::GetActorClassName(rpc::ActorId actor) const
{
return _pimpl->CallAndWait<std::string>("get_actor_class_name", actor);
}
} // namespace detail
} // namespace client
} // namespace carla

View File

@ -439,6 +439,10 @@ namespace detail {
std::vector<rpc::LabelledPoint> CastRay(
geom::Location start_location, geom::Location end_location) const;
std::string GetActorName(rpc::ActorId actor) const;
std::string GetActorClassName(rpc::ActorId actor) const;
private:
class Pimpl;

View File

@ -438,6 +438,16 @@ namespace detail {
return GetActorSnapshot(actor).acceleration;
}
std::string GetActorName(const Actor& actor) const
{
return _client.GetActorName(actor.GetId());
}
std::string GetActorClassName(const Actor& actor) const
{
return _client.GetActorClassName(actor.GetId());
}
void SetActorLocation(Actor &actor, const geom::Location &location) {
_client.SetActorLocation(actor.GetId(), location);
}

View File

@ -134,7 +134,6 @@ namespace detail {
geom::Vector3D angular_velocity;
geom::Vector3D acceleration;
union TypeDependentState {
detail::TrafficLightData traffic_light_data;
detail::TrafficSignData traffic_sign_data;

View File

@ -111,6 +111,8 @@ void export_actor() {
.def("get_velocity", &cc::Actor::GetVelocity)
.def("get_angular_velocity", &cc::Actor::GetAngularVelocity)
.def("get_acceleration", &cc::Actor::GetAcceleration)
.def("get_actor_name", &cc::Actor::GetActorName)
.def("get_actor_class_name", &cc::Actor::GetActorClassName)
.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")))

View File

@ -353,6 +353,9 @@ static carla::Buffer FWorldObserver_Serialize(
}
ActorTransform = View->GetActorGlobalTransform();
auto ActorPtr = View->GetActor();
check(ActorPtr != nullptr);
ActorDynamicState info = {
View->GetActorId(),
View->GetActorState(),
@ -360,7 +363,7 @@ static carla::Buffer FWorldObserver_Serialize(
carla::geom::Vector3D(Velocity.X, Velocity.Y, Velocity.Z),
AngularVelocity,
Acceleration,
State,
State
};
write_data(info);
}

View File

@ -2650,6 +2650,34 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_
return URayTracer::CastRay(StartLocation, EndLocation, World);
};
BIND_SYNC(get_actor_name) << [this](
cr::ActorId ActorID) -> R<std::string>
{
REQUIRE_CARLA_EPISODE();
auto CarlaActor = Episode->FindCarlaActor(ActorID);
check(CarlaActor != nullptr);
auto Actor = CarlaActor->GetActor();
check(Actor != nullptr);
auto Name = Actor->GetName();
auto NameStr = StringCast<UTF8CHAR>(*Name, Name.Len());
return std::string((const char*)NameStr.Get(), NameStr.Length());
};
BIND_SYNC(get_actor_class_name) << [this](
cr::ActorId ActorID) -> R<std::string>
{
REQUIRE_CARLA_EPISODE();
auto CarlaActor = Episode->FindCarlaActor(ActorID);
check(CarlaActor != nullptr);
auto Actor = CarlaActor->GetActor();
check(Actor != nullptr);
auto Class = Actor->GetClass();
check(Class != nullptr);
auto Name = Class->GetName();
auto NameStr = StringCast<UTF8CHAR>(*Name, Name.Len());
return std::string((const char*)NameStr.Get(), NameStr.Length());
};
}
// =============================================================================