25#include "CarSimMovementComponent.h"
33#include <util/ue-header-guard-begin.h>
34#include "Components/SkeletalMeshComponent.h"
35#include "WheeledVehiclePawn.h"
36#include "PhysicsEngine/PhysicsConstraintComponent.h"
37#include "VehicleAnimationInstance.h"
38#include "FoliageInstancedStaticMeshComponent.h"
39#include "CoreMinimal.h"
40#include "WheeledVehiclePawn.h"
41#include <util/ue-header-guard-end.h>
45#include "CarlaWheeledVehicle.generated.h"
50class UChaosVehicleWheel;
80class FPhysScene_Chaos;
106 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
109 return Cast<UChaosWheeledVehicleMovementComponent>(GetVehicleMovement());
113 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
120 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
128 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
131 return GetActorTransform();
135 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
136 float GetVehicleForwardSpeed()
const;
139 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
140 FVector GetVehicleOrientation()
const;
143 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
144 int32 GetVehicleCurrentGear()
const;
147 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
148 FTransform GetVehicleBoundingBoxTransform()
const;
151 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
152 FVector GetVehicleBoundingBoxExtent()
const;
155 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
162 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
163 float GetMaximumSteerAngle()
const;
178 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
184 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
191 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
194 FVector GetCenterOfMass(UChaosWheeledVehicleMovementComponent &VehicleMovComponent)
const;
196 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
201 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
202 void RestoreVehiclePhysicsControl();
204 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
209 void SetCenterOfMass(UChaosWheeledVehicleMovementComponent &VehicleMovComponent,
const FVehiclePhysicsControl &PhysicsControl);
215 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
216 void SetSimulatePhysics(
bool enabled);
222 UFUNCTION(BlueprintNativeEvent)
252 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"CARLA Wheeled Vehicle|Rider")
255 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"CARLA Wheeled Vehicle|Rider")
271 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"CARLA Wheeled Vehicle|Rider")
295 UFUNCTION(BlueprintPure, Category =
"CARLA Wheeled Vehicle|Rider")
323 if (
const UWorld* World = GetWorld())
336 AngularVelocityRadians.X = 0.0f;
337 AngularVelocityRadians.Y = 0.0f;
338 const FQuat DeltaRotation = FQuat::MakeFromRotationVector(AngularVelocityRadians * TimeSinceCache);
339 PredictedMeshTransform.SetRotation((DeltaRotation * PredictedMeshTransform.GetRotation()).GetNormalized());
349 VelocityForExtrapolation.Z = 0.0f;
350 PredictedMeshTransform.AddToTranslation(VelocityForExtrapolation * TimeSinceCache);
369 static const FName LeftPedalSocket(TEXT(
"LeftPedalSocket"));
370 static const FName RightPedalSocket(TEXT(
"RightPedalSocket"));
371 static const FName LeftPedalPivotBone(TEXT(
"LeftPedalGeo"));
372 static const FName RightPedalPivotBone(TEXT(
"RightPedalGeo"));
373 if (SocketName == LeftPedalSocket || SocketName == RightPedalSocket)
375 const FName PivotBoneName = (SocketName == LeftPedalSocket) ? LeftPedalPivotBone : RightPedalPivotBone;
378 if (CachedSocket && CachedPivot)
380 const FTransform SocketRelativeToPivot = CachedSocket->GetRelativeTransform(*CachedPivot);
385 const FQuat ComponentSpaceRotation(FRotator(SignedPedalAngle, 0.0f, 0.0f));
386 PredictedPivot.SetRotation((ComponentSpaceRotation * PredictedMeshTransform.GetRotation()).GetNormalized());
387 return SocketRelativeToPivot * PredictedPivot;
395 return FTransform::Identity;
403 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"CARLA Wheeled Vehicle|Rider")
423 UFUNCTION(BlueprintPure, Category =
"CARLA Wheeled Vehicle|Rider")
432 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"CARLA Wheeled Vehicle|Rider")
444 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
447 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
455 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
456 void ActivateVelocityControl(
const FVector &Velocity);
458 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
459 void DeactivateVelocityControl();
461 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
462 void ActivateAccelerationControl(
const FVector &Acceleration);
464 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
465 void DeactivateAccelerationControl();
468 void ApplyVehicleAccelerationControl(
float LongitudinalAccelerationMps2,
float Steer,
float SteerSpeed);
470 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
471 void ShowDebugTelemetry(
bool Enabled);
474 void FlushVehicleControl();
483 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
484 void SetThrottleInput(
float Value);
486 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
487 void SetSteeringInput(
float Value);
489 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
490 void SetBrakeInput(
float Value);
492 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
493 void SetReverse(
bool Value);
495 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
501 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
502 void SetHandbrakeInput(
bool Value);
504 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
510 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
516 TArray<float> GetWheelsFrictionScale();
518 void SetWheelsFrictionScale(TArray<float> &WheelsFrictionScale);
522 template<
typename T = UBaseCarlaMovementComponent>
536 virtual void BeginPlay()
override;
537 virtual void TickActor(
float DeltaTime,
enum ELevelTick TickType, FActorTickFunction& ThisTickFunction)
override;
538 virtual void EndPlay(
const EEndPlayReason::Type EndPlayReason);
540 UFUNCTION(BlueprintImplementableEvent)
543 UFUNCTION(BlueprintCallable, CallInEditor)
546 UPROPERTY(Category=
"Door Animation", EditAnywhere, BlueprintReadWrite)
549 UPROPERTY(Category=
"Door Animation", EditAnywhere, BlueprintReadWrite)
552 UFUNCTION(BlueprintCallable, CallInEditor)
567 UPROPERTY(Category =
"AI Controller", VisibleAnywhere)
570 UPROPERTY(Category =
"CARLA Wheeled Vehicle", EditAnywhere)
573 UPROPERTY(Category =
"CARLA Wheeled Vehicle", EditAnywhere)
648 UPROPERTY(Category =
"CARLA Wheeled Vehicle", EditDefaultsOnly)
651 UPROPERTY(Category =
"CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly)
654 UPROPERTY(Category =
"CARLA Wheeled Vehicle", EditAnywhere)
669 UFUNCTION(BlueprintCallable)
681 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
684 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
688 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
691 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
696 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
699 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
704 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
714 bool IsSimulatedByChaos()
const;
716 bool HasWheel(int32 WheelIndex)
const;
720 bool HasCarlaVehicleAnimation()
const;
724 float GetWheelRadius(int32 WheelIndex)
const;
727 FVector GetWheelSuspensionAxis(int32 WheelIndex)
const;
730 FWheelAnimationData GetDrawnWheelPose(int32 WheelIndex)
const;
732 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
735 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
738 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
741 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
744 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
745 void RecordDoorChange(
const EVehicleDoor DoorIdx,
const bool bIsOpen);
749 TArray<TPair<int32, FTransform>> GetOpenDoorPoses()
const;
754 void SetMirroredDoorPoses(
const TArray<TPair<int32, FTransform>> &OpenDoors);
756 virtual FVector GetVelocity()
const override;
761 void SetMirroredMotion(
const FVector &Velocity,
float ForwardSpeed);
763 void ClearMirroredMotion();
792 FPoseSnapshot GetWorldTransformedPose();
795 UPROPERTY(Category=
"CARLA Wheeled Vehicle", EditAnywhere)
799 UPROPERTY(Category=
"CARLA Wheeled Vehicle", VisibleAnywhere)
806 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
808 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
810 UPhysicsConstraintComponent*Component, const FRotator &NewAngle);
828 UPROPERTY(Category=
"CARLA Wheeled Vehicle", VisibleAnywhere)
832 UPROPERTY(Category=
"CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess =
"true"))
835 UPROPERTY(Category=
"CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess =
"true"))
853 FWheelAnimationData
GetWheelPose(int32 WheelIndex) const;
872 void OnSeedPreTick(FPhysScene_Chaos *Scene,
float DeltaSeconds);
887 UPROPERTY(Category=
"CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess =
"true"))
891 UPROPERTY(Category=
"CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess =
"true"))
894 UPROPERTY(Category=
"CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess =
"true"))
899 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
902 void CheckRollover(const
float roll, const
std::pair<
float,
float> threshold_roll);
922 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
925 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
928 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
931 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
ECarlaWheeledVehicleState
State of a ACarlaWheeledVehicle, to be displayed in editor for debugging purposes.
EVehicleDoor
Type of door to open/close.
TObjectPtr< UVehicleVelocityControl > VelocityControl
FBoxSphereBounds GetBoxSphereBounds() const
FVector GetWheelWorldLocation(int32 WheelIndex) const
World location, in cm, of the centre of the wheel at WheelIndex as shown: its resting position plus t...
void ApplyVehicleLightDefaultsForCurrentState()
void ArmSeedRewrite(TArray< float > Spins)
The next physics pre-tick copies in the output of the step before the seed, so the seeded spins are w...
bool HasWheelOrWarn(int32 WheelIndex, const TCHAR *Caller) const
FName VehicleMeshSeatSocketName
FDelegateHandle SeedPreTickHandle
void SetAIVehicleState(ECarlaWheeledVehicleState InState)
FVector CachedVehicleWorldAngularVelocityDegrees
FTransform CachedVehicleMeshTransform
bool IsTwoWheeledVehicle()
void AddReferenceToManager()
int RolloverBehaviorTracker
carla::rpc::VehicleFailureState GetFailureState() const
void RefreshLightState(const FVehicleLightState &VehicleLightState)
FPoseSnapshot WorldTransformedPose
void SetWheelSuspensionOffset(EVehicleWheelLocation WheelLocation, float OffsetInCm)
Suspension compression of a wheel, in cm.
void SetReverse(bool Value)
TMap< UPrimitiveComponent *, UPhysicsConstraintComponent * > CollisionDisableConstraints
bool bMirroredSimulatingPhysics
virtual bool IsTwoWheeledVehicle_Implementation()
float RolloverBehaviorForce
const TArray< int32 > GetFoliageInstancesCloseToVehicle(const UInstancedStaticMeshComponent *Component) const
float GetWheelSteerAngle(EVehicleWheelLocation WheelLocation)
bool IsInVehicleRange(const FVector &Location) const
bool bRiderComponentsResolved
T * GetCarlaMovementComponent() const
float GetPedalRotation() const
Two-wheeled vehicles spin a decorative pedal/crank bone (in the vehicle mesh's own Anim Blueprint,...
float GetWheelPitchAngle(EVehicleWheelLocation WheelLocation)
ECarlaWheeledVehicleState State
Current state of the vehicle controller (for debugging purposes).
bool GetMirroredManualGearShift() const
FVehicleControl LastAppliedControl
static void SetPhysicsConstraintAngle(UPhysicsConstraintComponent *Component, const FRotator &NewAngle)
void CheckRollover(const float roll, const std::pair< float, float > threshold_roll)
UChaosWheeledVehicleMovementComponent * GetChaosWheeledVehicleMovementComponent() const
Get chaos wheeled vehicle movement component casted.
const FVehicleAckermannControl & GetVehicleAckermannControl() const
Vehicle Ackermann control currently applied to this vehicle.
float MirroredForwardSpeed
TArray< UPhysicsConstraintComponent * > ConstraintsComponents
TObjectPtr< UVehicleAccelerationControl > AccelerationControl
struct ACarlaWheeledVehicle::@216275011323045035305324275337362024111062147326 InputControl
float CachedVehicleTransformsTimeSeconds
TArray< FWheelAnimationData > OverriddenWheelPoses
FVehicleAckermannControl LastAppliedAckermannControl
void SeedChaosWheels(const TArray< FWheelAnimationData > &Poses)
Sets the Chaos wheels to these poses, so that they do not jump when Chaos takes over the wheels again...
FDelegateHandle SeedPostTickHandle
float RiderSeatSmoothingSpeed
Chaos suspension has small, real, high-frequency vertical jitter on the vehicle mesh every frame (vis...
FWheelAnimationData * GetOverriddenWheelPoseOrWarn(EVehicleWheelLocation WheelLocation, const TCHAR *Caller)
The overridden pose for a setter to write, or nullptr, with a warning, if it cannot be set.
FVehiclePhysicsControl LastPhysicsControl
void OnSeedPostTick(FChaosScene *Scene)
static FRotator GetPhysicsConstraintAngle(UPhysicsConstraintComponent *Component)
float GetWheelSuspensionOffset(EVehicleWheelLocation WheelLocation)
FWheelAnimationData GetWheelPose(int32 WheelIndex) const
The pose shown for a wheel: the overridden one, otherwise Chaos's, otherwise the one last drawn.
TArray< float > PendingSeedSpins
Degrees, as drawn.
void SetWheelAnimationOverride(bool bEnabled)
While the wheel animation is overridden the wheels show only the values set through the wheel setters...
bool HasMirroredMotion() const
FRotator RiderSeatRelativeRotationOffset
The rider mesh's rest pose isn't authored to sit flush with the socket's own local axes – its compone...
TObjectPtr< UBoxComponent > VehicleBounds
void ActivateVehicleLightComponents()
Some vehicle Blueprints (Tesla, Mustang, DodgeCharger, ...) author real Spot/Point light components f...
TMap< UPhysicsConstraintComponent *, UPrimitiveComponent * > ConstraintDoor
void OnSeedPreTick(FPhysScene_Chaos *Scene, float DeltaSeconds)
FTimerHandle TimerHandler
void ResolveRiderComponentsIfNeeded()
void ApplyVehicleAckermannControl(const FVehicleAckermannControl &AckermannControl, EVehicleInputPriority Priority)
TMap< UPrimitiveComponent *, FTransform > DoorComponentsTransform
TObjectPtr< USkeletalMeshComponent > RiderMeshComponent
FBox GetDetectionBox() const
const TArray< FWheelAnimationData > & GetOverriddenWheelPoses() const
Indexed like the movement component's WheelSetups.
TMap< FName, FTransform > CachedVehicleSocketTransforms
void ApplyRolloverBehavior()
Rollovers tend to have too much angular velocity, resulting in the vehicle doing a full 360º flip.
UBaseCarlaMovementComponent * BaseMovementComponent
FTransform GetVehicleTransform() const
Transform of the vehicle.
TArray< FName > ConstraintComponentNames
bool IsAckermannControlActive() const
FTransform GetCachedVehicleSocketWorldTransform(FName SocketName) const
Cached, extrapolated world transform of ANY socket on the vehicle mesh (Seat, HandlerLeftSocket,...
float PedalRotationDegreesPerCm
Degrees the pedal bone rotates per centimeter of real vehicle travel (see GetPedalRotation).
void DrawFoliageBoundingBox() const
const FVehicleControl & GetVehicleControl() const
Vehicle control currently applied to this vehicle.
void UpdateDetectionBox()
void ApplyVehicleControl(const FVehicleControl &Control, EVehicleInputPriority Priority)
bool bHasSavedVehicleLightDefault
TObjectPtr< USkeletalMeshComponent > VehicleMeshForRiderSeat
ECarlaWheeledVehicleState GetAIVehicleState() const
ACarlaWheeledVehicle(const FObjectInitializer &ObjectInitializer)
carla::rpc::VehicleFailureState FailureState
bool IsMirroredSimulatingPhysics() const
FTransform SmoothedVehicleMeshTransform
void OnRiderBoneTransformsFinalized()
float GetDetectionSize() const
FVector CachedVehicleWorldVelocity
bool bWheelAnimationOverridden
void AdjustVehicleBounds()
void SetWheelSteerDirection(EVehicleWheelLocation WheelLocation, float AngleInDeg)
Set the rotation of the car wheels indicated by the user 0 = FL_VehicleWheel, 1 = FR_VehicleWheel,...
float GetRotationAnim() const
bool bAckermannControlActive
float SavedVehicleLightIntensity
TArray< FWheelAnimationData > GetWheelPoses() const
GetWheelPose for every wheel.
bool bSmoothedVehicleMeshTransformInitialized
float GetSpeedAnim() const
void ApplyAckermannControllerSettings(const FAckermannControllerSettings &AckermannControllerSettings)
void SetRotationAnim(float Rotation)
void SetMirroredDrivetrain(int32 Gear, bool bManualGearShift, bool bSimulatingPhysics)
Multi-GPU secondary: the primary's gear, which GetVehicleCurrentGear reports instead of the idle driv...
void SetSpeedAnim(float Speed)
void ApplyWheelPhysicsControl()
Applies LastPhysicsControl.Wheels to the live Chaos wheels.
const UChaosVehicleWheel * GetWheelDefaults(int32 WheelIndex) const
FAckermannControllerSettings GetAckermannControllerSettings() const
void SetHandbrakeInput(bool Value)
const UChaosVehicleWheel * GetSimulatedWheel(int32 WheelIndex) const
The Chaos wheel, while Chaos simulates the vehicle and has output for it.
bool bMirroredManualGearShift
void RemoveReferenceToManager()
void SetWheelPitchAngle(EVehicleWheelLocation WheelLocation, float AngleInDeg)
Spin angle of a wheel, in degrees. Purely visual, wheel animation override only.
TMap< FString, float > SavedVehicleLightGroupIntensity
FAckermannController AckermannController
void PrintROS2Message(const char *Message)
FName RiderMeshComponentName
Two-wheeled vehicles (bikes/motorcycles) embed their rider as a SkeletalMeshComponent (named RiderMes...
bool IsWheelAnimationOverridden() const
UBoxComponent * GetVehicleBoundingBox() const
Get vehicle's bounding box component.
Euler angles of a rotation in CARLA's / Unreal's left-handed frame: x forward, y right,...
This file contains definitions of common data structures used in traffic manager.