refactored code
This commit is contained in:
parent
12fd0178e5
commit
333fe4546d
|
@ -25,10 +25,21 @@ namespace client {
|
|||
}
|
||||
}
|
||||
|
||||
void Vehicle::ApplyPhysicsControl(const PhysicsControl &physics_control) {
|
||||
if (physics_control != _physics_control) {
|
||||
GetEpisode().Lock()->ApplyPhysicsControlToVehicle(*this, physics_control);
|
||||
_physics_control = physics_control;
|
||||
}
|
||||
}
|
||||
|
||||
Vehicle::Control Vehicle::GetControl() const {
|
||||
return GetEpisode().Lock()->GetActorDynamicState(*this).state.vehicle_data.control;
|
||||
}
|
||||
|
||||
Vehicle::PhysicsControl Vehicle::GetPhysicsControl() const {
|
||||
return GetEpisode().Lock()->GetVehiclePhysicsControl(*this);
|
||||
}
|
||||
|
||||
float Vehicle::GetSpeedLimit() const {
|
||||
return GetEpisode().Lock()->GetActorDynamicState(*this).state.vehicle_data.speed_limit;
|
||||
}
|
||||
|
@ -47,12 +58,5 @@ 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
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "carla/client/Actor.h"
|
||||
#include "carla/rpc/VehicleControl.h"
|
||||
#include "carla/rpc/VehiclePhysicsControl.h"
|
||||
#include "carla/rpc/TrafficLightState.h"
|
||||
|
||||
namespace carla {
|
||||
|
@ -18,6 +19,7 @@ namespace client {
|
|||
public:
|
||||
|
||||
using Control = rpc::VehicleControl;
|
||||
using PhysicsControl = rpc::VehiclePhysicsControl;
|
||||
|
||||
explicit Vehicle(ActorInitializer init) : Actor(std::move(init)) {}
|
||||
|
||||
|
@ -27,6 +29,9 @@ namespace client {
|
|||
/// Apply @a control to this vehicle.
|
||||
void ApplyControl(const Control &control);
|
||||
|
||||
/// Apply physics control to this vehicle
|
||||
void ApplyPhysicsControl(const PhysicsControl &physics_control);
|
||||
|
||||
/// Return the control last applied to this vehicle.
|
||||
///
|
||||
/// @note The following functions do not call the simulator, they return the
|
||||
|
@ -34,6 +39,7 @@ namespace client {
|
|||
/// received in the last tick.
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
Control GetControl() const;
|
||||
PhysicsControl GetPhysicsControl() const;
|
||||
|
||||
float GetSpeedLimit() const;
|
||||
|
||||
|
@ -43,12 +49,11 @@ namespace client {
|
|||
|
||||
SharedPtr<TrafficLight> GetTrafficLight() const;
|
||||
|
||||
rpc::VehiclePhysicsControl GetPhysicsControl() const;
|
||||
|
||||
void SetPhysicsControl(const rpc::VehiclePhysicsControl &physics_control);
|
||||
private:
|
||||
|
||||
Control _control;
|
||||
PhysicsControl _physics_control;
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
|
|
|
@ -120,14 +120,14 @@ namespace detail {
|
|||
return _pimpl->CallAndWait<return_t>("get_actors_by_id", ids);
|
||||
}
|
||||
|
||||
rpc::VehiclePhysicsControl Client::GetVehiclePhysicsControl(const int &actorId) const {
|
||||
return _pimpl->CallAndWait<carla::rpc::VehiclePhysicsControl>("get_physics_control", actorId);
|
||||
rpc::VehiclePhysicsControl Client::GetVehiclePhysicsControl(const rpc::Actor &actor) const {
|
||||
return _pimpl->CallAndWait<carla::rpc::VehiclePhysicsControl>("get_physics_control", actor);
|
||||
}
|
||||
|
||||
void Client::SetVehiclePhysicsControl(
|
||||
const int &actorId,
|
||||
void Client::ApplyPhysicsControlToVehicle(
|
||||
const rpc::Actor &actor,
|
||||
const rpc::VehiclePhysicsControl &physicsControl) {
|
||||
return _pimpl->AsyncCall("set_physics_control", actorId, physicsControl);
|
||||
return _pimpl->AsyncCall("apply_physics_control", actor, physicsControl);
|
||||
}
|
||||
|
||||
rpc::Actor Client::SpawnActor(
|
||||
|
|
|
@ -78,9 +78,8 @@ namespace detail {
|
|||
|
||||
std::vector<rpc::Actor> GetActorsById(const std::vector<actor_id_type> &ids);
|
||||
|
||||
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const int &actorId) const;
|
||||
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const rpc::Actor &actor) const;
|
||||
|
||||
void SetVehiclePhysicsControl(const int &actorId, const rpc::VehiclePhysicsControl &physicsControl);
|
||||
|
||||
rpc::Actor SpawnActor(
|
||||
const rpc::ActorDescription &description,
|
||||
|
@ -117,6 +116,10 @@ namespace detail {
|
|||
const rpc::Actor &walker,
|
||||
const rpc::WalkerControl &control);
|
||||
|
||||
void ApplyPhysicsControlToVehicle(
|
||||
const rpc::Actor &vehicle,
|
||||
const rpc::VehiclePhysicsControl &physicsControl);
|
||||
|
||||
void SetTrafficLightState(
|
||||
const rpc::Actor &trafficLight,
|
||||
const rpc::TrafficLightState trafficLightState);
|
||||
|
|
|
@ -135,13 +135,10 @@ namespace detail {
|
|||
_client.SetWeatherParameters(weather);
|
||||
}
|
||||
|
||||
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const int &actorId) const {
|
||||
return _client.GetVehiclePhysicsControl(actorId);
|
||||
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const Vehicle &vehicle) const {
|
||||
return _client.GetVehiclePhysicsControl(vehicle.Serialize());
|
||||
}
|
||||
|
||||
void SetVehiclePhysicsControl(const int &actorId, const rpc::VehiclePhysicsControl &physicsControl) {
|
||||
_client.SetVehiclePhysicsControl(actorId, physicsControl);
|
||||
}
|
||||
/// @}
|
||||
// =========================================================================
|
||||
/// @name General operations with actors
|
||||
|
@ -232,6 +229,9 @@ namespace detail {
|
|||
_client.ApplyControlToWalker(walker.Serialize(), control);
|
||||
}
|
||||
|
||||
void ApplyPhysicsControlToVehicle(Vehicle &vehicle, const rpc::VehiclePhysicsControl &physicsControl) {
|
||||
_client.ApplyPhysicsControlToVehicle(vehicle.Serialize(), physicsControl);
|
||||
}
|
||||
/// @}
|
||||
// =========================================================================
|
||||
/// @name Operations with sensors
|
||||
|
|
|
@ -76,13 +76,13 @@ void export_actor() {
|
|||
.add_property("bounding_box", CALL_RETURNING_COPY(cc::Vehicle, GetBoundingBox))
|
||||
.def("apply_control", &cc::Vehicle::ApplyControl, (arg("control")))
|
||||
.def("get_control", &cc::Vehicle::GetControl)
|
||||
.def("apply_physics_control", &cc::Vehicle::ApplyPhysicsControl, (arg("physics_control")))
|
||||
.def("get_physics_control", &cc::Vehicle::GetPhysicsControl)
|
||||
.def("set_autopilot", &cc::Vehicle::SetAutopilot, (arg("enabled") = true))
|
||||
.def("get_speed_limit", &cc::Vehicle::GetSpeedLimit)
|
||||
.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))
|
||||
;
|
||||
|
||||
|
|
|
@ -371,41 +371,39 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
|
||||
|
||||
Server.BindSync("get_physics_control", [this](
|
||||
int ActorId) -> R<cr::VehiclePhysicsControl>
|
||||
cr::Actor Actor) -> R<cr::VehiclePhysicsControl>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
|
||||
auto ActorView = Episode->FindActor(ActorId);
|
||||
auto ActorView = Episode->FindActor(Actor.id);
|
||||
if (!ActorView.IsValid())
|
||||
{
|
||||
RESPOND_ERROR("unable to apply control: actor not found");
|
||||
RESPOND_ERROR("unable to get actor physics control: actor not found");
|
||||
}
|
||||
auto Vehicle = Cast<ACarlaWheeledVehicle>(ActorView.GetActor());
|
||||
if (Vehicle == nullptr)
|
||||
{
|
||||
RESPOND_ERROR("unable to apply control: actor is not a vehicle");
|
||||
}
|
||||
|
||||
|
||||
return cr::VehiclePhysicsControl(Vehicle->GetVehiclePhysicsControl());
|
||||
});
|
||||
|
||||
Server.BindSync("set_physics_control", [this](
|
||||
int ActorId, cr::VehiclePhysicsControl PhysicsControl) -> R<void>
|
||||
Server.BindSync("apply_physics_control", [this](
|
||||
cr::Actor Actor, cr::VehiclePhysicsControl PhysicsControl) -> R<void>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
|
||||
auto ActorView = Episode->FindActor(ActorId);
|
||||
auto ActorView = Episode->FindActor(Actor.id);
|
||||
if (!ActorView.IsValid())
|
||||
{
|
||||
RESPOND_ERROR("unable to apply control: actor not found");
|
||||
RESPOND_ERROR("unable to apply actor physics 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));
|
||||
|
||||
Vehicle->ApplyVehiclePhysicsControl(FVehiclePhysicsControl(PhysicsControl));
|
||||
|
||||
return R<void>::Success();
|
||||
});
|
||||
|
|
|
@ -187,7 +187,7 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl()
|
|||
return PhysicsControl;
|
||||
}
|
||||
|
||||
void ACarlaWheeledVehicle::SetVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl)
|
||||
void ACarlaWheeledVehicle::ApplyVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl)
|
||||
{
|
||||
UWheeledVehicleMovementComponent4W *Vehicle4W = CastChecked<UWheeledVehicleMovementComponent4W>(
|
||||
GetVehicleMovement());
|
||||
|
@ -199,10 +199,8 @@ void ACarlaWheeledVehicle::SetVehiclePhysicsControl(const FVehiclePhysicsControl
|
|||
Vehicle4W->EngineSetup.MOI = PhysicsControl.MOI;
|
||||
|
||||
Vehicle4W->EngineSetup.DampingRateFullThrottle = PhysicsControl.DampingRateFullThrottle;
|
||||
Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchEngaged =
|
||||
PhysicsControl.DampingRateZeroThrottleClutchEngaged;
|
||||
Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchDisengaged =
|
||||
PhysicsControl.DampingRateZeroThrottleClutchDisengaged;
|
||||
Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchEngaged = PhysicsControl.DampingRateZeroThrottleClutchEngaged;
|
||||
Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchDisengaged = PhysicsControl.DampingRateZeroThrottleClutchDisengaged;
|
||||
|
||||
// Transmission Setup
|
||||
Vehicle4W->TransmissionSetup.bUseGearAutoBox = PhysicsControl.bUseGearAutoBox;
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
|
||||
FVehiclePhysicsControl GetVehiclePhysicsControl();
|
||||
|
||||
void SetVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl);
|
||||
void ApplyVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl);
|
||||
|
||||
/// @}
|
||||
// ===========================================================================
|
||||
|
|
Loading…
Reference in New Issue