CARLA
 
载入中...
搜索中...
未找到
ChronoMovementComponent.h
浏览该文件的文档.
1// Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3// Copyright (c) 2019 Intel Corporation
4//
5// This work is licensed under the terms of the MIT license.
6// For a copy, see <https://opensource.org/licenses/MIT>.
7
8#pragma once
9
12
13#ifdef WITH_CHRONO
15
16#if defined(__clang__)
17# pragma clang diagnostic push
18# pragma clang diagnostic ignored "-Wshadow"
19#endif
20
21#include "chrono/physics/ChSystemNSC.h"
22#include "chrono_vehicle/ChVehicleModelData.h"
23#include "chrono_vehicle/ChTerrain.h"
24#include "chrono_vehicle/driver/ChDataDriver.h"
25#include "chrono_vehicle/wheeled_vehicle/vehicle/WheeledVehicle.h"
26
27#if defined(__clang__)
28# pragma clang diagnostic pop
29#endif
30
32#endif
33
34#include "ChronoMovementComponent.generated.h"
35
36#ifdef WITH_CHRONO
37class UERayCastTerrain : public chrono::vehicle::ChTerrain
38{
39 ACarlaWheeledVehicle* CarlaVehicle;
40 chrono::vehicle::ChVehicle* ChronoVehicle;
41public:
42 UERayCastTerrain(ACarlaWheeledVehicle* UEVehicle, chrono::vehicle::ChVehicle* ChrVehicle);
43
44 std::pair<bool, FHitResult> GetTerrainProperties(const FVector &Location) const;
45 virtual double GetHeight(const chrono::ChVector<>& loc) const override;
46 virtual chrono::ChVector<> GetNormal(const chrono::ChVector<>& loc) const override;
47 virtual float GetCoefficientFriction(const chrono::ChVector<>& loc) const override;
48};
49#endif
50
51UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent) )
53{
54 GENERATED_BODY()
55
56#ifdef WITH_CHRONO
57 chrono::ChSystemNSC Sys;
58 std::shared_ptr<chrono::vehicle::WheeledVehicle> Vehicle;
59 std::shared_ptr<UERayCastTerrain> Terrain;
60#endif
61
62 uint64_t MaxSubsteps = 10;
63 float MaxSubstepDeltaTime = 0.01;
65 FString VehicleJSON = "hmmwv/vehicle/HMMWV_Vehicle.json";
66 FString PowertrainJSON = "hmmwv/powertrain/HMMWV_ShaftsPowertrain.json";
67 FString TireJSON = "hmmwv/tire/HMMWV_Pac02Tire.json";
68 FString BaseJSONPath = "";
69
70public:
71
72
73 static void CreateChronoMovementComponent(
75 uint64_t MaxSubsteps,
76 float MaxSubstepDeltaTime,
77 FString VehicleJSON = "",
78 FString PowertrainJSON = "",
79 FString TireJSON = "",
80 FString BaseJSONPath = "");
81
82 #ifdef WITH_CHRONO
83 virtual void BeginPlay() override;
84
85 void InitializeChronoVehicle();
86
87 void ProcessControl(FVehicleControl &Control) override;
88
89 void TickComponent(float DeltaTime,
90 ELevelTick TickType,
91 FActorComponentTickFunction* ThisTickFunction) override;
92
93 void AdvanceChronoSimulation(float StepSize);
94
95 virtual FVector GetVelocity() const override;
96
97 virtual int32 GetVehicleCurrentGear() const override;
98
99 virtual float GetVehicleForwardSpeed() const override;
100
101 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
102 #endif
103
104 virtual void DisableSpecialPhysics() override;
105
106private:
107
108 void DisableChronoPhysics();
109
110 UFUNCTION()
111 void OnVehicleHit(AActor *Actor,
112 AActor *OtherActor,
113 FVector NormalImpulse,
114 const FHitResult &Hit);
115
116 // On car mesh overlap, only works when carsim is enabled
117 // (this event triggers when overlapping with static environment)
118 UFUNCTION()
119 void OnVehicleOverlap(UPrimitiveComponent* OverlappedComponent,
120 AActor* OtherActor,
121 UPrimitiveComponent* OtherComp,
122 int32 OtherBodyIndex,
123 bool bFromSweep,
124 const FHitResult & SweepResult);
125};
Base class for CARLA wheeled vehicles.