Expose weather to client API
This commit is contained in:
parent
856ecde332
commit
5bb425737c
|
@ -18,6 +18,8 @@
|
|||
|
||||
- `get_blueprint_library()`
|
||||
- `get_spectator()`
|
||||
- `get_weather()`
|
||||
- `set_weather(weather_parameters)`
|
||||
- `spawn_actor(blueprint, transform, attach_to=None)`
|
||||
- `try_spawn_actor(blueprint, transform, attach_to=None)`
|
||||
|
||||
|
@ -120,6 +122,17 @@
|
|||
- `__eq__()`
|
||||
- `__ne__()`
|
||||
|
||||
## `carla.WeatherParameters`
|
||||
|
||||
- `cloudyness`
|
||||
- `precipitation`
|
||||
- `precipitation_deposits`
|
||||
- `wind_intensity`
|
||||
- `sun_azimuth_angle`
|
||||
- `sun_altitude_angle`
|
||||
- `__eq__()`
|
||||
- `__ne__()`
|
||||
|
||||
## `carla.Location`
|
||||
|
||||
- `x`
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "carla/PythonUtil.h"
|
||||
#include "carla/client/World.h"
|
||||
#include "carla/client/detail/Client.h"
|
||||
|
||||
namespace carla {
|
||||
|
|
|
@ -24,6 +24,14 @@ namespace client {
|
|||
return _episode->GetSpectator();
|
||||
}
|
||||
|
||||
rpc::WeatherParameters World::GetWeather() const {
|
||||
return _episode->GetWeatherParameters();
|
||||
}
|
||||
|
||||
void World::SetWeather(const rpc::WeatherParameters &weather) {
|
||||
_episode->SetWeatherParameters(weather);
|
||||
}
|
||||
|
||||
SharedPtr<Actor> World::SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const geom::Transform &transform,
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "carla/Memory.h"
|
||||
#include "carla/client/detail/Episode.h"
|
||||
#include "carla/geom/Transform.h"
|
||||
#include "carla/rpc/WeatherParameters.h"
|
||||
|
||||
namespace carla {
|
||||
namespace client {
|
||||
|
@ -32,6 +33,10 @@ namespace client {
|
|||
|
||||
SharedPtr<Actor> GetSpectator() const;
|
||||
|
||||
rpc::WeatherParameters GetWeather() const;
|
||||
|
||||
void SetWeather(const rpc::WeatherParameters &weather);
|
||||
|
||||
SharedPtr<Actor> SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const geom::Transform &transform,
|
||||
|
|
|
@ -101,6 +101,14 @@ namespace detail {
|
|||
GarbageCollectionPolicy::Disabled);
|
||||
}
|
||||
|
||||
rpc::WeatherParameters Client::GetWeatherParameters() {
|
||||
return _pimpl->CallAndWait<rpc::WeatherParameters>("get_weather");
|
||||
}
|
||||
|
||||
void Client::SetWeatherParameters(const rpc::WeatherParameters &weather) {
|
||||
_pimpl->AsyncCall("set_weather", weather);
|
||||
}
|
||||
|
||||
SharedPtr<Actor> Client::SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const geom::Transform &transform,
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "carla/client/detail/Episode.h"
|
||||
#include "carla/geom/Transform.h"
|
||||
#include "carla/profiler/LifetimeProfiled.h"
|
||||
#include "carla/rpc/WeatherParameters.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
@ -63,6 +64,10 @@ namespace detail {
|
|||
|
||||
SharedPtr<Actor> GetSpectator();
|
||||
|
||||
rpc::WeatherParameters GetWeatherParameters();
|
||||
|
||||
void SetWeatherParameters(const rpc::WeatherParameters &weather);
|
||||
|
||||
SharedPtr<Actor> SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const geom::Transform &transform,
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
|
||||
#include "carla/MsgPack.h"
|
||||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
# include "Carla/Vehicle/VehicleControl.h"
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
namespace carla {
|
||||
namespace rpc {
|
||||
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright (c) 2017 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/MsgPack.h"
|
||||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
# include "Carla/Weather/WeatherParameters.h"
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
namespace carla {
|
||||
namespace rpc {
|
||||
|
||||
class WeatherParameters {
|
||||
public:
|
||||
|
||||
WeatherParameters() = default;
|
||||
|
||||
WeatherParameters(
|
||||
float in_cloudyness,
|
||||
float in_precipitation,
|
||||
float in_precipitation_deposits,
|
||||
float in_wind_intensity,
|
||||
float in_sun_azimuth_angle,
|
||||
float in_sun_altitude_angle)
|
||||
: cloudyness(in_cloudyness),
|
||||
precipitation(in_precipitation),
|
||||
precipitation_deposits(in_precipitation_deposits),
|
||||
wind_intensity(in_wind_intensity),
|
||||
sun_azimuth_angle(in_sun_azimuth_angle),
|
||||
sun_altitude_angle(in_sun_altitude_angle) {}
|
||||
|
||||
float cloudyness = 0.0f;
|
||||
float precipitation = 0.0f;
|
||||
float precipitation_deposits = 0.0f;
|
||||
float wind_intensity = 0.0f;
|
||||
float sun_azimuth_angle = 0.0f;
|
||||
float sun_altitude_angle = 0.0f;
|
||||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
WeatherParameters(const FWeatherParameters &Weather)
|
||||
: cloudyness(Weather.Cloudyness),
|
||||
precipitation(Weather.Precipitation),
|
||||
precipitation_deposits(Weather.PrecipitationDeposits),
|
||||
wind_intensity(Weather.WindIntensity),
|
||||
sun_azimuth_angle(Weather.SunAzimuthAngle),
|
||||
sun_altitude_angle(Weather.SunAltitudeAngle) {}
|
||||
|
||||
operator FWeatherParameters() const {
|
||||
FWeatherParameters Weather;
|
||||
Weather.Cloudyness = cloudyness;
|
||||
Weather.Precipitation = precipitation;
|
||||
Weather.PrecipitationDeposits = precipitation_deposits;
|
||||
Weather.WindIntensity = wind_intensity;
|
||||
Weather.SunAzimuthAngle = sun_azimuth_angle;
|
||||
Weather.SunAltitudeAngle = sun_altitude_angle;
|
||||
return Weather;
|
||||
}
|
||||
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
bool operator!=(const WeatherParameters &rhs) const {
|
||||
return
|
||||
cloudyness != rhs.cloudyness ||
|
||||
precipitation != rhs.precipitation ||
|
||||
precipitation_deposits != rhs.precipitation_deposits ||
|
||||
wind_intensity != rhs.wind_intensity ||
|
||||
sun_azimuth_angle != rhs.sun_azimuth_angle ||
|
||||
sun_altitude_angle != rhs.sun_altitude_angle;
|
||||
}
|
||||
|
||||
bool operator==(const WeatherParameters &rhs) const {
|
||||
return !(*this != rhs);
|
||||
}
|
||||
|
||||
MSGPACK_DEFINE_ARRAY(
|
||||
cloudyness,
|
||||
precipitation,
|
||||
precipitation_deposits,
|
||||
wind_intensity,
|
||||
sun_azimuth_angle,
|
||||
sun_altitude_angle);
|
||||
};
|
||||
|
||||
} // namespace rpc
|
||||
} // namespace carla
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) 2017 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>.
|
||||
|
||||
#include <carla/rpc/WeatherParameters.h>
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace carla {
|
||||
namespace rpc {
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const WeatherParameters &weather) {
|
||||
out << "WeatherParameters(cloudyness=" << weather.cloudyness
|
||||
<< ", precipitation=" << weather.precipitation
|
||||
<< ", precipitation_deposits=" << weather.precipitation_deposits
|
||||
<< ", wind_intensity=" << weather.wind_intensity
|
||||
<< ", sun_azimuth_angle=" << weather.sun_azimuth_angle
|
||||
<< ", sun_altitude_angle=" << weather.sun_altitude_angle << ')';
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace rpc
|
||||
} // namespace carla
|
||||
|
||||
void export_weather() {
|
||||
using namespace boost::python;
|
||||
namespace cr = carla::rpc;
|
||||
|
||||
class_<cr::WeatherParameters>("WeatherParameters")
|
||||
.def(init<float, float, float, float, float, float>(
|
||||
(arg("cloudyness")=0.0f,
|
||||
arg("precipitation")=0.0f,
|
||||
arg("precipitation_deposits")=0.0f,
|
||||
arg("wind_intensity")=0.0f,
|
||||
arg("sun_azimuth_angle")=0.0f,
|
||||
arg("sun_altitude_angle")=0.0f)))
|
||||
.def_readwrite("cloudyness", &cr::WeatherParameters::cloudyness)
|
||||
.def_readwrite("precipitation", &cr::WeatherParameters::precipitation)
|
||||
.def_readwrite("precipitation_deposits", &cr::WeatherParameters::precipitation_deposits)
|
||||
.def_readwrite("wind_intensity", &cr::WeatherParameters::wind_intensity)
|
||||
.def_readwrite("sun_azimuth_angle", &cr::WeatherParameters::sun_azimuth_angle)
|
||||
.def_readwrite("sun_altitude_angle", &cr::WeatherParameters::sun_altitude_angle)
|
||||
.def("__eq__", &cr::WeatherParameters::operator==)
|
||||
.def("__ne__", &cr::WeatherParameters::operator!=)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
}
|
|
@ -26,6 +26,8 @@ void export_world() {
|
|||
class_<cc::World>("World", no_init)
|
||||
.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))
|
||||
.def("set_weather", &cc::World::SetWeather)
|
||||
.def("try_spawn_actor", SPAWN_ACTOR_WITHOUT_GIL(TrySpawnActor))
|
||||
.def("spawn_actor", SPAWN_ACTOR_WITHOUT_GIL(SpawnActor))
|
||||
;
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "Sensor.cpp"
|
||||
#include "SensorData.cpp"
|
||||
#include "Transform.cpp"
|
||||
#include "Weather.cpp"
|
||||
#include "World.cpp"
|
||||
|
||||
BOOST_PYTHON_MODULE(libcarla) {
|
||||
|
@ -49,6 +50,7 @@ BOOST_PYTHON_MODULE(libcarla) {
|
|||
export_actor();
|
||||
export_sensor();
|
||||
export_sensor_data();
|
||||
export_weather();
|
||||
export_world();
|
||||
export_client();
|
||||
export_exception();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Carla/Actor/ActorDispatcher.h"
|
||||
#include "Carla/Weather/Weather.h"
|
||||
|
||||
#include "CarlaEpisode.generated.h"
|
||||
|
||||
|
@ -20,13 +21,6 @@ class CARLA_API UCarlaEpisode : public UObject
|
|||
|
||||
public:
|
||||
|
||||
void SetMapName(const FString &InMapName)
|
||||
{
|
||||
MapName = InMapName;
|
||||
}
|
||||
|
||||
void InitializeAtBeginPlay();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
const FString &GetMapName() const
|
||||
{
|
||||
|
@ -39,9 +33,10 @@ public:
|
|||
return Spectator;
|
||||
}
|
||||
|
||||
void RegisterActorFactory(ACarlaActorFactory &ActorFactory)
|
||||
UFUNCTION(BlueprintCallable)
|
||||
AWeather *GetWeather() const
|
||||
{
|
||||
ActorDispatcher.Bind(ActorFactory);
|
||||
return Weather;
|
||||
}
|
||||
|
||||
/// Return the list of actor definitions that are available to be spawned this
|
||||
|
@ -93,6 +88,15 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
friend class ATheNewCarlaGameModeBase;
|
||||
|
||||
void InitializeAtBeginPlay();
|
||||
|
||||
void RegisterActorFactory(ACarlaActorFactory &ActorFactory)
|
||||
{
|
||||
ActorDispatcher.Bind(ActorFactory);
|
||||
}
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
FString MapName;
|
||||
|
||||
|
@ -100,4 +104,7 @@ private:
|
|||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
APawn *Spectator = nullptr;
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
AWeather *Weather = nullptr;
|
||||
};
|
||||
|
|
|
@ -32,7 +32,10 @@ void ATheNewCarlaGameModeBase::InitGame(
|
|||
checkf(
|
||||
Episode != nullptr,
|
||||
TEXT("Missing episode, can't continue without an episode!"));
|
||||
Episode->SetMapName(MapName);
|
||||
Episode->MapName = MapName;
|
||||
|
||||
auto World = GetWorld();
|
||||
check(World != nullptr);
|
||||
|
||||
GameInstance = Cast<UCarlaGameInstance>(GetGameInstance());
|
||||
checkf(
|
||||
|
@ -40,12 +43,20 @@ void ATheNewCarlaGameModeBase::InitGame(
|
|||
TEXT("GameInstance is not a UCarlaGameInstance, did you forget to set it in the project settings?"));
|
||||
|
||||
if (TaggerDelegate != nullptr) {
|
||||
check(GetWorld() != nullptr);
|
||||
TaggerDelegate->RegisterSpawnHandler(GetWorld());
|
||||
TaggerDelegate->RegisterSpawnHandler(World);
|
||||
} else {
|
||||
UE_LOG(LogCarla, Error, TEXT("Missing TaggerDelegate!"));
|
||||
}
|
||||
|
||||
if (WeatherClass != nullptr)
|
||||
{
|
||||
Episode->Weather = World->SpawnActor<AWeather>(WeatherClass);
|
||||
// Apply default weather.
|
||||
Episode->Weather->ApplyWeather(FWeatherParameters());
|
||||
} else {
|
||||
UE_LOG(LogCarla, Error, TEXT("Missing weather class!"));
|
||||
}
|
||||
|
||||
SpawnActorFactories();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "Carla/Actor/CarlaActorFactory.h"
|
||||
#include "Carla/Game/CarlaEpisode.h"
|
||||
#include "Carla/Game/CarlaGameInstance.h"
|
||||
#include "Carla/Weather/Weather.h"
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
|
@ -50,9 +51,13 @@ private:
|
|||
UPROPERTY()
|
||||
UCarlaEpisode *Episode = nullptr;
|
||||
|
||||
/// The class of Weather to spawn.
|
||||
UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
|
||||
TSubclassOf<AWeather> WeatherClass;
|
||||
|
||||
/// List of actor spawners that will be used to define and spawn the actors
|
||||
/// available in game.
|
||||
UPROPERTY(EditAnywhere)
|
||||
UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
|
||||
TSet<TSubclassOf<ACarlaActorFactory>> ActorFactories;
|
||||
|
||||
UPROPERTY()
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <carla/rpc/Server.h>
|
||||
#include <carla/rpc/Transform.h>
|
||||
#include <carla/rpc/VehicleControl.h>
|
||||
#include <carla/rpc/WeatherParameters.h>
|
||||
#include <carla/streaming/Server.h>
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
|
@ -148,6 +149,24 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
return ActorView;
|
||||
});
|
||||
|
||||
Server.BindSync("get_weather", [this]() -> cr::WeatherParameters {
|
||||
RequireEpisode();
|
||||
auto *Weather = Episode->GetWeather();
|
||||
if (Weather == nullptr) {
|
||||
RespondErrorStr("unable to find weather");
|
||||
}
|
||||
return Weather->GetCurrentWeather();
|
||||
});
|
||||
|
||||
Server.BindSync("set_weather", [this](const cr::WeatherParameters &weather) {
|
||||
RequireEpisode();
|
||||
auto *Weather = Episode->GetWeather();
|
||||
if (Weather == nullptr) {
|
||||
RespondErrorStr("unable to find weather");
|
||||
}
|
||||
Weather->ApplyWeather(weather);
|
||||
});
|
||||
|
||||
Server.BindSync("spawn_actor", [this](
|
||||
const cr::Transform &Transform,
|
||||
cr::ActorDescription Description) -> cr::Actor {
|
||||
|
|
|
@ -14,7 +14,7 @@ struct CARLA_API FWeatherParameters
|
|||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0", UIMin = "0.0", UIMax = "100.0"))
|
||||
float Cloudyness = 0.0f;
|
||||
float Cloudyness = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0", UIMin = "0.0", UIMax = "100.0"))
|
||||
float Precipitation = 0.0f;
|
||||
|
@ -29,5 +29,5 @@ struct CARLA_API FWeatherParameters
|
|||
float SunAzimuthAngle = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "-90.0", ClampMax = "90.0", UIMin = "-90.0", UIMax = "90.0"))
|
||||
float SunAltitudeAngle = 0.0f;
|
||||
float SunAltitudeAngle = 70.0f;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue