we can now set physics params of vehicles

This commit is contained in:
Manish 2019-02-18 11:39:32 +01:00
parent 6547535a71
commit 0c8839ccb6
9 changed files with 71 additions and 1 deletions

View File

@ -45,6 +45,10 @@ namespace client {
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

@ -59,6 +59,9 @@ namespace client {
/// 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

@ -124,6 +124,10 @@ namespace detail {
return _pimpl->CallAndWait<carla::rpc::VehiclePhysicsControl>("get_physics_control", actorId);
}
void Client::SetVehiclePhysicsControl(const int &actorId, const rpc::VehiclePhysicsControl &physicsControl) {
return _pimpl->AsyncCall("set_physics_control", actorId, physicsControl);
}
rpc::Actor Client::SpawnActor(
const rpc::ActorDescription &description,
const geom::Transform &transform) {

View File

@ -80,6 +80,8 @@ namespace detail {
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const int &actorId) const;
void SetVehiclePhysicsControl(const int &actorId, const rpc::VehiclePhysicsControl &physicsControl);
rpc::Actor SpawnActor(
const rpc::ActorDescription &description,
const geom::Transform &transform);

View File

@ -138,6 +138,10 @@ namespace detail {
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const int &actorId) const {
return _client.GetVehiclePhysicsControl(actorId);
}
void SetVehiclePhysicsControl(const int &actorId, const rpc::VehiclePhysicsControl &physicsControl) {
_client.SetVehiclePhysicsControl(actorId, physicsControl);
}
/// @}
// =========================================================================
/// @name General operations with actors

View File

@ -93,6 +93,7 @@ void export_world() {
.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

@ -388,6 +388,27 @@ void FTheNewCarlaServer::FPimpl::BindActions()
return cr::VehiclePhysicsControl(Vehicle->GetVehiclePhysicsControl());
});
Server.BindSync("set_physics_control", [this](
int ActorId, cr::VehiclePhysicsControl PhysicsControl) -> R<void>
{
REQUIRE_CARLA_EPISODE();
auto ActorView = Episode->FindActor(ActorId);
if (!ActorView.IsValid())
{
RESPOND_ERROR("unable to apply control: actor not found");
}
auto Vehicle = Cast<ACarlaWheeledVehicle>(ActorView.GetActor());
if (Vehicle == nullptr)
{
RESPOND_ERROR("unable to apply control: actor is not a vehicle");
}
Vehicle->SetVehiclePhysicsControl(FVehiclePhysicsControl(PhysicsControl));
return R<void>::Success();
});
Server.BindSync("set_actor_simulate_physics", [this](
cr::Actor Actor,
bool bEnabled) -> R<void>

View File

@ -159,3 +159,32 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl()
return PhysicsControl;
}
void ACarlaWheeledVehicle::SetVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl)
{
UCarlaWheeledVehicleMovementComponent4W *Vehicle4W = CastChecked<UCarlaWheeledVehicleMovementComponent4W>(GetVehicleMovement());
// Engine Setup
Vehicle4W->EngineSetup.TorqueCurve.EditorCurveData = PhysicsControl.TorqueCurve;
Vehicle4W->EngineSetup.MaxRPM = PhysicsControl.MaxRPM;
Vehicle4W->EngineSetup.MOI = PhysicsControl.MOI;
Vehicle4W->EngineSetup.DampingRateFullThrottle = PhysicsControl.DampingRateFullThrottle;
Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchEngaged = PhysicsControl.DampingRateZeroThrottleClutchEngaged;
Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchDisengaged = PhysicsControl.DampingRateZeroThrottleClutchDisengaged;
Vehicle4W->ApplyEngineSetup(Vehicle4W->EngineSetup);
// Transmission Setup
Vehicle4W->TransmissionSetup.bUseGearAutoBox = PhysicsControl.bUseGearAutoBox;
Vehicle4W->TransmissionSetup.GearSwitchTime = PhysicsControl.GearSwitchTime;
Vehicle4W->TransmissionSetup.ClutchStrength = PhysicsControl.ClutchStrength;
Vehicle4W->ApplyTransmissionSetup(Vehicle4W->TransmissionSetup);
// Vehicle Setup
Vehicle4W->Mass = PhysicsControl.Mass;
Vehicle4W->DragCoefficient = PhysicsControl.DragCoefficient;
Vehicle4W->InertiaTensorScale = PhysicsControl.InertiaTensorScale;
}

View File

@ -111,7 +111,9 @@ public:
return State;
}
FVehiclePhysicsControl GetVehiclePhysicsControl();
FVehiclePhysicsControl GetVehiclePhysicsControl();
void SetVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl);
/// @}
// ===========================================================================