diff --git a/LibCarla/source/carla/client/Vehicle.cpp b/LibCarla/source/carla/client/Vehicle.cpp index a7f6b444c..a23e1cfc9 100644 --- a/LibCarla/source/carla/client/Vehicle.cpp +++ b/LibCarla/source/carla/client/Vehicle.cpp @@ -47,5 +47,12 @@ namespace client { return boost::static_pointer_cast(actor); } + rpc::VehiclePhysicsControl Vehicle::GetPhysicsControl() const { + return GetEpisode().Lock()->GetVehiclePhysicsControl(GetId()); + } + + void Vehicle::SetPhysicsControl(const rpc::VehiclePhysicsControl &physics_control) { + return GetEpisode().Lock()->SetVehiclePhysicsControl(GetId(), physics_control); + } } // namespace client } // namespace carla diff --git a/LibCarla/source/carla/client/Vehicle.h b/LibCarla/source/carla/client/Vehicle.h index e970dbb8f..aa3eeff2e 100644 --- a/LibCarla/source/carla/client/Vehicle.h +++ b/LibCarla/source/carla/client/Vehicle.h @@ -43,6 +43,9 @@ namespace client { SharedPtr GetTrafficLight() const; + rpc::VehiclePhysicsControl GetPhysicsControl() const; + + void SetPhysicsControl(const rpc::VehiclePhysicsControl &physics_control); private: Control _control; diff --git a/LibCarla/source/carla/client/World.cpp b/LibCarla/source/carla/client/World.cpp index 2d30cece8..6dca9b335 100644 --- a/LibCarla/source/carla/client/World.cpp +++ b/LibCarla/source/carla/client/World.cpp @@ -41,14 +41,6 @@ namespace client { return _episode.Lock()->GetWeatherParameters(); } - rpc::VehiclePhysicsControl World::GetVehiclePhysicsControl(const int &actor_id) const { - return _episode.Lock()->GetVehiclePhysicsControl(actor_id); - } - - void World::SetVehiclePhysicsControl(const int &actor_id, const rpc::VehiclePhysicsControl &physics_control) { - return _episode.Lock()->SetVehiclePhysicsControl(actor_id, physics_control); - } - void World::SetWeather(const rpc::WeatherParameters &weather) { _episode.Lock()->SetWeatherParameters(weather); } diff --git a/LibCarla/source/carla/client/World.h b/LibCarla/source/carla/client/World.h index 7e181f37a..ff1b74bfc 100644 --- a/LibCarla/source/carla/client/World.h +++ b/LibCarla/source/carla/client/World.h @@ -56,12 +56,6 @@ namespace client { /// Retrieve the weather parameters currently active in the world. rpc::WeatherParameters GetWeather() const; - /// Retrieve the physics control parameters of an actor. - rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const int &actor_id) const; - - /// Change vehicle physics control of an actors - void SetVehiclePhysicsControl(const int &actor_id, const rpc::VehiclePhysicsControl &physics_control); - /// Change the weather in the simulation. void SetWeather(const rpc::WeatherParameters &weather); diff --git a/LibCarla/source/carla/rpc/VehiclePhysicsControl.h b/LibCarla/source/carla/rpc/VehiclePhysicsControl.h index 0a805da5b..cebe57516 100644 --- a/LibCarla/source/carla/rpc/VehiclePhysicsControl.h +++ b/LibCarla/source/carla/rpc/VehiclePhysicsControl.h @@ -15,6 +15,31 @@ namespace carla { namespace rpc { + class WheelPhysicsControl { + public: + explicit WheelPhysicsControl() = default; + + explicit WheelPhysicsControl( + float in_tire_friction + ) { + tire_friction = in_tire_friction; + } + + float tire_friction; + + #ifdef LIBCARLA_INCLUDED_FROM_UE4 + WheelPhysicsControl(const FWheelPhysicsControl &Wheel) { + tire_friction = Wheel.TireFriction; + } + + operator FWheelPhysicsControl() const { + FWheelPhysicsControl Wheel; + Wheel.TireFriction = tire_friction; + return Wheel; + } + #endif + }; + class VehiclePhysicsControl { public: @@ -35,7 +60,9 @@ namespace rpc { float in_mass, float in_drag_coefficient, - geom::Vector3D in_inertia_tensor_scale + geom::Vector3D in_inertia_tensor_scale, + const std::vector& in_steering_curve + // const std::vector in_wheels ) { torque_curve = in_torque_curve; @@ -52,6 +79,9 @@ namespace rpc { mass = in_mass; drag_coefficient = in_drag_coefficient; inertia_tensor_scale = in_inertia_tensor_scale; + + steering_curve = in_steering_curve; + // wheels = in_wheels; } const std::vector GetTorqueCurve() const { @@ -62,6 +92,14 @@ namespace rpc { torque_curve = in_torque_curve; } + const std::vector GetSteeringCurve() const { + return steering_curve; + } + + void SetSteeringCurve(std::vector &in_steering_curve) { + steering_curve = in_steering_curve; + } + std::vector torque_curve; float max_rpm = 0.0f; float moi = 0.0f; @@ -76,16 +114,19 @@ namespace rpc { float mass = 0.0f; float drag_coefficient = 0.0f; geom::Vector3D inertia_tensor_scale; - + + std::vector steering_curve; + std::vector wheels; + #ifdef LIBCARLA_INCLUDED_FROM_UE4 VehiclePhysicsControl(const FVehiclePhysicsControl &Control) { // Engine Setup - TArray CurveKeys = Control.TorqueCurve.GetCopyOfKeys(); - for(int32 KeyIdx = 0; KeyIdx < CurveKeys.Num(); KeyIdx++) + TArray TorqueCurveKeys = Control.TorqueCurve.GetCopyOfKeys(); + for(int32 KeyIdx = 0; KeyIdx < TorqueCurveKeys.Num(); KeyIdx++) { - geom::Location point(CurveKeys[KeyIdx].Time, CurveKeys[KeyIdx].Value, 0.0f); - torque_curve.push_back(point); + geom::Location point(TorqueCurveKeys[KeyIdx].Time, TorqueCurveKeys[KeyIdx].Value, 0.0f); + torque_curve.push_back(point); } max_rpm = Control.MaxRPM; moi = Control.MOI; @@ -103,6 +144,18 @@ namespace rpc { drag_coefficient = Control.DragCoefficient; inertia_tensor_scale = Control.InertiaTensorScale; + TArray SteeringCurveKeys = Control.SteeringCurve.GetCopyOfKeys(); + for(int32 KeyIdx = 0; KeyIdx < SteeringCurveKeys.Num(); KeyIdx++) + { + geom::Location point(SteeringCurveKeys[KeyIdx].Time, SteeringCurveKeys[KeyIdx].Value, 0.0f); + steering_curve.push_back(point); + } + + // Wheels Setup + // wheels = std::vector(); + // for( auto Wheel : Control.Wheels) { + // wheels.push_back(WheelPhysicsControl(Wheel)); + // } } operator FVehiclePhysicsControl() const { @@ -110,9 +163,8 @@ namespace rpc { // Engine Setup FRichCurve TorqueCurve; - for (auto location : torque_curve) { - TorqueCurve.AddKey (location.x, location.y); - } + for (auto location : torque_curve) + TorqueCurve.AddKey (location.x, location.y); Control.TorqueCurve = TorqueCurve; Control.MaxRPM = max_rpm; Control.MOI = moi; @@ -130,6 +182,19 @@ namespace rpc { Control.DragCoefficient = drag_coefficient; Control.InertiaTensorScale = inertia_tensor_scale; + // Transmission Setup + FRichCurve SteeringCurve; + for (auto location : steering_curve) + SteeringCurve.AddKey (location.x, location.y); + Control.SteeringCurve = SteeringCurve; + + // Wheels Setup + // TArray Wheels; + // for (auto wheel : wheels) { + // Wheels.Add(FWheelPhysicsControl(wheel)); + // } + // Control.Wheels = Wheels; + return Control; } @@ -146,7 +211,9 @@ namespace rpc { clutch_strength, mass, drag_coefficient, - inertia_tensor_scale); + inertia_tensor_scale, + steering_curve + ); }; } // namespace rpc diff --git a/PythonAPI/source/libcarla/Actor.cpp b/PythonAPI/source/libcarla/Actor.cpp index 7375ce0f3..de0cb2a3a 100644 --- a/PythonAPI/source/libcarla/Actor.cpp +++ b/PythonAPI/source/libcarla/Actor.cpp @@ -81,6 +81,8 @@ void export_actor() { .def("get_traffic_light_state", &cc::Vehicle::GetTrafficLightState) .def("is_at_traffic_light", &cc::Vehicle::IsAtTrafficLight) .def("get_traffic_light", &cc::Vehicle::GetTrafficLight) + .def("get_physics_control", &cc::Vehicle::GetPhysicsControl) + .def("set_physics_control", &cc::Vehicle::SetPhysicsControl) .def(self_ns::str(self_ns::self)) ; diff --git a/PythonAPI/source/libcarla/Control.cpp b/PythonAPI/source/libcarla/Control.cpp index 7a85aa30c..2d19e37a6 100644 --- a/PythonAPI/source/libcarla/Control.cpp +++ b/PythonAPI/source/libcarla/Control.cpp @@ -73,6 +73,22 @@ static void SetTorqueCurve(carla::rpc::VehiclePhysicsControl &self, const boost: self.torque_curve = torque_curve; } +static auto GetSteeringCurve(const carla::rpc::VehiclePhysicsControl &self) { + const auto &steering_curve = self.GetSteeringCurve(); + boost::python::object get_iter = boost::python::iterator>(); + boost::python::object iter = get_iter(steering_curve); + return boost::python::list(steering_curve); +} + +static void SetSteeringCurve(carla::rpc::VehiclePhysicsControl &self, const boost::python::list &list) { + std::vector steering_curve; + auto length = boost::python::len(list); + for (auto i = 0u; i < length; ++i) { + steering_curve.push_back(boost::python::extract(list[i])); + } + self.steering_curve = steering_curve; +} + void export_control() { using namespace boost::python; namespace cr = carla::rpc; @@ -120,7 +136,8 @@ void export_control() { class_("VehiclePhysicsControl") .def(init, float, float, float, float, float, bool, float, float, - float, float, cg::Vector3D + float, float, cg::Vector3D, + std::vector > ((arg("torque_curve")=std::vector(), arg("max_rpm")=0.0f, @@ -133,9 +150,11 @@ void export_control() { arg("clutch_strength")=0.0f, arg("mass")=0.0f, arg("drag_coefficient")=0.0f, - arg("inertia_tensor_scale")=cg::Vector3D{1.0f, 0.0f, 0.0f} + arg("inertia_tensor_scale")=cg::Vector3D{1.0f, 0.0f, 0.0f}, + arg("steering_curve")=std::vector() ))) .add_property("torque_curve", &GetTorqueCurve, &SetTorqueCurve) + .add_property("steering_curve", &GetSteeringCurve, &SetSteeringCurve) .def_readwrite("max_rpm", &cr::VehiclePhysicsControl::max_rpm) .def_readwrite("moi", &cr::VehiclePhysicsControl::moi) .def_readwrite("damping_rate_full_throttle", &cr::VehiclePhysicsControl::damping_rate_full_throttle) diff --git a/PythonAPI/source/libcarla/World.cpp b/PythonAPI/source/libcarla/World.cpp index 05f5d57bf..202330786 100644 --- a/PythonAPI/source/libcarla/World.cpp +++ b/PythonAPI/source/libcarla/World.cpp @@ -92,8 +92,6 @@ void export_world() { .def("get_weather", CONST_CALL_WITHOUT_GIL(cc::World, GetWeather)) .def("set_weather", &cc::World::SetWeather) .def("get_actors", CONST_CALL_WITHOUT_GIL(cc::World, GetActors)) - .def("get_physics_control", &cc::World::GetVehiclePhysicsControl, (arg("actor_id"))) - .def("set_physics_control", &cc::World::SetVehiclePhysicsControl, (arg("actor_id"), arg("physics_control"))) .def("spawn_actor", SPAWN_ACTOR_WITHOUT_GIL(SpawnActor)) .def("try_spawn_actor", SPAWN_ACTOR_WITHOUT_GIL(TrySpawnActor)) .def("wait_for_tick", &WaitForTick, (arg("seconds")=10.0)) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index 55040bd05..10d008635 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -5,13 +5,15 @@ // For a copy, see . #include "Carla.h" +#include "TireConfig.h" #include "CarlaWheeledVehicle.h" +#include "VehicleWheel.h" #include "Agent/VehicleAgentComponent.h" #include "Components/BoxComponent.h" #include "Engine/CollisionProfile.h" - +#include "PhysicalMaterials/PhysicalMaterial.h" // ============================================================================= // -- Constructor and destructor ----------------------------------------------- // ============================================================================= @@ -157,6 +159,26 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl() PhysicsControl.DragCoefficient = Vehicle4W->DragCoefficient; PhysicsControl.InertiaTensorScale = Vehicle4W->InertiaTensorScale; + // Transmission Setup + PhysicsControl.SteeringCurve = Vehicle4W->SteeringCurve.EditorCurveData; + + // Wheels Setup + + // Friction Scale + // Enable AffectedByHandbrake + + TArray Wheels; + FWheelPhysicsControl Wheel; + Wheel.TireFriction = Vehicle4W->Wheels[0]->TireConfig->GetFrictionScale(); + Wheel.Torque = Vehicle4W->Wheels[0]->DebugWheelTorque; + Wheel.Mass = Vehicle4W->Wheels[0]->Mass; + Wheel.bDisableSteering = Vehicle4W->Wheels[0]->GetWheelSetup().bDisableSteering; + + UPhysicalMaterial* WheelPhysicalMaterial = Vehicle4W->Wheels[0]->GetContactSurfaceMaterial(); + Wheel.ContactSurfaceFriction = ( WheelPhysicalMaterial != nullptr) ? WheelPhysicalMaterial->Friction : 1.0f; + Wheels.Add(Wheel); + PhysicsControl.Wheels = Wheels; + return PhysicsControl; } @@ -187,4 +209,7 @@ void ACarlaWheeledVehicle::SetVehiclePhysicsControl(const FVehiclePhysicsControl Vehicle4W->Mass = PhysicsControl.Mass; Vehicle4W->DragCoefficient = PhysicsControl.DragCoefficient; Vehicle4W->InertiaTensorScale = PhysicsControl.InertiaTensorScale; + + // Transmission Setup + Vehicle4W->SteeringCurve.EditorCurveData = PhysicsControl.SteeringCurve; } \ No newline at end of file diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehiclePhysicsControl.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehiclePhysicsControl.h index 871c0756e..6ed4162df 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehiclePhysicsControl.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehiclePhysicsControl.h @@ -6,6 +6,7 @@ #pragma once +#include "Vehicle/WheelPhysicsControl.h" #include "VehiclePhysicsControl.generated.h" USTRUCT(BlueprintType) @@ -56,4 +57,9 @@ struct CARLA_API FVehiclePhysicsControl UPROPERTY(Category = "Vehicle Engine Physics Control", EditAnywhere, BlueprintReadWrite) FVector InertiaTensorScale; + // Steering Setup + FRichCurve SteeringCurve; + + // Wheels Setup + TArray Wheels; }; \ No newline at end of file diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheelPhysicsControl.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheelPhysicsControl.h new file mode 100644 index 000000000..2147215cc --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheelPhysicsControl.h @@ -0,0 +1,31 @@ +// 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 . + +#pragma once + +#include "WheelPhysicsControl.generated.h" + +USTRUCT(BlueprintType) +struct CARLA_API FWheelPhysicsControl +{ + GENERATED_BODY() + + UPROPERTY(Category = "Wheel Tire Friction", EditAnywhere, BlueprintReadWrite) + float TireFriction = 0.0f; + + UPROPERTY(Category = "Wheel Torque", EditAnywhere, BlueprintReadWrite) + float Torque = 0.0f; + + UPROPERTY(Category = "Wheel Mass", EditAnywhere, BlueprintReadWrite) + float Mass = 0.0f; + + UPROPERTY(Category = "Wheel Disable Steering", EditAnywhere, BlueprintReadWrite) + bool bDisableSteering = 0.0f; + + UPROPERTY(Category = "Wheel Contact Surface Friction", EditAnywhere, BlueprintReadWrite) + float ContactSurfaceFriction = 0.0f; + +}; \ No newline at end of file