Add ActorSnapshot

This commit is contained in:
nsubiron 2019-06-17 16:00:26 +02:00 committed by Néstor Subirón
parent 47a0e9b61c
commit 932b7a73ad
7 changed files with 57 additions and 33 deletions

View File

@ -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 <https://opensource.org/licenses/MIT>.
#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

View File

@ -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<SharedPtr<TrafficLight>> TrafficLight::GetGroupTrafficLights() {

View File

@ -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<TrafficLight> 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<TrafficLight>(GetWorld().GetActor(id));
}

View File

@ -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

View File

@ -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,

View File

@ -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 <memory>
@ -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<ActorId, ActorState> _actors;
std::unordered_map<ActorId, ActorSnapshot> _actors;
};
} // namespace detail

View File

@ -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) {