Add episode info message

This commit is contained in:
nsubiron 2018-10-16 20:12:23 +02:00
parent 5d2ec3aad0
commit d7d4dd4e1e
12 changed files with 86 additions and 9 deletions

View File

@ -15,6 +15,8 @@
## `carla.World`
- `id`
- `map_name`
- `get_blueprint_library()`
- `get_spectator()`
- `get_weather()`

View File

@ -16,6 +16,14 @@
namespace carla {
namespace client {
uint32_t World::GetId() const {
return _episode->GetCurrentEpisodeId();
}
const std::string &World::GetMapName() const {
return _episode->GetCurrentMapName();
}
SharedPtr<BlueprintLibrary> World::GetBlueprintLibrary() const {
return _episode->GetBlueprintLibrary();
}

View File

@ -29,6 +29,10 @@ namespace client {
World &operator=(const World &) = default;
World &operator=(World &&) = default;
uint32_t GetId() const;
const std::string &GetMapName() const;
SharedPtr<BlueprintLibrary> GetBlueprintLibrary() const;
SharedPtr<Actor> GetSpectator() const;

View File

@ -65,10 +65,18 @@ namespace detail {
_pimpl->rpc_client.set_timeout(timeout.milliseconds());
}
std::string Client::GetClientVersion() {
return ::carla::version();
}
std::string Client::GetServerVersion() {
return _pimpl->CallAndWait<std::string>("version");
}
rpc::EpisodeInfo Client::GetEpisodeInfo() {
return _pimpl->CallAndWait<rpc::EpisodeInfo>("get_episode_info");
}
std::vector<rpc::ActorDefinition> Client::GetActorDefinitions() {
return _pimpl->CallAndWait<std::vector<rpc::ActorDefinition>>("get_actor_definitions");
}

View File

@ -12,6 +12,7 @@
#include "carla/geom/Transform.h"
#include "carla/rpc/Actor.h"
#include "carla/rpc/ActorDefinition.h"
#include "carla/rpc/EpisodeInfo.h"
#include "carla/rpc/WeatherParameters.h"
#include <functional>
@ -49,8 +50,12 @@ namespace detail {
void SetTimeout(time_duration timeout);
std::string GetClientVersion();
std::string GetServerVersion();
rpc::EpisodeInfo GetEpisodeInfo();
std::vector<rpc::ActorDefinition> GetActorDefinitions();
rpc::Actor GetSpectator();

View File

@ -17,8 +17,6 @@ namespace detail {
class EpisodeState : private MovableNonCopyable {
public:
EpisodeState() = default; /// @todo
EpisodeState(rpc::EpisodeInfo description)
: _description(std::move(description)) {}

View File

@ -19,6 +19,18 @@ namespace carla {
namespace client {
namespace detail {
static void ValidateVersions(Client &client) {
const auto vc = client.GetClientVersion();
const auto vs = client.GetServerVersion();
if (vc != vs) {
log_warning(
"Version mismatch detected: You are trying to connect to a simulator",
"that might be incompatible with this API");
log_warning("Client API version: =", vc);
log_warning("Simulator API version =", vs);
}
}
// ===========================================================================
// -- Constructor ------------------------------------------------------------
// ===========================================================================
@ -30,10 +42,21 @@ namespace detail {
const bool enable_garbage_collection)
: LIBCARLA_INITIALIZE_LIFETIME_PROFILER("SimulatorClient("s + host + ":" + std::to_string(port) + ")"),
_client(host, port, worker_threads),
_episode(), /// @todo
_gc_policy(enable_garbage_collection ?
GarbageCollectionPolicy::Enabled : GarbageCollectionPolicy::Disabled) {}
// ===========================================================================
// -- Access to current episode ----------------------------------------------
// ===========================================================================
EpisodeProxy Simulator::GetCurrentEpisode() {
if (_episode == nullptr) {
ValidateVersions(_client);
_episode = std::make_unique<EpisodeState>(_client.GetEpisodeInfo());
}
return EpisodeProxy{shared_from_this()};
}
// ===========================================================================
// -- Access to global objects in the episode --------------------------------
// ===========================================================================

View File

@ -6,6 +6,7 @@
#pragma once
#include "carla/Debug.h"
#include "carla/Memory.h"
#include "carla/NonCopyable.h"
#include "carla/Version.h"
@ -54,13 +55,17 @@ namespace detail {
/// @{
auto GetCurrentEpisodeId() const {
return _episode.GetId();
DEBUG_ASSERT(_episode != nullptr);
return _episode->GetId();
}
EpisodeProxy GetCurrentEpisode() {
return EpisodeProxy{shared_from_this()};
const std::string &GetCurrentMapName() const {
DEBUG_ASSERT(_episode != nullptr);
return _episode->GetMapName();
}
EpisodeProxy GetCurrentEpisode();
/// @}
// =========================================================================
/// @name Garbage collection policy
@ -82,7 +87,7 @@ namespace detail {
}
std::string GetClientVersion() {
return ::carla::version();
return _client.GetClientVersion();
}
std::string GetServerVersion() {
@ -165,7 +170,7 @@ namespace detail {
Client _client;
EpisodeState _episode;
std::unique_ptr<EpisodeState> _episode;
GarbageCollectionPolicy _gc_policy;
};

View File

@ -24,6 +24,8 @@ void export_world() {
(arg("blueprint"), arg("transform"), arg("attach_to")=carla::SharedPtr<cc::Actor>())
class_<cc::World>("World", no_init)
.add_property("id", &cc::World::GetId)
.add_property("map_name", CALL_RETURNING_COPY(cc::World, GetMapName))
.def("get_blueprint_library", CONST_CALL_WITHOUT_GIL(cc::World, GetBlueprintLibrary))
.def("get_spectator", CONST_CALL_WITHOUT_GIL(cc::World, GetSpectator))
.def("get_weather", CONST_CALL_WITHOUT_GIL(cc::World, GetWeather))

View File

@ -10,6 +10,13 @@
#include "EngineUtils.h"
#include "GameFramework/SpectatorPawn.h"
UCarlaEpisode::UCarlaEpisode(const FObjectInitializer &ObjectInitializer)
: Super(ObjectInitializer),
Id([]() {
static uint32 COUNTER = 0u;
return ++COUNTER;
}()) {}
void UCarlaEpisode::InitializeAtBeginPlay()
{
auto World = GetWorld();

View File

@ -21,6 +21,13 @@ class CARLA_API UCarlaEpisode : public UObject
public:
UCarlaEpisode(const FObjectInitializer &ObjectInitializer);
auto GetId() const
{
return Id;
}
UFUNCTION(BlueprintCallable)
const FString &GetMapName() const
{
@ -97,6 +104,8 @@ private:
ActorDispatcher.Bind(ActorFactory);
}
const uint32 Id = 0u;
UPROPERTY(VisibleAnywhere)
FString MapName;

View File

@ -16,6 +16,7 @@
#include <carla/rpc/Actor.h>
#include <carla/rpc/ActorDefinition.h>
#include <carla/rpc/ActorDescription.h>
#include <carla/rpc/EpisodeInfo.h>
#include <carla/rpc/Server.h>
#include <carla/rpc/Transform.h>
#include <carla/rpc/VehicleControl.h>
@ -133,7 +134,12 @@ void FTheNewCarlaServer::FPimpl::BindActions()
Server.BindAsync("ping", []() { return true; });
Server.BindAsync("version", []() { return std::string(carla::version()); });
Server.BindAsync("version", []() -> std::string { return carla::version(); });
Server.BindSync("get_episode_info", [this]() -> cr::EpisodeInfo {
RequireEpisode();
return {Episode->GetId(), cr::FromFString(Episode->GetMapName())};
});
Server.BindSync("get_actor_definitions", [this]() {
RequireEpisode();