Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Examples/CppClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(example)
link_directories(
${RPCLIB_LIB_PATH})

file(GLOB example_sources "main.cpp" "*.h")
file(GLOB example_sources "basic_usage.cpp" "*.h")

file(GLOB example_client_sources "")

Expand All @@ -22,18 +22,19 @@ foreach(target ${build_targets})

target_include_directories(${target} SYSTEM PRIVATE
"../../LibCarla/source"
"../../Build/debug/boost-1.86.0-install/include"
"../../Build/debug/rpclib-install/include/"
"../../Build/debug/recast-install/include/"
"../../PythonAPI/carla/dependencies/include" # 瑙e喅锛氭棤娉曟墦寮� 婧� 鏂囦欢 "carla/client/ActorBlueprint.h"
"../../Build/boost-1.86.0-install/include"
"../../Build/rpclib-install/include/"
"../../Build/recast-install/include/"
"../../Build/zlib-install/include/"
"../../Build/libpng-1.2.37-install/include/"
"../../LibCarla/source/third-party/")

# 涓虹壒瀹氱殑鐩爣锛堝彲鎵ц鏂囦欢鎴栧簱锛夋寚瀹氶摼鎺ュ櫒鎼滅储搴撴枃浠剁殑鐩綍
target_link_directories(${target} PRIVATE
"../../Build/debug/boost-1.86.0-install/lib"
"../../Build/debug/rpclib-install/lib/"
"../../Build/debug/recast-install/lib/"
"../../Build/boost-1.86.0-install/lib"
"../../Build/rpclib-install/lib/"
"../../Build/recast-install/lib/"
"../../PythonAPI/carla/dependencies/lib/" # 涓轰簡瀵煎叆 carla_client_debug.lib
"../../Build/zlib-install/lib/"
"../../Build/libcarla-visualstudio/LibCarla/cmake/client/Debug/"
Expand Down
104 changes: 104 additions & 0 deletions Examples/CppClient/basic_usage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// 参考:https://zhuanlan.zhihu.com/p/663460928
#include <sstream>
#include <string>
#include <thread>
#include <tuple>

// 注意:hutb\Unreal\CarlaUE4\Plugins\Carla\CarlaDependencies\include\carla 不存在 carla/client 目录
#include <carla/client/ActorBlueprint.h>
#include <carla/client/BlueprintLibrary.h>
#include <carla/client/Client.h>
#include <carla/client/Sensor.h>
#include <carla/client/TimeoutException.h>
#include <carla/client/World.h>
#include <carla/geom/Transform.h>
#include <carla/actors/BlueprintLibrary.h>

using namespace std;
using namespace carla;

static auto ParseArguments(int argc, const char* argv[])
{
// EXPECT_TRUE((argc == 1u) || (argc == 3u));
using ResultType = std::tuple<std::string, uint16_t>;
return argc == 3u ? ResultType{ argv[1u], std::stoi(argv[2u]) } : ResultType{ "localhost", 2000u };
}

int main(int argc, const char* argv[])
{
try
{
std::string host;
uint16_t port;
std::tie(host, port) = ParseArguments(argc, argv);

client::Client client = client::Client(host, port);
client.SetTimeout(40s);

std::cout << "Client API version : " << client.GetClientVersion() << "\n";
std::cout << "Server API version : " << client.GetServerVersion() << '\n';
// 导入地图
std::string town_name = "HutbCarlaCity";
client::World world = client.LoadWorld(town_name);

// 创建Waypoint。在Town05中,每隔2米获取一个Waypoint
SharedPtr<client::Map> map = world.GetMap();
std::vector<SharedPtr<client::Waypoint>> way_point = map->GenerateWaypoints(2);

// 获取推荐的车辆其实位置
std::vector<geom::Transform> spawn_point = map->GetRecommendedSpawnPoints();

// 构建汽车对象
// 获取这张地图中所有实物的蓝图
SharedPtr<actors::BlueprintLibrary> blueprint_library = world.GetBlueprintLibrary();
// 获取汽车的蓝图并指定其颜色
actors::ActorBlueprint vehile_bp = *blueprint_library->Find("vehicle.tesla.model3");
vehile_bp.SetAttribute("color", "255,255,255");
std::vector<geom::Transform> recommend_points = map->GetRecommendedSpawnPoints();
// 在推荐点中选取一点生成汽车
SharedPtr<client::Actor> actor = world.SpawnActor(vehile_bp, recommend_points[300]);
SharedPtr<client::Vehicle> vehicle = boost::static_pointer_cast<client::Vehicle>(actor);

// 切换视角查看生成的汽车
geom::Transform view_transform = recommend_points[300];
SharedPtr<client::Actor> spectator = world.GetSpectator();
view_transform.location -= 5.0f * view_transform.GetForwardVector();
view_transform.location.z += 3.0f;
view_transform.rotation.yaw += 0.0f;
view_transform.rotation.pitch = -15.0f;
spectator->SetTransform(view_transform);


// 参考:https://zhuanlan.zhihu.com/p/663726656
// 踩油门
// client::Vehicle::Control control;
// control.throttle = 0.3;
// while (true)
// {
// vehicle->ApplyControl(control);
// }
// 除了油门,还可以控制刹车、方向盘、传动比、手刹等
// control.brake = 0.1;
// control.steer = 0.02;
// control.gear = 2;
// control.hand_brake = true;

// 速度加速度:AckermanControl

// 自动驾驶
vehicle->SetAutopilot(true);


}
catch (const client::TimeoutException& e)
{
std::cout << '\n' << e.what() << std::endl;
return 1;
}
catch (const std::exception& e)
{
std::cout << "\nException: " << e.what() << std::endl;
return 2;
}

}
2 changes: 1 addition & 1 deletion Examples/CppClient/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(int argc, const char *argv[]) {
std::cout << "Server API version : " << client.GetServerVersion() << '\n';

// Load town
auto world = client.LoadWorld("Town10HD");
auto world = client.LoadWorld("HutbCarlaCity");

// Get a random vehicle blueprint.
auto blueprint_library = world.GetBlueprintLibrary();
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MIT License

Copyright (c) 2026 OpenHUTB
Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma de
Barcelona (UAB).

Expand Down
2 changes: 1 addition & 1 deletion LibCarla/cmake/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ install(DIRECTORY "${RPCLIB_INCLUDE_PATH}/rpc" DESTINATION include/system)
file(GLOB libcarla_carla_rpclib "${RPCLIB_LIB_PATH}/*.*")
install(FILES ${libcarla_carla_rpclib} DESTINATION lib)

# Install boost headers (install in system folder to avoid extra warnings).
# Install boost headers (install in system folder to avoid extra warnings). prevent printed message too long.
# @todo Remove boost from public interface of LibCarla.client.
install(DIRECTORY "${BOOST_INCLUDE_PATH}/boost" DESTINATION include/system)
file(GLOB boost_libraries "${BOOST_LIB_PATH}/*.*")
Expand Down
2 changes: 1 addition & 1 deletion LibCarla/cmake/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ foreach(dir ""

endforeach()

# Install boost headers and libraries.
# Install boost headers and libraries. Prevent printed message too long.
install(DIRECTORY "${BOOST_INCLUDE_PATH}/boost" DESTINATION include)

if(WIN32)
Expand Down
15 changes: 15 additions & 0 deletions LibCarla/source/carla/Version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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

namespace carla {

constexpr const char *version() {
return "${CARLA_VERSION}";
}

} // namespace carla
7 changes: 7 additions & 0 deletions LibCarla/source/carla/trafficmanager/InMemoryMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ namespace traffic_manager {
void InMemoryMap::SetUp() {

// 1. Building segment topology (i.e., defining set of segment predecessors and successors)
log_warning("1. Building segment topology (i.e., defining set of segment predecessors and successors)...");
assert(_world_map != nullptr && "No map reference found.");
auto waypoint_topology = _world_map->GetTopology();

Expand Down Expand Up @@ -227,6 +228,7 @@ namespace traffic_manager {
}

// 2. Consuming the raw dense topology from cc::Map into SimpleWaypoints.
log_warning("2. Consuming the raw dense topology from cc::Map into SimpleWaypoints....");
SegmentMap segment_map;
assert(_world_map != nullptr && "No map reference found.");
auto raw_dense_topology = _world_map->GenerateWaypoints(MAP_RESOLUTION);
Expand All @@ -238,6 +240,7 @@ namespace traffic_manager {
}

// 3. Processing waypoints.
log_warning("3. Processing waypoints....");
auto distance_squared = [](cg::Location l1, cg::Location l2) {
return cg::Math::DistanceSquared(l1, l2);
};
Expand Down Expand Up @@ -434,6 +437,10 @@ namespace traffic_manager {
}
junction_end_waypoint = temp.front();
}
// Skip if traversed_waypoints is empty to avoid front() on empty vector
if (traversed_waypoints.empty()) {
continue;
}

// Calculate the angle between the first and the last point of the junction.
int16_t current_angle = static_cast<int16_t>(traversed_waypoints.front()->GetTransform().rotation.yaw);
Expand Down
20 changes: 16 additions & 4 deletions Unreal/CarlaUE4/Config/DefaultGame.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ bCompressed=False
bEncryptIniFiles=False
bEncryptPakIndex=False
bSkipEditorContent=False
bNativizeBlueprintAssets=False
bNativizeOnlySelectedBlueprints=False
+MapsToCook=(FilePath="/Game/Carla/Maps/Town01")
+MapsToCook=(FilePath="/Game/Carla/Maps/Town01_Opt")
+MapsToCook=(FilePath="/Game/Carla/Maps/Town02")
Expand All @@ -73,6 +75,12 @@ bSkipEditorContent=False
+MapsToCook=(FilePath="/Game/Carla/Maps/Town12/Town12")
+MapsToCook=(FilePath="/Game/Carla/Maps/Town13/Town13")
+MapsToCook=(FilePath="/Game/Carla/Maps/Town15/Town15")
; 鎵撳寘 HUTB 鍦板浘
+MapsToCook=(FilePath="/Game/Carla/RoadRunner/Maps/HutbCarlaCity")
+DirectoriesToAlwaysCook=(Path="/Game/Carla/RoadRunner/Static")
+DirectoriesToAlwaysCook=(Path="/Game/Carla/Static/Other")
+DirectoriesToAlwaysCook=(Path="/Game/Carla/Static/Bridge")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/RoadRunner/Maps/OpenDrive")
+DirectoriesToAlwaysCook=(Path="/AirSim/HUDAssets")
+DirectoriesToAlwaysCook=(Path="Carla/Static/GenericMaterials/Licenseplates/Textures")
+DirectoriesToAlwaysCook=(Path="Carla/Static/Car/4Wheeled/ParkedVehicles")
Expand All @@ -82,12 +90,12 @@ bSkipEditorContent=False
+DirectoriesToAlwaysCook=(Path="/Carla/PostProcessingMaterials")
+DirectoriesToAlwaysCook=(Path="/Game/StarterContent")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/OpenDrive")
; 澶у湴鍥剧殑鏉愯川
+DirectoriesToAlwaysCook=(Path="/Carla/Maps/Town15/DefaultMaterials")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/Nav")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/TM")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Config")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/Nav")
; 澶у湴鍥剧殑鏉愯川
+DirectoriesToAlwaysCook=(Path="/Carla/Maps/Town15/DefaultMaterials")
; 鎷疯礉澶у湴鍥剧儤鐒欐椂鍊欐墍缂哄皯鐨� OpenDrive, TM (Nav) 鏂囦欢澶�
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/Town11/OpenDrive")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/Town11/TM")
Expand All @@ -98,8 +106,12 @@ bSkipEditorContent=False
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/Town15/Nav")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/Town15/OpenDrive")
+DirectoriesToAlwaysStageAsUFS=(Path="Carla/Maps/Town15/TM")
bNativizeBlueprintAssets=False
bNativizeOnlySelectedBlueprints=False
; 涓數杞欢鍥祫浜�
+MapsToCook=(FilePath="/Game/roadrunner/map/baidutest2test")
+DirectoriesToAlwaysCook=(Path="/Game/roadrunner/static")
+DirectoriesToAlwaysCook=(Path="/Game/roadrunner/map")
+DirectoriesToAlwaysStageAsUFS=(Path="roadrunner/map/OpenDrive")
+DirectoriesToAlwaysStageAsUFS=(Path="roadrunner/ccsp")

[/Script/VRSSettingsEditor.VRSSettings]
vrs.EnableVRS=True
Expand Down
58 changes: 41 additions & 17 deletions Util/BuildTools/BuildCarlaUE4.bat
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,47 @@ echo %OPTIONAL_MODULES_TEXT% > "%ROOT_PATH%Unreal/CarlaUE4/Config/OptionalModule
if %BUILD_UE4_EDITOR% == true (
echo %FILE_N% Building Unreal Editor...

call "%UE4_ROOT%Engine\Build\BatchFiles\Build.bat"^
CarlaUE4Editor^
Win64^
Development^
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
if errorlevel 1 goto bad_exit

call "%UE4_ROOT%Engine\Build\BatchFiles\Build.bat"^
CarlaUE4^
Win64^
Development^
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
if errorlevel 1 goto bad_exit
if %IS_DEBUG% == true (
echo %FILE_N% Building Unreal Editor in debug mode...
call "%UE4_ROOT%Engine\Build\BatchFiles\Build.bat"^
CarlaUE4Editor^
Win64^
Debug^
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
if errorlevel 1 goto bad_exit

call "%UE4_ROOT%Engine\Build\BatchFiles\Build.bat"^
CarlaUE4^
Win64^
Debug^
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
if errorlevel 1 goto bad_exit
) else (
echo %FILE_N% Building Unreal Editor in release mode...
call "%UE4_ROOT%Engine\Build\BatchFiles\Build.bat"^
CarlaUE4Editor^
Win64^
Development^
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
if errorlevel 1 goto bad_exit

call "%UE4_ROOT%Engine\Build\BatchFiles\Build.bat"^
CarlaUE4^
Win64^
Development^
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
if errorlevel 1 goto bad_exit
)


)

rem Launch Carla Editor
Expand Down
Loading
Loading