Agrarsense
Weather.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "GameFramework/Actor.h"
10#include "Engine/World.h"
11
12#include "WeatherParameters.h"
13#include "Season.h"
14
15#include "ROSIntegration/Public/std_msgs/String.h"
16
17#include "Weather.generated.h"
18
19class UROSIntegrationGameInstance;
20class UTopic;
21
22DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLevelEventDelegate_WeatherChanged, FWeatherParameters, weatherParameters);
23
24/*
25* This Actor class handles changing simulation Weather.
26* When Weather is changed, either through user interface or ROS (.json),
27* an event is dispatched and Weather values are changed in BP_Weather blueprint.
28*/
29UCLASS(Abstract)
30class AGRARSENSE_API AWeather : public AActor
31{
32 GENERATED_BODY()
33
34public:
35
36 AWeather(const FObjectInitializer& ObjectInitializer);
37
43 UFUNCTION(BlueprintCallable)
44 void UpdateWeather(const FWeatherParameters& WeatherParameters, bool updateToROS);
45
46 /*
47 * Export current Weather to JSON file.
48 */
49 UFUNCTION(BlueprintCallable)
50 FString ExportToJSON(const FString& FileName);
51
55 UFUNCTION(BlueprintCallable)
56 void ResetWeather();
57
61 UFUNCTION(BlueprintCallable, BlueprintPure)
62 ESeason GetCurrentSeason();
63
69 UFUNCTION(BlueprintCallable, BlueprintPure)
70 ESeason GetSeasonForMonth(const int Month);
71
75 UFUNCTION(BlueprintCallable)
76 const FWeatherParameters& GetCurrentWeather() const
77 {
78 return CurrentWeather;
79 }
80
84 UPROPERTY(BlueprintAssignable)
85 FLevelEventDelegate_WeatherChanged OnWeatherChanged;
86
87protected:
88
89 virtual void BeginPlay() override;
90
91 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
92
93private:
94
95 UFUNCTION()
96 void ROSBridgeStateChanged(EROSState ROSState);
97
98 void DestroyTopic();
99
100 void InitializeROSTopic();
101
102 void SendWeatherData(FWeatherParameters Parameters);
103
104 FWeatherParameters CurrentWeather;
105
106 UPROPERTY()
107 UTopic* WeatherTopic = nullptr;
108
109 UPROPERTY()
110 UROSIntegrationGameInstance* RosInstance = nullptr;
111
112 bool ROSConnected = false;
113
114 UPROPERTY()
115 TArray<FWeatherParameters> WeatherPresets;
116
117 TSharedPtr<ROSMessages::std_msgs::String> Message;
118
119 const FWeatherParameters Default = { 0.0f, 0.0f, 0.1f, 0.05f, 0.0f, 0.2f, 0.0f, 15.0f, 0.0f, 0.0f, 7, 9 };
120};
EROSState
Definition: ROSState.h:16
ESeason
Definition: Season.h:12
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLevelEventDelegate_WeatherChanged, FWeatherParameters, weatherParameters)