Working on wheel physics and changed call from world to each actor

This commit is contained in:
Manish 2019-02-18 19:16:13 +01:00
parent 0c8839ccb6
commit f9255b9544
11 changed files with 173 additions and 29 deletions

View File

@ -47,5 +47,12 @@ namespace client {
return boost::static_pointer_cast<TrafficLight>(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

View File

@ -43,6 +43,9 @@ namespace client {
SharedPtr<TrafficLight> GetTrafficLight() const;
rpc::VehiclePhysicsControl GetPhysicsControl() const;
void SetPhysicsControl(const rpc::VehiclePhysicsControl &physics_control);
private:
Control _control;

View File

@ -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);
}

View File

@ -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);

View File

@ -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<geom::Location>& in_steering_curve
// const std::vector<WheelPhysicsControl> 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<geom::Location> GetTorqueCurve() const {
@ -62,6 +92,14 @@ namespace rpc {
torque_curve = in_torque_curve;
}
const std::vector<geom::Location> GetSteeringCurve() const {
return steering_curve;
}
void SetSteeringCurve(std::vector<geom::Location> &in_steering_curve) {
steering_curve = in_steering_curve;
}
std::vector<geom::Location> 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<geom::Location> steering_curve;
std::vector<WheelPhysicsControl> wheels;
#ifdef LIBCARLA_INCLUDED_FROM_UE4
VehiclePhysicsControl(const FVehiclePhysicsControl &Control) {
// Engine Setup
TArray<FRichCurveKey> CurveKeys = Control.TorqueCurve.GetCopyOfKeys();
for(int32 KeyIdx = 0; KeyIdx < CurveKeys.Num(); KeyIdx++)
TArray<FRichCurveKey> 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<FRichCurveKey> 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<WheelPhysicsControl>();
// 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<FWheelPhysicsControl> 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

View File

@ -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))
;

View File

@ -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<std::vector<carla::geom::Location>>();
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<carla::geom::Location> steering_curve;
auto length = boost::python::len(list);
for (auto i = 0u; i < length; ++i) {
steering_curve.push_back(boost::python::extract<carla::geom::Location &>(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_<cr::VehiclePhysicsControl>("VehiclePhysicsControl")
.def(init<std::vector<cg::Location>, float, float, float, float, float,
bool, float, float,
float, float, cg::Vector3D
float, float, cg::Vector3D,
std::vector<cg::Location>
>
((arg("torque_curve")=std::vector<cg::Location>(),
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<cg::Location>()
)))
.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)

View File

@ -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))

View File

@ -5,13 +5,15 @@
// For a copy, see <https://opensource.org/licenses/MIT>.
#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<FWheelPhysicsControl> 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;
}

View File

@ -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<FWheelPhysicsControl> Wheels;
};

View File

@ -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 <https://opensource.org/licenses/MIT>.
#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;
};