CARLA
ChronoMovementComponent.h
Go to the documentation of this file.
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
37 class UERayCastTerrain : public chrono::vehicle::ChTerrain
38 {
39  ACarlaWheeledVehicle* CarlaVehicle;
40  chrono::vehicle::ChVehicle* ChronoVehicle;
41 public:
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 
51 UCLASS(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 
70 public:
71 
72 
73  static void CreateChronoMovementComponent(
74  ACarlaWheeledVehicle* Vehicle,
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 private:
105 
106  void DisableChronoPhysics();
107 
108  UFUNCTION()
109  void OnVehicleHit(AActor *Actor,
110  AActor *OtherActor,
111  FVector NormalImpulse,
112  const FHitResult &Hit);
113 
114  // On car mesh overlap, only works when carsim is enabled
115  // (this event triggers when overlapping with static environment)
116  UFUNCTION()
117  void OnVehicleOverlap(UPrimitiveComponent* OverlappedComponent,
118  AActor* OtherActor,
119  UPrimitiveComponent* OtherComp,
120  int32 OtherBodyIndex,
121  bool bFromSweep,
122  const FHitResult & SweepResult);
123 };
geom::Location Location
Definition: rpc/Location.h:14
carla::SharedPtr< cc::Actor > Actor
Base class for CARLA wheeled vehicles.