WIP : python wrapper for TrafficManager

This commit is contained in:
Praveen Kumar 2019-10-11 21:40:50 +05:30 committed by bernat
parent c51376bedc
commit eef5cd5276
2 changed files with 87 additions and 6 deletions

View File

@ -7,7 +7,11 @@ set(CMAKE_CXX_COMPILER /usr/bin/clang++-7)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC -O3 -g -fsanitize=address" CACHE STRING "" FORCE)
## Release options
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3 -DNDEBUG" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC -O3 -DNDEBUG" CACHE STRING "" FORCE)
# Scanning for python wrapper dependencies
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
set(CARLA_LOCATION $ENV{CARLA_LOCATION})
@ -16,6 +20,8 @@ include_directories(${CARLA_LOCATION}/LibCarla/source/)
include_directories(${CARLA_LOCATION}/Build/boost-1.69.0-c7-install/include)
include_directories(${CARLA_LOCATION}/Build/recast-cdce4e-c7-install/include)
include_directories(${CARLA_LOCATION}/Build/rpclib-v2.2.1_c2-c7-libstdcxx-install/include)
# Including python wrapper dependencies
include_directories(${PYTHON_INCLUDE_DIRS})
link_directories(${CARLA_LOCATION}/Build/boost-1.69.0-c7-install/lib)
link_directories(${CARLA_LOCATION}/Build/recast-cdce4e-c7-install/lib)
@ -23,12 +29,30 @@ link_directories(${CARLA_LOCATION}/Build/rpclib-v2.2.1_c2-c7-libstdcxx-install/l
link_directories(${CARLA_LOCATION}/PythonAPI/carla/dependencies/lib)
file(GLOB SOURCES ${CARLA_LOCATION}/TrafficManager/source/pipeline/*.cpp)
## Release executable
file(GLOB SOURCES_EXE ${CARLA_LOCATION}/TrafficManager/source/pipeline/executable/PipelineExecutable.cpp)
# file(GLOB SOURCES_EXE ${CARLA_LOCATION}/TrafficManager/source/pipeline/executable/PipelineExecutable.cpp)
## Debug executable
# file(GLOB SOURCES_EXE ${CARLA_LOCATION}/TrafficManager/source/test/Test.cpp)
add_library(pipeline ${SOURCES})
add_executable(traffic_manager ${SOURCES_EXE})
target_link_libraries(traffic_manager pipeline carla_client rpc pthread boost_system Detour DetourCrowd DetourTileCache Recast)
# Executable target
# add_executable(traffic_manager ${SOURCES_EXE})
# Python wrapper target
add_library(traffic_manager SHARED ${CARLA_LOCATION}/TrafficManager/source/pipeline/python/Wrapper.cpp)
# Linking executable target
# target_link_libraries(traffic_manager pipeline carla_client rpc pthread boost_system
# Detour DetourCrowd DetourTileCache Recast)
# Linking python wrapper
target_link_libraries(traffic_manager ${PYTHON_LIBRARIES}
pipeline carla_client rpc pthread boost_system boost_python27
Detour DetourCrowd DetourTileCache Recast)
# Setting target properties for python wrapper
set_target_properties(traffic_manager PROPERTIES SUFFIX .so)
set_target_properties(traffic_manager PROPERTIES PREFIX "")

View File

@ -1,10 +1,67 @@
#pragma once
#include <memory>
#include "carla/client/Client.h"
#include "boost/python.hpp"
#include "Pipeline.h"
namespace cc = carla::client;
using namespace boost::python;
namespace traffic_manager {
class TrafficManager {
private:
std::shared_ptr<Pipeline> pipeline;
cc::Client &client;
public:
TrafficManager (list &longitudinal_parameters,
list &longitudinal_highway_parameters,
list &lateral_parameters,
float urban_target_velocity,
float highway_target_velocity,
cc::Client &client):
client(client) {
std::vector<float> longitudinal_parameters_vector;
for (uint i = 0u; i < len(longitudinal_parameters); ++i) {
longitudinal_parameters_vector.push_back(
extract<double>(longitudinal_parameters[i]));
}
std::vector<float> longitudinal_highway_parameters_vector;
for (uint i = 0u; i < len(longitudinal_highway_parameters); ++i) {
longitudinal_highway_parameters_vector.push_back(
extract<double>(longitudinal_highway_parameters[i]));
}
std::vector<float> lateral_parameters_vector;
for (uint i = 0u; i < len(lateral_parameters); ++i) {
lateral_parameters_vector.push_back(
extract<double>(lateral_parameters[i]));
}
pipeline = std::make_shared<Pipeline>(longitudinal_parameters_vector,
longitudinal_highway_parameters_vector,
lateral_parameters_vector,
urban_target_velocity,
highway_target_velocity,
this->client);
};
};
}
BOOST_PYTHON_MODULE(traffic_manager) {
class_<traffic_manager::Pipeline>("traffic_manager", init<>());
}
class_<traffic_manager::TrafficManager, boost::noncopyable>(
"traffic_manager",
init<list&, list&, list&, float, float, cc::Client&>())
.def("register_vehicles", &traffic_manager::Pipeline::RegisterVehicles)
.def("unregister_vehicles", &traffic_manager::Pipeline::UnregisterVehicles)
.def("start", &traffic_manager::Pipeline::Start)
.def("stop", &traffic_manager::Pipeline::Stop);
}