RoveSoSimulator
Loading...
Searching...
No Matches
ImuComponent.h
1// Copyright Mars Rover 2025
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Actor.h"
7#include "ImuComponent.generated.h"
8
10class URoveCommManifestWrapper;
11
12/**
13 * @brief IMU DESC
14 */
15UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
16class ROVESOSIMULATOR_API UImuComponent : public UActorComponent
17{
18 GENERATED_BODY()
19
20public:
21 UImuComponent();
22
23 UFUNCTION(BlueprintCallable, Category = "RoveComm")
24 void InitializeRoveComm(URoveCommUDPWrapper* InUDPWrapper, URoveCommManifestWrapper* InManifestWrapper);
25
26 // Expose IMU data to blueprints for debugging/monitoring
27 UPROPERTY(BlueprintReadOnly, Category = "IMU")
28 FVector LinearAcceleration;
29
30 UPROPERTY(BlueprintReadOnly, Category = "IMU")
31 FVector AngularVelocity;
32
33 UPROPERTY(BlueprintReadOnly, Category = "IMU")
34 FQuat Orientation;
35
36 // Option to include gravity in acceleration (real IMUs measure gravity)
37 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IMU")
38 bool bIncludeGravity = true;
39
40 // Gravity magnitude in m/s^2 (default Earth gravity)
41 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IMU")
42 float GravityMagnitude = 9.81f;
43
44 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RoveComm")
45 URoveCommUDPWrapper* UDPWrapper;
46
47 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RoveComm")
48 URoveCommManifestWrapper* ManifestWrapper;
49
50 // The IP address and Port to send the IMU data to.
51 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RoveComm")
52 FString TargetIPAddress = "127.0.0.1";
53
54 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RoveComm")
55 int32 TargetPort = 11000;
56
57
58protected:
59 virtual void BeginPlay() override;
60
61public:
62 virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
63
64private:
65 // State variables to store data from the previous frame
66 FVector LastVelocity;
67 FTransform LastTransform;
68 bool bIsFirstFrame;
69
70 // Private function to perform the calculations
71 void UpdateImuData(float DeltaTime);
72
73 // Function to handle coordinate system transformation
74 void TransformToZedImuFrame(
75 const FVector& InLinearAcceleration,
76 const FVector& InAngularVelocity,
77 const FQuat& InOrientation,
78 FVector& OutLinearAcceleration,
79 FVector& OutAngularVelocity,
80 FQuat& OutOrientation
81 );
82
83 // Helper function to calculate angular velocity from quaternion delta
84 FVector CalculateAngularVelocity(const FQuat& CurrentQuat, const FQuat& PreviousQuat, float DeltaTime);
85
86 bool bIsRoveCommInitialized;
87 int32 AccelDataId;
88 int32 ImuDataId;
89 int32 GyroDataId;
90 int32 QuatDataId;
91};
Blueprintable wrapper class for RoveCommUDP to allow usage in Unreal Engine Blueprints.
Definition RoveCommUDPWrapper.h:25