Added tire stiffness forces to physics control

This commit is contained in:
Daniel Santos-Olivan 2021-04-21 18:45:36 +02:00 committed by bernat
parent 8c6288ea24
commit e3ba9e4940
4 changed files with 48 additions and 3 deletions

View File

@ -24,6 +24,9 @@ namespace rpc {
float in_radius,
float in_max_brake_torque,
float in_max_handbrake_torque,
float in_lat_stiff_max_load,
float in_lat_stiff_value,
float in_long_stiff_value,
geom::Vector3D in_position)
: tire_friction(in_tire_friction),
damping_rate(in_damping_rate),
@ -31,6 +34,9 @@ namespace rpc {
radius(in_radius),
max_brake_torque(in_max_brake_torque),
max_handbrake_torque(in_max_handbrake_torque),
lat_stiff_max_load(in_lat_stiff_max_load),
lat_stiff_value(in_lat_stiff_value),
long_stiff_value(in_long_stiff_value),
position(in_position) {}
float tire_friction = 2.0f;
@ -39,6 +45,9 @@ namespace rpc {
float radius = 30.0f;
float max_brake_torque = 1500.0f;
float max_handbrake_torque = 3000.0f;
float lat_stiff_max_load = 2.0f;
float lat_stiff_value = 17.0f;
float long_stiff_value = 1000.0f;
geom::Vector3D position = {0.0f, 0.0f, 0.0f};
bool operator!=(const WheelPhysicsControl &rhs) const {
@ -49,6 +58,9 @@ namespace rpc {
radius != rhs.radius ||
max_brake_torque != rhs.max_brake_torque ||
max_handbrake_torque != rhs.max_handbrake_torque ||
lat_stiff_max_load != rhs.lat_stiff_max_load ||
lat_stiff_value != rhs.lat_stiff_value ||
long_stiff_value != rhs.long_stiff_value ||
position != rhs.position;
}
@ -64,6 +76,9 @@ namespace rpc {
radius(Wheel.Radius),
max_brake_torque(Wheel.MaxBrakeTorque),
max_handbrake_torque(Wheel.MaxHandBrakeTorque),
lat_stiff_max_load(Wheel.LatStiffMaxLoad),
lat_stiff_value(Wheel.LatStiffValue),
long_stiff_value(Wheel.LongStiffValue),
position(Wheel.Position.X, Wheel.Position.Y, Wheel.Position.Z) {}
operator FWheelPhysicsControl() const {
@ -74,6 +89,9 @@ namespace rpc {
Wheel.Radius = radius;
Wheel.MaxBrakeTorque = max_brake_torque;
Wheel.MaxHandBrakeTorque = max_handbrake_torque;
Wheel.LatStiffMaxLoad = lat_stiff_max_load;
Wheel.LatStiffValue = lat_stiff_value;
Wheel.LongStiffValue = long_stiff_value;
Wheel.Position = {position.x, position.y, position.z};
return Wheel;
}
@ -85,6 +103,9 @@ namespace rpc {
radius,
max_brake_torque,
max_handbrake_torque,
lat_stiff_max_load,
lat_stiff_value,
long_stiff_value,
position)
};

View File

@ -62,6 +62,9 @@ namespace rpc {
<< ", radius=" << std::to_string(control.radius)
<< ", max_brake_torque=" << std::to_string(control.max_brake_torque)
<< ", max_handbrake_torque=" << std::to_string(control.max_handbrake_torque)
<< ", lat_stiff_max_load=" << std::to_string(control.lat_stiff_max_load)
<< ", lat_stiff_value=" << std::to_string(control.lat_stiff_value)
<< ", long_stiff_value=" << std::to_string(control.long_stiff_value)
<< ", position=" << control.position << ')';
return out;
}
@ -332,13 +335,16 @@ void export_control() {
;
class_<cr::WheelPhysicsControl>("WheelPhysicsControl")
.def(init<float, float, float, float, float, float, cg::Vector3D>(
.def(init<float, float, float, float, float, float, float, float, float, cg::Vector3D>(
(arg("tire_friction")=2.0f,
arg("damping_rate")=0.25f,
arg("max_steer_angle")=70.0f,
arg("radius")=30.0f,
arg("max_brake_torque")=1500.0f,
arg("max_handbrake_torque")=3000.0f,
arg("lat_stiff_max_load")=2.0f,
arg("lat_stiff_value")=17.0f,
arg("long_stiff_value")=1000.0f,
arg("position")=cg::Vector3D{0.0f, 0.0f, 0.0f})))
.def_readwrite("tire_friction", &cr::WheelPhysicsControl::tire_friction)
.def_readwrite("damping_rate", &cr::WheelPhysicsControl::damping_rate)
@ -346,6 +352,9 @@ void export_control() {
.def_readwrite("radius", &cr::WheelPhysicsControl::radius)
.def_readwrite("max_brake_torque", &cr::WheelPhysicsControl::max_brake_torque)
.def_readwrite("max_handbrake_torque", &cr::WheelPhysicsControl::max_handbrake_torque)
.def_readwrite("lat_stiff_max_load", &cr::WheelPhysicsControl::lat_stiff_max_load)
.def_readwrite("lat_stiff_value", &cr::WheelPhysicsControl::lat_stiff_value)
.def_readwrite("long_stiff_value", &cr::WheelPhysicsControl::long_stiff_value)
.def_readwrite("position", &cr::WheelPhysicsControl::position)
.def("__eq__", &cr::WheelPhysicsControl::operator==)
.def("__ne__", &cr::WheelPhysicsControl::operator!=)

View File

@ -309,14 +309,16 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl() const
FWheelPhysicsControl PhysicsWheel;
PxVehicleWheelData PWheelData = Vehicle4W->PVehicle->mWheelsSimData.getWheelData(i);
PhysicsWheel.TireFriction = Vehicle4W->Wheels[i]->TireConfig->GetFrictionScale();
PhysicsWheel.DampingRate = Cm2ToM2(PWheelData.mDampingRate);
PhysicsWheel.MaxSteerAngle = FMath::RadiansToDegrees(PWheelData.mMaxSteer);
PhysicsWheel.Radius = PWheelData.mRadius;
PhysicsWheel.MaxBrakeTorque = Cm2ToM2(PWheelData.mMaxBrakeTorque);
PhysicsWheel.MaxHandBrakeTorque = Cm2ToM2(PWheelData.mMaxHandBrakeTorque);
PhysicsWheel.TireFriction = Vehicle4W->Wheels[i]->TireConfig->GetFrictionScale();
PhysicsWheel.LatStiffMaxLoad = Vehicle4W->Wheels[i]->LatStiffMaxLoad;
PhysicsWheel.LatStiffValue = Vehicle4W->Wheels[i]->LatStiffValue;
PhysicsWheel.LongStiffValue = Vehicle4W->Wheels[i]->LongStiffValue;
PhysicsWheel.Position = Vehicle4W->Wheels[i]->Location;
Wheels.Add(PhysicsWheel);
@ -409,6 +411,10 @@ void ACarlaWheeledVehicle::ApplyVehiclePhysicsControl(const FVehiclePhysicsContr
UVehicleWheel *Wheel = NewWheelSetups[i].WheelClass.GetDefaultObject();
check(Wheel != nullptr);
Wheel->LatStiffMaxLoad = PhysicsControl.Wheels[i].LatStiffMaxLoad;
Wheel->LatStiffValue = PhysicsControl.Wheels[i].LatStiffValue;
Wheel->LongStiffValue = PhysicsControl.Wheels[i].LongStiffValue;
// Assigning new tire config
Wheel->TireConfig = DuplicateObject<UTireConfig>(Wheel->TireConfig, nullptr);

View File

@ -31,6 +31,15 @@ struct CARLA_API FWheelPhysicsControl
UPROPERTY(Category = "Wheel Max Handbrake Torque (Nm)", EditAnywhere, BlueprintReadWrite)
float MaxHandBrakeTorque = 3000.0f;
UPROPERTY(Category = "Max normalized tire load at which the tire can deliver no more lateral stiffness no matter how much extra load is applied to the tire", EditAnywhere, BlueprintReadWrite)
float LatStiffMaxLoad = 2.0f;
UPROPERTY(Category = "Lateral Stiffness Value", EditAnywhere, BlueprintReadWrite)
float LatStiffValue = 17.0f;
UPROPERTY(Category = "Longitudinal Stiffness Value", EditAnywhere, BlueprintReadWrite)
float LongStiffValue = 1000.0f;
UPROPERTY(Category = "Wheel Position", EditAnywhere, BlueprintReadWrite)
FVector Position = FVector::ZeroVector;
};