Added first CarSim integration to vehicle class.
This commit is contained in:
parent
7a6edc405c
commit
7739b5eb94
|
@ -88,5 +88,9 @@ namespace client {
|
|||
return boost::static_pointer_cast<TrafficLight>(GetWorld().GetActor(id));
|
||||
}
|
||||
|
||||
void Vehicle::SetCarSimEnabled(bool enabled) {
|
||||
GetEpisode().Lock()->SetCarSimEnabled(*this, enabled);
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
} // namespace carla
|
||||
|
|
|
@ -87,6 +87,9 @@ namespace client {
|
|||
/// Retrieve the traffic light actor currently affecting this vehicle.
|
||||
SharedPtr<TrafficLight> GetTrafficLight() const;
|
||||
|
||||
/// Enables CarSim simulation if it is availiable
|
||||
void SetCarSimEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
|
||||
const bool _is_control_sticky;
|
||||
|
|
|
@ -330,6 +330,10 @@ namespace detail {
|
|||
_pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
|
||||
}
|
||||
|
||||
void Client::SetCarSimEnabled(rpc::ActorId vehicle, bool enabled) {
|
||||
_pimpl->AsyncCall("set_carsim_enabled", vehicle, enabled);
|
||||
}
|
||||
|
||||
void Client::ApplyControlToWalker(rpc::ActorId walker, const rpc::WalkerControl &control) {
|
||||
_pimpl->AsyncCall("apply_control_to_walker", walker, control);
|
||||
}
|
||||
|
|
|
@ -211,6 +211,10 @@ namespace detail {
|
|||
rpc::ActorId vehicle,
|
||||
const rpc::VehicleControl &control);
|
||||
|
||||
void SetCarSimEnabled(
|
||||
rpc::ActorId vehicle,
|
||||
bool enabled);
|
||||
|
||||
void ApplyControlToWalker(
|
||||
rpc::ActorId walker,
|
||||
const rpc::WalkerControl &control);
|
||||
|
|
|
@ -445,6 +445,10 @@ namespace detail {
|
|||
_client.SetLightStateToVehicle(vehicle.GetId(), light_state);
|
||||
}
|
||||
|
||||
void SetCarSimEnabled(Vehicle &vehicle, bool enabled) {
|
||||
_client.SetCarSimEnabled(vehicle.GetId(), enabled);
|
||||
}
|
||||
|
||||
/// @}
|
||||
// =========================================================================
|
||||
/// @name Operations with the recorder
|
||||
|
|
|
@ -141,6 +141,7 @@ 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("set_carsim_enabled", &cc::Vehicle::SetCarSimEnabled)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
|
|
|
@ -41,6 +41,13 @@ public class Carla : ModuleRules
|
|||
"ProceduralMeshComponent"
|
||||
// ... add other public dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"CarSim"
|
||||
// ... add other public dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
||||
if (Target.Type == TargetType.Editor)
|
||||
|
@ -68,6 +75,14 @@ public class Carla : ModuleRules
|
|||
// ... add private dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"CarSim"
|
||||
// ... add private dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
PrivateIncludePathModuleNames.AddRange(new string[] { "CarSim" });
|
||||
|
||||
DynamicallyLoadedModuleNames.AddRange(
|
||||
new string[]
|
||||
|
|
|
@ -1083,6 +1083,24 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
return R<void>::Success();
|
||||
};
|
||||
|
||||
BIND_SYNC(set_carsim_enabled) << [this](
|
||||
cr::ActorId ActorId,
|
||||
bool bEnabled) -> R<void>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
auto ActorView = Episode->FindActor(ActorId);
|
||||
if (!ActorView.IsValid())
|
||||
{
|
||||
RESPOND_ERROR("unable to set carsim: actor not found");
|
||||
}
|
||||
auto Vehicle = Cast<ACarlaWheeledVehicle>(ActorView.GetActor());
|
||||
if (Vehicle == nullptr)
|
||||
{
|
||||
RESPOND_ERROR("unable to set carsim: not actor is not a vehicle");
|
||||
}
|
||||
Vehicle->SetCarSimEnabled(bEnabled);
|
||||
return R<void>::Success();
|
||||
};
|
||||
// ~~ Traffic lights ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
BIND_SYNC(set_traffic_light_state) << [this](
|
||||
|
|
|
@ -33,6 +33,8 @@ ACarlaWheeledVehicle::ACarlaWheeledVehicle(const FObjectInitializer& ObjectIniti
|
|||
VelocityControl = CreateDefaultSubobject<UVehicleVelocityControl>(TEXT("VelocityControl"));
|
||||
VelocityControl->Deactivate();
|
||||
|
||||
CarSimMovementComponent = CreateDefaultSubobject<UCarSimMovementComponent>(TEXT("CarSimMovement"));
|
||||
|
||||
GetVehicleMovementComponent()->bReverseAsBrake = false;
|
||||
}
|
||||
|
||||
|
@ -110,6 +112,8 @@ void ACarlaWheeledVehicle::BeginPlay()
|
|||
}
|
||||
|
||||
Vehicle4W->WheelSetups = NewWheelSetups;
|
||||
|
||||
SetCarSimEnabled(false);
|
||||
}
|
||||
|
||||
void ACarlaWheeledVehicle::AdjustVehicleBounds()
|
||||
|
@ -177,25 +181,53 @@ float ACarlaWheeledVehicle::GetMaximumSteerAngle() const
|
|||
|
||||
void ACarlaWheeledVehicle::FlushVehicleControl()
|
||||
{
|
||||
auto *MovementComponent = GetVehicleMovementComponent();
|
||||
MovementComponent->SetThrottleInput(InputControl.Control.Throttle);
|
||||
MovementComponent->SetSteeringInput(InputControl.Control.Steer);
|
||||
MovementComponent->SetBrakeInput(InputControl.Control.Brake);
|
||||
MovementComponent->SetHandbrakeInput(InputControl.Control.bHandBrake);
|
||||
if (LastAppliedControl.bReverse != InputControl.Control.bReverse)
|
||||
if (bCarSimEnabled)
|
||||
{
|
||||
MovementComponent->SetUseAutoGears(!InputControl.Control.bReverse);
|
||||
MovementComponent->SetTargetGear(InputControl.Control.bReverse ? -1 : 1, true);
|
||||
CarSimMovementComponent->SetThrottleInput(InputControl.Control.Throttle);
|
||||
CarSimMovementComponent->SetSteeringInput(InputControl.Control.Steer);
|
||||
CarSimMovementComponent->SetBrakeInput(InputControl.Control.Brake);
|
||||
if (InputControl.Control.bHandBrake)
|
||||
{
|
||||
CarSimMovementComponent->SetBrakeInput(InputControl.Control.Brake + 1.0);
|
||||
}
|
||||
// CarSimMovementComponent->SetHandbrakeInput(InputControl.Control.bHandBrake);
|
||||
// if (LastAppliedControl.bReverse != InputControl.Control.bReverse)
|
||||
// {
|
||||
// CarSimMovementComponent->SetUseAutoGears(!InputControl.Control.bReverse);
|
||||
// CarSimMovementComponent->SetTargetGear(InputControl.Control.bReverse ? -1 : 1, true);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// CarSimMovementComponent->SetUseAutoGears(!InputControl.Control.bManualGearShift);
|
||||
// if (InputControl.Control.bManualGearShift)
|
||||
// {
|
||||
// CarSimMovementComponent->SetTargetGear(InputControl.Control.Gear, true);
|
||||
// }
|
||||
// }
|
||||
InputControl.Control.Gear = CarSimMovementComponent->GetCurrentGear();
|
||||
}
|
||||
else
|
||||
{
|
||||
MovementComponent->SetUseAutoGears(!InputControl.Control.bManualGearShift);
|
||||
if (InputControl.Control.bManualGearShift)
|
||||
auto *MovementComponent = GetVehicleMovementComponent();
|
||||
MovementComponent->SetThrottleInput(InputControl.Control.Throttle);
|
||||
MovementComponent->SetSteeringInput(InputControl.Control.Steer);
|
||||
MovementComponent->SetBrakeInput(InputControl.Control.Brake);
|
||||
MovementComponent->SetHandbrakeInput(InputControl.Control.bHandBrake);
|
||||
if (LastAppliedControl.bReverse != InputControl.Control.bReverse)
|
||||
{
|
||||
MovementComponent->SetTargetGear(InputControl.Control.Gear, true);
|
||||
MovementComponent->SetUseAutoGears(!InputControl.Control.bReverse);
|
||||
MovementComponent->SetTargetGear(InputControl.Control.bReverse ? -1 : 1, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MovementComponent->SetUseAutoGears(!InputControl.Control.bManualGearShift);
|
||||
if (InputControl.Control.bManualGearShift)
|
||||
{
|
||||
MovementComponent->SetTargetGear(InputControl.Control.Gear, true);
|
||||
}
|
||||
}
|
||||
InputControl.Control.Gear = MovementComponent->GetCurrentGear();
|
||||
}
|
||||
InputControl.Control.Gear = MovementComponent->GetCurrentGear();
|
||||
InputControl.Control.bReverse = InputControl.Control.Gear < 0;
|
||||
LastAppliedControl = InputControl.Control;
|
||||
InputControl.Priority = EVehicleInputPriority::INVALID;
|
||||
|
@ -453,3 +485,29 @@ void ACarlaWheeledVehicle::SetVehicleLightState(const FVehicleLightState &LightS
|
|||
InputControl.LightState = LightState;
|
||||
RefreshLightState(LightState);
|
||||
}
|
||||
|
||||
//-----CARSIM--------------------------------
|
||||
void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled)
|
||||
{
|
||||
carla::log_warning("Enabling CarSim", bEnabled);
|
||||
bCarSimEnabled = bEnabled;
|
||||
if (bCarSimEnabled)
|
||||
{
|
||||
GetVehicleMovementComponent()->SetComponentTickEnabled(false);
|
||||
GetVehicleMovementComponent()->Deactivate();
|
||||
CarSimMovementComponent->Activate();
|
||||
CarSimMovementComponent->ResetVsVehicle(false);
|
||||
CarSimMovementComponent->SyncVsVehicleLocOri();
|
||||
CarSimMovementComponent->SetComponentTickEnabled(true);
|
||||
GetMesh()->SetSimulatePhysics(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetVehicleMovementComponent()->SetComponentTickEnabled(true);
|
||||
GetVehicleMovementComponent()->Activate();
|
||||
CarSimMovementComponent->SetComponentTickEnabled(false);
|
||||
CarSimMovementComponent->Deactivate();
|
||||
GetMesh()->SetSimulatePhysics(true);
|
||||
}
|
||||
}
|
||||
//-------------------------------------------
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
//-----CARSIM--------------------------------
|
||||
#include "CarSimMovementComponent.h"
|
||||
//-------------------------------------------
|
||||
|
||||
#include "CarlaWheeledVehicle.generated.h"
|
||||
|
||||
class UBoxComponent;
|
||||
|
@ -235,4 +239,20 @@ private:
|
|||
InputControl;
|
||||
|
||||
FVehicleControl LastAppliedControl;
|
||||
|
||||
|
||||
//-----CARSIM--------------------------------
|
||||
public:
|
||||
|
||||
UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintCallable)
|
||||
void SetCarSimEnabled(bool bEnabled);
|
||||
|
||||
private:
|
||||
|
||||
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere)
|
||||
bool bCarSimEnabled = false;
|
||||
|
||||
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
|
||||
UCarSimMovementComponent * CarSimMovementComponent;
|
||||
//-------------------------------------------
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue