Merge branch 'xisco' of https://bitbucket.org/carla-cvc/carla-ue4-plugin into xisco
This commit is contained in:
commit
1c5b600be7
|
@ -10,9 +10,9 @@
|
|||
"DocsURL": "",
|
||||
"MarketplaceURL": "",
|
||||
"SupportURL": "",
|
||||
"CanContainContent": true,
|
||||
"CanContainContent": false,
|
||||
"IsBetaVersion": true,
|
||||
"Installed": false,
|
||||
"Installed": true,
|
||||
"Modules": [
|
||||
{
|
||||
"Name": "Carla",
|
||||
|
|
|
@ -7,27 +7,18 @@ public class Carla : ModuleRules
|
|||
{
|
||||
public Carla(TargetInfo Target)
|
||||
{
|
||||
string CarlaServerIncludePath = "CarlaServer/include";
|
||||
string CarlaServerLibPath = "CarlaServer/lib";
|
||||
|
||||
PublicIncludePaths.AddRange(
|
||||
new string[] {
|
||||
"Carla/Public",
|
||||
CarlaServerIncludePath
|
||||
// ... add public include paths required here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateIncludePaths.AddRange(
|
||||
new string[] {
|
||||
"Carla/Private",
|
||||
CarlaServerIncludePath
|
||||
// ... add other private include paths required here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
|
@ -36,7 +27,6 @@ public class Carla : ModuleRules
|
|||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
|
@ -49,7 +39,6 @@ public class Carla : ModuleRules
|
|||
}
|
||||
);
|
||||
|
||||
|
||||
DynamicallyLoadedModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
|
@ -57,14 +46,90 @@ public class Carla : ModuleRules
|
|||
}
|
||||
);
|
||||
|
||||
PublicAdditionalLibraries.AddRange(
|
||||
new string[]
|
||||
AddBoostDependency(Target);
|
||||
AddProtobufDependency(Target);
|
||||
AddCarlaServerDependency(Target);
|
||||
|
||||
if (Target.Platform == UnrealTargetPlatform.Linux)
|
||||
{
|
||||
// Fails to link the std libraries.
|
||||
PublicAdditionalLibraries.Add("stdc++");
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsWindows(TargetInfo Target)
|
||||
{
|
||||
return (Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32);
|
||||
}
|
||||
|
||||
private void AddBoostDependency(TargetInfo Target)
|
||||
{
|
||||
if (IsWindows(Target))
|
||||
{
|
||||
string BoostRoot = System.Environment.GetEnvironmentVariable("BOOST_ROOT");
|
||||
if (string.IsNullOrEmpty(BoostRoot) || !System.IO.Directory.Exists(BoostRoot))
|
||||
{
|
||||
Path.Combine(ModuleDirectory, "..", CarlaServerLibPath, "libcarla_server.a"),
|
||||
"boost_system",
|
||||
"protobuf"
|
||||
// ... add any modules that your module loads dynamically here ...
|
||||
throw new System.Exception("BOOST_ROOT is not defined, or points to a non-existant directory, please set this environment variable.");
|
||||
}
|
||||
);
|
||||
PrivateIncludePaths.Add(BoostRoot);
|
||||
|
||||
string BoostLib = Path.Combine(BoostRoot, "stage", "lib");
|
||||
if (!System.IO.Directory.Exists(BoostLib))
|
||||
{
|
||||
throw new System.Exception("Please build boost and make sure the libraries are at " + BoostLib + ". ");
|
||||
}
|
||||
bool found = System.IO.Directory.GetFiles(BoostLib, "libboost_system-*.lib").Length > 0;
|
||||
if (!found)
|
||||
{
|
||||
throw new System.Exception("Not finding libboost_system-*.lib in " + BoostLib + ".");
|
||||
}
|
||||
PublicLibraryPaths.Add(Path.Combine(BoostLib));
|
||||
}
|
||||
else
|
||||
{
|
||||
PublicAdditionalLibraries.Add("boost_system");
|
||||
}
|
||||
}
|
||||
|
||||
private void AddProtobufDependency(TargetInfo Target)
|
||||
{
|
||||
if (IsWindows(Target))
|
||||
{
|
||||
string ProtobufRoot = System.Environment.GetEnvironmentVariable("PROTOBUF_ROOT");
|
||||
if (string.IsNullOrEmpty(ProtobufRoot) || !System.IO.Directory.Exists(ProtobufRoot))
|
||||
{
|
||||
throw new System.Exception("PROTOBUF_ROOT is not defined, or points to a non-existant directory, please set this environment variable.");
|
||||
}
|
||||
PrivateIncludePaths.Add(Path.Combine(ProtobufRoot, "include"));
|
||||
PublicAdditionalLibraries.Add(Path.Combine(ProtobufRoot, "lib", "libprotobuf.lib"));
|
||||
}
|
||||
else
|
||||
{
|
||||
PublicAdditionalLibraries.Add("protobuf");
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCarlaServerDependency(TargetInfo Target)
|
||||
{
|
||||
string CarlaServerIncludePath;
|
||||
string CarlaServerLibPath;
|
||||
string CarlaServerLib;
|
||||
|
||||
if (IsWindows(Target))
|
||||
{
|
||||
CarlaServerIncludePath = "CarlaServer/include";
|
||||
CarlaServerLibPath = "CarlaServer/lib/Release";
|
||||
CarlaServerLib = Path.Combine(ModuleDirectory, "..", CarlaServerLibPath, "carla_server.lib");
|
||||
}
|
||||
else
|
||||
{
|
||||
CarlaServerIncludePath = "CarlaServer/include";
|
||||
CarlaServerLibPath = "CarlaServer/lib";
|
||||
CarlaServerLib = Path.Combine(ModuleDirectory, "..", CarlaServerLibPath, "libcarla_server.a");
|
||||
}
|
||||
|
||||
PublicIncludePaths.Add(CarlaServerIncludePath);
|
||||
PrivateIncludePaths.Add(CarlaServerIncludePath);
|
||||
PublicAdditionalLibraries.Add(CarlaServerLib);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,6 @@ static void SendReward(
|
|||
Set(reward.player_location, PlayerState.GetLocation());
|
||||
Set(reward.player_orientation, PlayerState.GetOrientation());
|
||||
Set(reward.player_acceleration, PlayerState.GetAcceleration());
|
||||
// Set(reward.player_acceleration, );
|
||||
Set(reward.forward_speed, PlayerState.GetForwardSpeed());
|
||||
Set(reward.collision_car, PlayerState.GetCollisionIntensityCars());
|
||||
Set(reward.collision_pedestrian, PlayerState.GetCollisionIntensityPedestrians());
|
||||
|
@ -108,7 +107,7 @@ static void SendReward(
|
|||
reward.image_height = Cameras[0u]->GetImageSizeY();
|
||||
}
|
||||
Set(reward.image_rgb_0, Cameras[0u]);
|
||||
Set(reward.image_rgb_1, Cameras[1u]);
|
||||
// Set(reward.image_rgb_1, Cameras[1u]);
|
||||
// Set(reward.image_depth_0, );
|
||||
// Set(reward.image_depth_1, );
|
||||
UE_LOG(LogCarla, Log, TEXT("Send reward"));
|
||||
|
@ -129,6 +128,18 @@ static void ReadControl(carla::CarlaServer &Server, ACarlaVehicleController &Pla
|
|||
}
|
||||
}
|
||||
|
||||
static void SetActorTransform(
|
||||
ACarlaVehicleController &Player,
|
||||
const TArray<FTransform> &AvailableStartTransforms,
|
||||
uint32 Index)
|
||||
{
|
||||
if (Index >= AvailableStartTransforms.Num()) {
|
||||
Index = 0u;
|
||||
}
|
||||
check(AvailableStartTransforms.Num() > 0);
|
||||
Player.SetActorTransform(AvailableStartTransforms[Index]);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// -- CarlaGameController ------------------------------------------------------
|
||||
// =============================================================================
|
||||
|
@ -136,11 +147,7 @@ static void ReadControl(carla::CarlaServer &Server, ACarlaVehicleController &Pla
|
|||
CarlaGameController::CarlaGameController() :
|
||||
Server(MakeUnique<carla::CarlaServer>(2001u, 2002u, 2000u)),
|
||||
Player(nullptr),
|
||||
Cameras({{nullptr}})
|
||||
{
|
||||
UE_LOG(LogCarla, Log, TEXT("Initializing CarlaServer"));
|
||||
Server->init(1u);
|
||||
}
|
||||
Cameras({{nullptr}}) {}
|
||||
|
||||
APlayerStart *CarlaGameController::ChoosePlayerStart(
|
||||
const TArray<APlayerStart *> &AvailableStartSpots)
|
||||
|
@ -179,20 +186,27 @@ void CarlaGameController::RegisterCaptureCamera(const ASceneCaptureCamera &Captu
|
|||
void CarlaGameController::Tick(float DeltaSeconds)
|
||||
{
|
||||
check(Player != nullptr);
|
||||
if (!Server->clientConnected() || !Server->serverConnected() || !Server->worldConnected())
|
||||
return;
|
||||
|
||||
uint32 StartIndex;
|
||||
if (bIsResetting) {
|
||||
if (bIsResetting || Server->needRestart()) {
|
||||
UE_LOG(LogCarla, Log, TEXT("Initializing CarlaServer"));
|
||||
Server->init(1u);
|
||||
UE_LOG(LogCarla, Log, TEXT("Resetting the world"));
|
||||
// Resetting the world.
|
||||
ReadSceneInit(*Server);
|
||||
SendSceneValues(*Server, AvailableStartTransforms);
|
||||
StartIndex = ReadEpisodeStart(*Server);
|
||||
Player->SetActorTransform(AvailableStartTransforms[StartIndex]);
|
||||
SetActorTransform(*Player, AvailableStartTransforms, StartIndex);
|
||||
Player->ResetPlayerState();
|
||||
Server->sendEndReset();
|
||||
bIsResetting = false;
|
||||
} else if (TryReadEpisodeStart(*Server, StartIndex)) {
|
||||
// Handle request for resetting the world.
|
||||
UE_LOG(LogCarla, Log, TEXT("Handle request for resetting the world"));
|
||||
Player->SetActorTransform(AvailableStartTransforms[StartIndex]);
|
||||
SetActorTransform(*Player, AvailableStartTransforms, StartIndex);
|
||||
Player->ResetPlayerState();
|
||||
Server->sendEndReset();
|
||||
} else {
|
||||
// Regular tick.
|
||||
|
|
|
@ -3,7 +3,34 @@
|
|||
#include "Carla.h"
|
||||
#include "CarlaPlayerState.h"
|
||||
|
||||
void RegisterCollision(AActor *Actor, FVector NormalImpulse)
|
||||
void ACarlaPlayerState::Reset()
|
||||
{
|
||||
|
||||
Super::Reset();
|
||||
CollisionIntensityCars = 0.0f;
|
||||
CollisionIntensityPedestrians = 0.0f;
|
||||
CollisionIntensityOther = 0.0f;
|
||||
}
|
||||
|
||||
void ACarlaPlayerState::CopyProperties(APlayerState *PlayerState)
|
||||
{
|
||||
Super::CopyProperties(PlayerState);
|
||||
if ((PlayerState != nullptr) && (this != PlayerState))
|
||||
{
|
||||
ACarlaPlayerState *Other = Cast<ACarlaPlayerState>(PlayerState);
|
||||
if (Other != nullptr)
|
||||
{
|
||||
Location = Other->Location;
|
||||
Orientation = Other->Orientation;
|
||||
Acceleration = Other->Acceleration;
|
||||
ForwardSpeed = Other->ForwardSpeed;
|
||||
CollisionIntensityCars = Other->CollisionIntensityCars;
|
||||
CollisionIntensityPedestrians = Other->CollisionIntensityPedestrians;
|
||||
CollisionIntensityOther = Other->CollisionIntensityOther;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ACarlaPlayerState::RegisterCollision(AActor */*Actor*/, FVector NormalImpulse)
|
||||
{
|
||||
CollisionIntensityOther += NormalImpulse.Size();
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ class CARLA_API ACarlaPlayerState : public APlayerState
|
|||
|
||||
public:
|
||||
|
||||
/// @todo ?
|
||||
// virtual void Reset();
|
||||
// virtual void CopyProperties(APlayerState *PlayerState);
|
||||
virtual void Reset() override;
|
||||
|
||||
virtual void CopyProperties(APlayerState *PlayerState) override;
|
||||
|
||||
void RegisterCollision(AActor *Actor, FVector NormalImpulse);
|
||||
|
||||
|
|
|
@ -92,9 +92,11 @@ void ACarlaVehicleController::Tick(float DeltaTime)
|
|||
|
||||
if (IsPossessingAVehicle()) {
|
||||
CarlaPlayerState->Location = GetVehicleLocation();
|
||||
const FVector PreviousSpeed = CarlaPlayerState->ForwardSpeed * CarlaPlayerState->Orientation;
|
||||
CarlaPlayerState->Orientation = GetVehicleOrientation();
|
||||
CarlaPlayerState->Acceleration = GetVehicleAcceleration();
|
||||
CarlaPlayerState->ForwardSpeed = GetVehicleForwardSpeed();
|
||||
const FVector CurrentSpeed = CarlaPlayerState->ForwardSpeed * CarlaPlayerState->Orientation;
|
||||
CarlaPlayerState->Acceleration = (CurrentSpeed - PreviousSpeed) / DeltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,10 +127,10 @@ FVector ACarlaVehicleController::GetVehicleOrientation() const
|
|||
return GetPawn()->GetTransform().GetRotation().GetForwardVector();
|
||||
}
|
||||
|
||||
FVector ACarlaVehicleController::GetVehicleAcceleration() const
|
||||
void ACarlaVehicleController::ResetPlayerState()
|
||||
{
|
||||
check(GetPawn() != nullptr);
|
||||
return {0.0f, 0.0f, 0.0f};
|
||||
check(CarlaPlayerState != nullptr);
|
||||
CarlaPlayerState->Reset();
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
|
@ -63,14 +63,13 @@ public:
|
|||
/// Orientation vector of the vehicle, pointing forward.
|
||||
FVector GetVehicleOrientation() const;
|
||||
|
||||
/// Acceleration vector of the vehicle.
|
||||
FVector GetVehicleAcceleration() const;
|
||||
|
||||
const ACarlaPlayerState &GetPlayerState() const
|
||||
{
|
||||
return *CarlaPlayerState;
|
||||
}
|
||||
|
||||
void ResetPlayerState();
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
/// @name Vehicle movement
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required (VERSION 2.6)
|
||||
cmake_minimum_required (VERSION 3.0.2)
|
||||
project (CarlaServer)
|
||||
|
||||
if (UNIX)
|
||||
|
@ -10,17 +10,23 @@ endif (UNIX)
|
|||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED 14)
|
||||
|
||||
# Boost configuration
|
||||
# Boost configuration.
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
find_package(Boost REQUIRED system date_time regex)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
# Protobuf.
|
||||
include(FindProtobuf)
|
||||
find_package(Protobuf REQUIRED)
|
||||
include_directories(${PROTOBUF_INCLUDE_DIR})
|
||||
if (UNIX)
|
||||
set(Protobuf_LIBRARIES ${Protobuf_LIBRARIES} protobuf)
|
||||
endif (UNIX)
|
||||
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||
|
||||
set(Protobuf_LIBRARY -lprotobuf)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}/source")
|
||||
|
||||
add_subdirectory(source/carla/server)
|
||||
|
|
|
@ -8,9 +8,9 @@ Building
|
|||
|
||||
#### Linux
|
||||
|
||||
Install boost, protobuf, and ninja.
|
||||
Install boost, protobuf, cmake and ninja.
|
||||
|
||||
$ sudo apt-get install libprotobuf-dev protobuf-compiler libboost-all-dev ninja-build
|
||||
$ sudo apt-get install libprotobuf-dev protobuf-compiler libboost-all-dev cmake ninja-build
|
||||
|
||||
Run make
|
||||
|
||||
|
@ -18,10 +18,23 @@ Run make
|
|||
|
||||
#### Windows
|
||||
|
||||
Install boost and protobuf.
|
||||
Install and compile [boost](http://www.boost.org/).
|
||||
|
||||
Install and compile [protobuf](https://developers.google.com/protocol-buffers/).
|
||||
While compiling protobuf, use `-Dprotobuf_MSVC_STATIC_RUNTIME=OFF` when calling
|
||||
CMake in order to use the static runtime library, otherwise may give errors
|
||||
while trying to link with CarlaServer.
|
||||
|
||||
CMake looks at the following environment variables
|
||||
|
||||
* `CMAKE_INCLUDE_PATH` should contain the protobuf include folder.
|
||||
* `CMAKE_LIBRARY_PATH` should contain "libprotobuf" "libprotobuf-lite" "liteprotoc" .lib files.
|
||||
* `BOOST_ROOT` root of the boost folder.
|
||||
|
||||
To generate the Visual Studio solution
|
||||
|
||||
$ make vsproject
|
||||
|
||||
The solution gets generated at `./build/CarlaServer.sln`.
|
||||
The solution gets generated at `./build/CarlaServer.sln`. Change the solution
|
||||
configuration to match protobuf (release, most probably). Don't forget to build
|
||||
the project INSTALL, it doesn't build when building the solution.
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include "carla/thread/AsyncReaderJobQueue.h"
|
||||
#include "carla/thread/AsyncWriterJobQueue.h"
|
||||
|
||||
#include "carla_protocol.pb.h"
|
||||
|
||||
class EpisodeReady;
|
||||
|
||||
namespace carla {
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace server {
|
|||
reward.set_speed(values.forward_speed);
|
||||
reward.set_timestamp(values.timestamp);
|
||||
|
||||
auto images = {values.image_rgb_0, values.image_rgb_1};
|
||||
auto images = {values.image_rgb_0/*, values.image_rgb_1*/};
|
||||
for (const std::vector<Color> &image : images) {
|
||||
std::vector<unsigned char> png_image;
|
||||
if (getPNGImage(image, values.image_width, values.image_height, png_image)) {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
syntax = "proto2";
|
||||
|
||||
// Client Messages
|
||||
message EpisodeStart {
|
||||
|
|
|
@ -1,8 +1,26 @@
|
|||
add_executable(test_async_server async_server.cpp)
|
||||
target_link_libraries(test_async_server carla_server ${CMAKE_THREAD_LIBS_INIT} ${Boost_DATE_TIME_LIBRARY} ${Boost_REGEX_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Protobuf_LIBRARY})
|
||||
target_link_libraries(test_async_server
|
||||
carla_server
|
||||
${Protobuf_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${Boost_DATE_TIME_LIBRARY}
|
||||
${Boost_REGEX_LIBRARY}
|
||||
${Boost_SYSTEM_LIBRARY})
|
||||
|
||||
add_executable(test_sync_server sync_server.cpp)
|
||||
target_link_libraries(test_sync_server carla_server ${CMAKE_THREAD_LIBS_INIT} ${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_REGEX_LIBRARY} ${Protobuf_LIBRARY})
|
||||
target_link_libraries(test_sync_server
|
||||
carla_server
|
||||
${Protobuf_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${Boost_DATE_TIME_LIBRARY}
|
||||
${Boost_REGEX_LIBRARY}
|
||||
${Boost_SYSTEM_LIBRARY})
|
||||
|
||||
add_executable(test_client client.cpp)
|
||||
target_link_libraries(test_client carla_server ${CMAKE_THREAD_LIBS_INIT} ${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_REGEX_LIBRARY} ${Protobuf_LIBRARY})
|
||||
target_link_libraries(test_client
|
||||
carla_server
|
||||
${Protobuf_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${Boost_DATE_TIME_LIBRARY}
|
||||
${Boost_REGEX_LIBRARY}
|
||||
${Boost_SYSTEM_LIBRARY})
|
||||
|
|
Loading…
Reference in New Issue