From 932b7a73adffdbf9290b0310d89f328ffbe75bb2 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Mon, 17 Jun 2019 16:00:26 +0200 Subject: [PATCH] Add ActorSnapshot --- LibCarla/source/carla/client/ActorSnapshot.h | 27 +++++++++++++++++++ LibCarla/source/carla/client/TrafficLight.cpp | 14 +++++----- LibCarla/source/carla/client/Vehicle.cpp | 10 +++---- LibCarla/source/carla/client/Walker.cpp | 2 +- .../carla/client/detail/EpisodeState.cpp | 3 ++- .../source/carla/client/detail/EpisodeState.h | 16 +++-------- .../source/carla/client/detail/Simulator.h | 18 ++++++++----- 7 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 LibCarla/source/carla/client/ActorSnapshot.h diff --git a/LibCarla/source/carla/client/ActorSnapshot.h b/LibCarla/source/carla/client/ActorSnapshot.h new file mode 100644 index 000000000..26b6d5563 --- /dev/null +++ b/LibCarla/source/carla/client/ActorSnapshot.h @@ -0,0 +1,27 @@ +// Copyright (c) 2019 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/geom/Transform.h" +#include "carla/geom/Vector3D.h" +#include "carla/rpc/ActorId.h" +#include "carla/sensor/data/ActorDynamicState.h" + +namespace carla { +namespace client { + + struct ActorSnapshot { + ActorId id = 0u; + geom::Transform transform; + geom::Vector3D velocity; + geom::Vector3D angular_velocity; + geom::Vector3D acceleration; + sensor::data::ActorDynamicState::TypeDependentState state; + }; + +} // namespace client +} // namespace carla diff --git a/LibCarla/source/carla/client/TrafficLight.cpp b/LibCarla/source/carla/client/TrafficLight.cpp index 6b5dc8a63..1f2536386 100644 --- a/LibCarla/source/carla/client/TrafficLight.cpp +++ b/LibCarla/source/carla/client/TrafficLight.cpp @@ -16,7 +16,7 @@ namespace client { } rpc::TrafficLightState TrafficLight::GetState() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.state; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.state; } void TrafficLight::SetGreenTime(float green_time) { @@ -24,7 +24,7 @@ namespace client { } float TrafficLight::GetGreenTime() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.green_time; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.green_time; } void TrafficLight::SetYellowTime(float yellow_time) { @@ -32,7 +32,7 @@ namespace client { } float TrafficLight::GetYellowTime() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.yellow_time; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.yellow_time; } void TrafficLight::SetRedTime(float red_time) { @@ -40,11 +40,11 @@ namespace client { } float TrafficLight::GetRedTime() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.red_time; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.red_time; } float TrafficLight::GetElapsedTime() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.elapsed_time; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.elapsed_time; } void TrafficLight::Freeze(bool freeze) { @@ -52,12 +52,12 @@ namespace client { } bool TrafficLight::IsFrozen() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.time_is_frozen; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.time_is_frozen; } uint32_t TrafficLight::GetPoleIndex() { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.traffic_light_data.pole_index; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.pole_index; } std::vector> TrafficLight::GetGroupTrafficLights() { diff --git a/LibCarla/source/carla/client/Vehicle.cpp b/LibCarla/source/carla/client/Vehicle.cpp index b2c75ea1e..d1d96fce4 100644 --- a/LibCarla/source/carla/client/Vehicle.cpp +++ b/LibCarla/source/carla/client/Vehicle.cpp @@ -44,7 +44,7 @@ namespace client { } Vehicle::Control Vehicle::GetControl() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.vehicle_data.control; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.control; } Vehicle::PhysicsControl Vehicle::GetPhysicsControl() const { @@ -52,19 +52,19 @@ namespace client { } float Vehicle::GetSpeedLimit() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.vehicle_data.speed_limit; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.speed_limit; } rpc::TrafficLightState Vehicle::GetTrafficLightState() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.vehicle_data.traffic_light_state; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.traffic_light_state; } bool Vehicle::IsAtTrafficLight() { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.vehicle_data.has_traffic_light; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.has_traffic_light; } SharedPtr Vehicle::GetTrafficLight() const { - auto id = GetEpisode().Lock()->GetActorDynamicState(*this).state.vehicle_data.traffic_light_id; + auto id = GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.traffic_light_id; return boost::static_pointer_cast(GetWorld().GetActor(id)); } diff --git a/LibCarla/source/carla/client/Walker.cpp b/LibCarla/source/carla/client/Walker.cpp index 145f9bc5f..3311f8967 100644 --- a/LibCarla/source/carla/client/Walker.cpp +++ b/LibCarla/source/carla/client/Walker.cpp @@ -19,7 +19,7 @@ namespace client { } Walker::Control Walker::GetWalkerControl() const { - return GetEpisode().Lock()->GetActorDynamicState(*this).state.walker_control; + return GetEpisode().Lock()->GetActorSnapshot(*this).state.walker_control; } } // namespace client diff --git a/LibCarla/source/carla/client/detail/EpisodeState.cpp b/LibCarla/source/carla/client/detail/EpisodeState.cpp index f8a7a43e7..c8a8e7e02 100644 --- a/LibCarla/source/carla/client/detail/EpisodeState.cpp +++ b/LibCarla/source/carla/client/detail/EpisodeState.cpp @@ -22,7 +22,8 @@ namespace detail { DEBUG_ONLY(auto result = ) _actors.emplace( actor.id, - ActorState{ + ActorSnapshot{ + actor.id, actor.transform, actor.velocity, actor.angular_velocity, diff --git a/LibCarla/source/carla/client/detail/EpisodeState.h b/LibCarla/source/carla/client/detail/EpisodeState.h index 64b45daff..eac8ed00c 100644 --- a/LibCarla/source/carla/client/detail/EpisodeState.h +++ b/LibCarla/source/carla/client/detail/EpisodeState.h @@ -9,8 +9,8 @@ #include "carla/Iterator.h" #include "carla/ListView.h" #include "carla/NonCopyable.h" +#include "carla/client/ActorSnapshot.h" #include "carla/client/Timestamp.h" -#include "carla/sensor/data/ActorDynamicState.h" #include "carla/sensor/data/RawEpisodeState.h" #include @@ -26,14 +26,6 @@ namespace detail { private NonCopyable { public: - struct ActorState { - geom::Transform transform; - geom::Vector3D velocity; - geom::Vector3D angular_velocity; - geom::Vector3D acceleration; - sensor::data::ActorDynamicState::TypeDependentState state; - }; - explicit EpisodeState(uint64_t episode_id) : _episode_id(episode_id) {} explicit EpisodeState(const sensor::data::RawEpisodeState &state); @@ -50,8 +42,8 @@ namespace detail { return _timestamp; } - ActorState GetActorState(ActorId id) const { - ActorState state; + ActorSnapshot GetActorSnapshot(ActorId id) const { + ActorSnapshot state; auto it = _actors.find(id); if (it != _actors.end()) { state = it->second; @@ -73,7 +65,7 @@ namespace detail { const Timestamp _timestamp; - std::unordered_map _actors; + std::unordered_map _actors; }; } // namespace detail diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index abda07a05..d62fb0175 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -215,21 +215,25 @@ namespace detail { bool DestroyActor(Actor &actor); - auto GetActorDynamicState(const Actor &actor) const { + ActorSnapshot GetActorSnapshot(ActorId actor_id) const { DEBUG_ASSERT(_episode != nullptr); - return _episode->GetState()->GetActorState(actor.GetId()); + return _episode->GetState()->GetActorSnapshot(actor_id); + } + + ActorSnapshot GetActorSnapshot(const Actor &actor) const { + return GetActorSnapshot(actor.GetId()); } geom::Location GetActorLocation(const Actor &actor) const { - return GetActorDynamicState(actor).transform.location; + return GetActorSnapshot(actor).transform.location; } geom::Transform GetActorTransform(const Actor &actor) const { - return GetActorDynamicState(actor).transform; + return GetActorSnapshot(actor).transform; } geom::Vector3D GetActorVelocity(const Actor &actor) const { - return GetActorDynamicState(actor).velocity; + return GetActorSnapshot(actor).velocity; } void SetActorVelocity(const Actor &actor, const geom::Vector3D &vector) { @@ -237,7 +241,7 @@ namespace detail { } geom::Vector3D GetActorAngularVelocity(const Actor &actor) const { - return GetActorDynamicState(actor).angular_velocity; + return GetActorSnapshot(actor).angular_velocity; } void SetActorAngularVelocity(const Actor &actor, const geom::Vector3D &vector) { @@ -249,7 +253,7 @@ namespace detail { } geom::Vector3D GetActorAcceleration(const Actor &actor) const { - return GetActorDynamicState(actor).acceleration; + return GetActorSnapshot(actor).acceleration; } void SetActorLocation(Actor &actor, const geom::Location &location) {