From 3835de9b0d56097a01a4ced37397475cd9d23bd8 Mon Sep 17 00:00:00 2001 From: Daniel Santos-Olivan Date: Fri, 20 Nov 2020 16:15:28 +0100 Subject: [PATCH] Added sweep wheel option to VehiclePhysicsControl --- .../source/carla/rpc/VehiclePhysicsControl.h | 26 ++++++++++++++++--- PythonAPI/carla/source/libcarla/Control.cpp | 10 ++++--- .../Carla/Vehicle/VehiclePhysicsControl.h | 3 +++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/LibCarla/source/carla/rpc/VehiclePhysicsControl.h b/LibCarla/source/carla/rpc/VehiclePhysicsControl.h index f35fbc390..0c4422b53 100644 --- a/LibCarla/source/carla/rpc/VehiclePhysicsControl.h +++ b/LibCarla/source/carla/rpc/VehiclePhysicsControl.h @@ -41,7 +41,8 @@ namespace rpc { float in_drag_coefficient, geom::Location in_center_of_mass, const std::vector &in_steering_curve, - std::vector &in_wheels) + std::vector &in_wheels, + bool in_use_sweep_wheel_collision) : torque_curve(in_torque_curve), max_rpm(in_max_rpm), moi(in_moi), @@ -57,7 +58,8 @@ namespace rpc { drag_coefficient(in_drag_coefficient), center_of_mass(in_center_of_mass), steering_curve(in_steering_curve), - wheels(in_wheels) {} + wheels(in_wheels), + use_sweep_wheel_collision(in_use_sweep_wheel_collision) {} const std::vector &GetForwardGears() const { return forward_gears; @@ -91,6 +93,14 @@ namespace rpc { steering_curve = in_steering_curve; } + void SetUseSweepWheelCollision(bool in_sweep) { + use_sweep_wheel_collision = in_sweep; + } + + bool GetUseSweepWheelCollision() { + return use_sweep_wheel_collision; + } + std::vector torque_curve = {geom::Vector2D(0.0f, 500.0f), geom::Vector2D(5000.0f, 500.0f)}; float max_rpm = 5000.0f; float moi = 1.0f; @@ -111,6 +121,8 @@ namespace rpc { std::vector steering_curve = {geom::Vector2D(0.0f, 1.0f), geom::Vector2D(10.0f, 0.5f)}; std::vector wheels; + bool use_sweep_wheel_collision = false; + bool operator!=(const VehiclePhysicsControl &rhs) const { return max_rpm != rhs.max_rpm || @@ -129,7 +141,8 @@ namespace rpc { drag_coefficient != rhs.drag_coefficient || steering_curve != rhs.steering_curve || center_of_mass != rhs.center_of_mass || - wheels != rhs.wheels; + wheels != rhs.wheels || + use_sweep_wheel_collision != rhs.use_sweep_wheel_collision; } bool operator==(const VehiclePhysicsControl &rhs) const { @@ -180,6 +193,8 @@ namespace rpc { for (const auto &Wheel : Control.Wheels) { wheels.push_back(WheelPhysicsControl(Wheel)); } + + use_sweep_wheel_collision = Control.UseSweepWheelCollision; } operator FVehiclePhysicsControl() const { @@ -229,6 +244,8 @@ namespace rpc { } Control.Wheels = Wheels; + Control.UseSweepWheelCollision = use_sweep_wheel_collision; + return Control; } @@ -249,7 +266,8 @@ namespace rpc { drag_coefficient, center_of_mass, steering_curve, - wheels); + wheels, + use_sweep_wheel_collision); }; } // namespace rpc diff --git a/PythonAPI/carla/source/libcarla/Control.cpp b/PythonAPI/carla/source/libcarla/Control.cpp index c6af7568a..8a00bfee7 100644 --- a/PythonAPI/carla/source/libcarla/Control.cpp +++ b/PythonAPI/carla/source/libcarla/Control.cpp @@ -82,13 +82,13 @@ namespace rpc { << ", drag_coefficient=" << std::to_string(control.drag_coefficient) << ", center_of_mass=" << control.center_of_mass << ", steering_curve=" << control.steering_curve - << ", wheels=" << control.wheels << ')'; + << ", wheels=" << control.wheels + << ", use_sweep_wheel_collision=" << control.use_sweep_wheel_collision << ')'; return out; } } // namespace rpc } // namespace carla - static auto GetVectorOfVector2DFromList(const boost::python::list &list) { std::vector v; @@ -181,7 +181,7 @@ static void SetSteeringCurve(carla::rpc::VehiclePhysicsControl &self, const boos boost::python::object VehiclePhysicsControl_init(boost::python::tuple args, boost::python::dict kwargs) { // Args names - const uint32_t NUM_ARGUMENTS = 16; + const uint32_t NUM_ARGUMENTS = 17; const char *args_names[NUM_ARGUMENTS] = { "torque_curve", "max_rpm", @@ -201,7 +201,8 @@ boost::python::object VehiclePhysicsControl_init(boost::python::tuple args, boos "center_of_mass", "steering_curve", - "wheels" + "wheels", + "use_sweep_wheel_collision", }; boost::python::object self = args[0]; @@ -373,6 +374,7 @@ void export_control() { .def_readwrite("center_of_mass", &cr::VehiclePhysicsControl::center_of_mass) .add_property("steering_curve", &GetSteeringCurve, &SetSteeringCurve) .add_property("wheels", &GetWheels, &SetWheels) + .def_readwrite("use_sweep_wheel_collision", &cr::VehiclePhysicsControl::use_sweep_wheel_collision) .def("__eq__", &cr::VehiclePhysicsControl::operator==) .def("__ne__", &cr::VehiclePhysicsControl::operator!=) .def(self_ns::str(self_ns::self)) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehiclePhysicsControl.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehiclePhysicsControl.h index 2dd66624f..18890a545 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehiclePhysicsControl.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehiclePhysicsControl.h @@ -82,4 +82,7 @@ struct CARLA_API FVehiclePhysicsControl // Wheels Setup TArray Wheels; + + UPROPERTY(Category = "Vehicle Wheels Configuration", EditAnywhere, BlueprintReadWrite) + bool UseSweepWheelCollision = false; };