CARLA
Loading...
Searching...
No Matches
VehicleStatusSensor.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
10
13
17
18#include "VehicleStatusSensor.generated.h"
19
21
22// Structure imported from LibCarla
24
25USTRUCT(BlueprintType)
27{
28 GENERATED_BODY()
29
30 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Velocity")
31 FVector Velocity;
32
33 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Velocity")
34 FVector AngularVelocity;
35
36 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Velocity")
37 FRotator RotationRate;
38
40 : Velocity(FVector::ZeroVector)
41 , AngularVelocity(FVector::ZeroVector)
42 , RotationRate(FRotator::ZeroRotator)
43 {
44 }
45
46 float GetSpeed() const
47 {
48 return Velocity.Size();
49 }
50
51 FString ToString() const
52 {
53 return FString::Printf(TEXT("Velocity: %s | Angular Velocity: %s | Rotation Rate: %s"),
54 *Velocity.ToString(),
55 *AngularVelocity.ToString(),
56 *RotationRate.ToString());
57 }
58};
59
60/// Vehicle status sensor ("sensor.other.vehicle_status"): attached to a
61/// vehicle, streams a packed kinematic + control state snapshot each tick and
62/// forwards it to the ROS2 side, where it feeds the six Autoware
63/// /vehicle/status/* report publishers. Ported from tier4/autoware-support.
64UCLASS()
65class CARLA_API AVehicleStatusSensor : public ASensor
66{
67 GENERATED_BODY()
68
69public:
70
71 explicit AVehicleStatusSensor(const FObjectInitializer &ObjectInitializer);
72
73 // Carla blueprint definition (get sensor.other.vehicle_status in BP)
74 static FActorDefinition GetSensorDefinition();
75
76 // Called by Carla's spawning pipeline with user attributes
77 virtual void Set(const FActorDescription &ActorDescription) override;
78
79 virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override;
80
81protected:
82
83 virtual void BeginPlay() override;
84
85 // Publish frequency
86 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Sensor|Rate", meta=(ClampMin="1.0", UIMin="1.0"))
87 float MinRateHz = 1.0f;
88 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Sensor|Rate", meta=(ClampMin="1.0", UIMin="1.0"))
89 float MaxRateHz = 1000.0f;
90
91 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Sensor|Rate", meta=(ClampMin="1.0", ClampMax="1000.0", UIMin="1.0", UIMax="1000.0"))
92 float TargetRateHz = 30.0f;
93
94private:
95
96 // Cached parent vehicle
97 TWeakObjectPtr<ACarlaWheeledVehicle> OwningVehicle;
98 FVelocityInfo VelocityInfo;
99
100 // Find parent helpers
101 FTimerHandle CheckParentTimerHandle;
102 void CheckForParentVehicle();
103 TObjectPtr<ACarlaWheeledVehicle> FindAttachmentParentVehicle() const;
104
105 // Helpers
106 void CollectAndStream(float DeltaSeconds);
107 void SetVelocityInfoToLocal(const AActor* VehicleActor);
108
109 // Scale UE velocity from cm/s to m/s
110 template<typename T>
111 static FORCEINLINE T CmpsToMps(const T& v_cmps)
112 {
113 return v_cmps * 0.01f;
114 }
115};
Base class for CARLA wheeled vehicles.
virtual void BeginPlay() override
Vehicle status sensor ("sensor.other.vehicle_status"): attached to a vehicle, streams a packed kinema...
A definition of a Carla Actor with all the variation and attributes.
A description of a Carla Actor with all its variation.
FString ToString() const
float GetSpeed() const
Snapshot of a vehicle's kinematic + control state, streamed each tick by the Autoware VehicleStatusSe...