Agrarsense
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
UROSCommands Class Reference

#include <ROSCommands.h>

Inheritance diagram for UROSCommands:
Inheritance graph
[legend]
Collaboration diagram for UROSCommands:
Collaboration graph
[legend]

Public Member Functions

void TryExecuteCommand (const FString &Command)
 

Private Member Functions

void Init ()
 
void Destroy ()
 
UWorld * GetGameWorld ()
 
UAgrarsenseSettingsGetSettings ()
 
void AddCommands ()
 
void SetupROSCommandTopic ()
 
void DestroyROSTopic ()
 
void ParseIncomingMessage (const FString Message)
 
void ROSBridgeStateChanged (EROSState state)
 
bool TryParseBoolean (const FString &String, bool &OutBool)
 
void HandlePrintAvailableCommands (const FString &Variable)
 
void HandleQuit (const FString &Variable)
 
void HandlePauseSimulator (const FString &Variable)
 
void HandleUnPauseSimulator (const FString &Variable)
 
void HandleAdvanceOneFrame (const FString &Variable)
 
void HandleAdvanceFrames (const FString &Variable)
 
void HandleAdvanceTime (const FString &Variable)
 
void HandleChangeMap (const FString &Variable)
 
void HandleUnrealCommand (const FString &Variable)
 
void HandleTeleportSpectator (const FString &Variable)
 
void HandleTeleportActorByID (const FString &Variable)
 
void HandleTryDestroyObjectByID (const FString &Variable)
 
void HandleDestroyAllSensors (const FString &Variable)
 
void HandleDestroyAllWalkers (const FString &Variable)
 
void HandleDestroyAllVehicles (const FString &Variable)
 
void HandlePrintMaps (const FString &Variable)
 
void HandlePrintAllSensors (const FString &Variable)
 
void HandlePrintAllVehicles (const FString &Variable)
 
void HandlePrintAllWalkers (const FString &Variable)
 
void PrintActorInformation (const FString &Variable, UClass *ActorClass, const FString &ActorTypeName)
 
void HandlePrintIds (const FString &Variable)
 
void HandleSetGlobalTargetFrameRate (const FString &Variable)
 
void HandleSetGlobalTimeDilation (const FString &Variable)
 
void HandleSetQualityLevel (const FString &Variable)
 
void HandleSetWorldRendering (const FString &Variable)
 
void HandleSetSaveCombinedPointcloudToDisk (const FString &Variable)
 
void HandleSpawnObjects (const FString &Variable)
 
void HandleExportAll (const FString &Variable)
 
void HandleExportWeather (const FString &Variable)
 
void HandleExportWalkers (const FString &Variable)
 
void HandleExportVehicles (const FString &Variable)
 
void HandleExportSensors (const FString &Variable)
 
void HandleExportFoliage (const FString &Variable)
 
void HandleExportProps (const FString &Variable)
 
void HandleVisualizeOverlapSensorsBounds (const FString &Variable)
 
void HandleChangeOverlapSensorBounds (const FString &Variable)
 
void HandleChangeOverlapSensorPosition (const FString &Variable)
 
void HandleMoveWalkerToAndDestroy (const FString &Variable)
 
void HandleMoveWalkerToAndStop (const FString &Variable)
 
void HandleMoveWalkerTo (const FString &Variable, EWalkerEndAction EndAction)
 
void HandleStopWalker (const FString &Variable)
 
void HandleResumeWalker (const FString &Variable)
 
void HandleSetWalkerMovement (const FString &Variable, bool IsPaused)
 
void HandleMoveDroneTo (const FString &Variable, EDroneEndAction EndAction)
 
void HandleMoveDroneToAndStop (const FString &Variable)
 
void HandleSetAllSensorsEnabled (const FString &Variable)
 
void HandleEnableAllSensors (const FString &Variable)
 
void HandleDisableAllSensors (const FString &Variable)
 
void HandleSetSensorEnabled (const FString &Variable)
 
void HandleSetWPO (const FString &Variable)
 
void HandleSetNaniteMaxPixelsPerEdge (const FString &Variable)
 
void HandleDestroyTreesArea (const FString &Variable)
 
void HandleDestroyActorsArea (const FString &Variable)
 
void HandleDestroyActors (const FString &Variable, bool OnlyTrees)
 

Private Attributes

UTopic * CommandTopic = nullptr
 
UROSIntegrationGameInstance * RosInstance = nullptr
 

Static Private Attributes

static TMap< FString, FCommandCommandHandlers
 

Friends

class AAgrarsenseGameModeBase
 

Detailed Description

Definition at line 46 of file ROSCommands.h.

Member Function Documentation

◆ AddCommands()

void UROSCommands::AddCommands ( )
private

Definition at line 84 of file ROSCommands.cpp.

85{
86 // To call from Terminal:
87 // rostopic pub /Agrarsense/in/commands std_msgs/String "{COMMAND} {VARIABLE}" --once
88 // rostopic pub /Agrarsense/in/commands std_msgs/String "help" --once
89
90 if (!CommandHandlers.IsEmpty())
91 {
92 return;
93 }
94
96
97 // General commands
98 CommandHandlers.Add(TEXT("help"), FCommand(&UROSCommands::HandlePrintAvailableCommands, 0.1f, "Print all commands"));
99 CommandHandlers.Add(TEXT("quit"), FCommand(&UROSCommands::HandleQuit, 1.0f, "Quits the Simulator"));
100 CommandHandlers.Add(TEXT("loadmap"), FCommand(&UROSCommands::HandleChangeMap, 5.0f, TEXT("load map by name")));
101 CommandHandlers.Add(TEXT("unrealcommand"), FCommand(&UROSCommands::HandleUnrealCommand, 0.05f, TEXT("Execute Unreal engine console command")));
102
103 // Pause commands
104 CommandHandlers.Add(TEXT("pause"), FCommand(&UROSCommands::HandlePauseSimulator, 0.01f, "Pauses the Simulator after current frame has finished"));
105 CommandHandlers.Add(TEXT("unpause"), FCommand(&UROSCommands::HandleUnPauseSimulator, 0.01f, "Un pauses the Simulator immediately upon receiving the message"));
106 CommandHandlers.Add(TEXT("nextframe"), FCommand(&UROSCommands::HandleAdvanceOneFrame, 0.01f, "Advance one frame"));
107 CommandHandlers.Add(TEXT("advanceframes"), FCommand(&UROSCommands::HandleAdvanceFrames, 0.01f, "Advance given amount of frames"));
108 CommandHandlers.Add(TEXT("advancetime"), FCommand(&UROSCommands::HandleAdvanceTime, 0.01f, "Advance given amount of time in seconds"));
109
110 // Teleport commands
111 CommandHandlers.Add(TEXT("teleportspectator"), FCommand(&UROSCommands::HandleTeleportSpectator, 0.05f, TEXT("x,y,z or x,y,z,yaw,pitch,roll")));
112 CommandHandlers.Add(TEXT("teleportbyid"), FCommand(&UROSCommands::HandleTeleportActorByID, 0.05f, TEXT("ID of Actor, x,y,z or x,y,z,yaw,pitch,roll")));
113
114 // Destroy commands
115 CommandHandlers.Add(TEXT("destroyobjectbyid"), FCommand(&UROSCommands::HandleTryDestroyObjectByID, 0.05f, TEXT("Try to destroy object by id")));
116 CommandHandlers.Add(TEXT("destroyallsensors"), FCommand(&UROSCommands::HandleDestroyAllSensors, 1.0f, TEXT("Destroy all sensors")));
117 CommandHandlers.Add(TEXT("destroyallwalkers"), FCommand(&UROSCommands::HandleDestroyAllWalkers, 1.0f, TEXT("Destroy all sensors")));
118 CommandHandlers.Add(TEXT("destroyallvehicles"), FCommand(&UROSCommands::HandleDestroyAllVehicles, 1.0f, TEXT("Destroy all sensors")));
119
120 // Volume commands
121 // ex. "destroytrees 0,0,0 300,300,300" - destroys all tree actors within certain box area.
122 // ex. "destroyassets 0,0,0 300,300,300" - destroys all Instanced actors within certain box area.
123 CommandHandlers.Add(TEXT("destroytreesarea"), FCommand(&UROSCommands::HandleDestroyTreesArea, 0.05f, TEXT("x,y,z sizeX,sizeY,sizeZ")));
124 CommandHandlers.Add(TEXT("destroyassetsarea"), FCommand(&UROSCommands::HandleDestroyActorsArea, 0.05f, TEXT("x,y,z sizeX,sizeY,sizeZ")));
125
126 // Print commands
127 CommandHandlers.Add(TEXT("getmaps"), FCommand(&UROSCommands::HandlePrintMaps, 0.5f, TEXT("Print all available maps")));
128 CommandHandlers.Add(TEXT("getsensors"), FCommand(&UROSCommands::HandlePrintAllSensors, 0.1f, TEXT("Print all sensors information")));
129 CommandHandlers.Add(TEXT("getvehicles"), FCommand(&UROSCommands::HandlePrintAllVehicles, 0.1f, TEXT("Print all vehicles information")));
130 CommandHandlers.Add(TEXT("getwalkers"), FCommand(&UROSCommands::HandlePrintMaps, 0.1f, TEXT("print all walkers information")));
131 CommandHandlers.Add(TEXT("getids"), FCommand(&UROSCommands::HandlePrintIds, 0.1f, TEXT("print all ids")));
132
133 // Set commands
134 CommandHandlers.Add(TEXT("setglobaltargetframeRate"), FCommand(&UROSCommands::HandleSetGlobalTargetFrameRate, 1.0f, TEXT("0 - 300")));
135 CommandHandlers.Add(TEXT("setglobaltimedilation"), FCommand(&UROSCommands::HandleSetGlobalTimeDilation, 1.0f, TEXT("0.0f - 10.0f")));
136 CommandHandlers.Add(TEXT("setqualityLevel"), FCommand(&UROSCommands::HandleSetQualityLevel, 2.0f, TEXT("low / ultra")));
137 CommandHandlers.Add(TEXT("setworldrendering"), FCommand(&UROSCommands::HandleSetWorldRendering, 1.0f, TEXT("true / false")));
138 CommandHandlers.Add(TEXT("setsavecombinedpointcloud"), FCommand(&UROSCommands::HandleSetSaveCombinedPointcloudToDisk, 0.05f, TEXT("true / false")));
139 CommandHandlers.Add(TEXT("setwpodistance"), FCommand(&UROSCommands::HandleSetWPO, 0.5f, TEXT("Set WPO render distance in cm")));
140 CommandHandlers.Add(TEXT("setnanitemaxpixelsperedge"), FCommand(&UROSCommands::HandleSetNaniteMaxPixelsPerEdge, 0.5f, TEXT("Set Nanite max pixels per edge")));
141
142 // Sensor commands
143 CommandHandlers.Add(TEXT("setallsensorsenabled"), FCommand(&UROSCommands::HandleSetAllSensorsEnabled, 1.0f, TEXT("true / false")));
144 CommandHandlers.Add(TEXT("enableallsensors"), FCommand(&UROSCommands::HandleEnableAllSensors, 1.0f, TEXT("true / false")));
145 CommandHandlers.Add(TEXT("disableallsensors"), FCommand(&UROSCommands::HandleDisableAllSensors, 1.0f, TEXT("true / false")));
146 CommandHandlers.Add(TEXT("setsensorenabled"), FCommand(&UROSCommands::HandleSetSensorEnabled, 1.0f, TEXT("ID true/false")));
147
148 // Spawn/change objects commands. They all call the same function. They are defined separately for clarity.
149 CommandHandlers.Add(TEXT("spawnobjects"), FCommand(&UROSCommands::HandleSpawnObjects, 0.05f, TEXT("Spawn objects from JSON file")));
150 CommandHandlers.Add(TEXT("changeweather"), FCommand(&UROSCommands::HandleSpawnObjects, 0.05f, TEXT("change weather from JSON file")));
151 CommandHandlers.Add(TEXT("changecolors"), FCommand(&UROSCommands::HandleSpawnObjects, 0.05f, TEXT("change weather from JSON file")));
152
153 // Exports
154 CommandHandlers.Add(TEXT("exportall"), FCommand(&UROSCommands::HandleExportAll, 1.0f, TEXT("Export all spanwed things to JSON file")));
155 CommandHandlers.Add(TEXT("exportweather"), FCommand(&UROSCommands::HandleExportWeather, 1.0f, TEXT("Export current weather to JSON file")));
156 CommandHandlers.Add(TEXT("exportwalkers"), FCommand(&UROSCommands::HandleExportWalkers, 1.0f, TEXT("Export all Walkers to JSON file")));
157 CommandHandlers.Add(TEXT("exportvehicles"), FCommand(&UROSCommands::HandleExportVehicles, 1.0f, TEXT("Export all Vehicles to JSON file")));
158 CommandHandlers.Add(TEXT("exportsensors"), FCommand(&UROSCommands::HandleExportSensors, 1.0f, TEXT("Export all Sensors to JSON file")));
159 CommandHandlers.Add(TEXT("exportprops"), FCommand(&UROSCommands::HandleExportProps, 1.0f, TEXT("Export all props to JSON file")));
160 CommandHandlers.Add(TEXT("exportfoliage"), FCommand(&UROSCommands::HandleExportFoliage, 1.0f, TEXT("Export all Foliage to JSON file")));
161
162 // Overlap sensor commands
163 // changeoverlapbounds format: 'changeoverlapbounds sensor_id 500,500,500'
164 // changeoverlapposition format: 'changeoverlapposition sensor_id 0,0,0'
165 CommandHandlers.Add(TEXT("visoverlapbounds"), FCommand(&UROSCommands::HandleVisualizeOverlapSensorsBounds, 0.05f, TEXT("Visualize All Overlap sensors bounds")));
166 CommandHandlers.Add(TEXT("changeoverlapbounds"), FCommand(&UROSCommands::HandleChangeOverlapSensorBounds, 0.05f, TEXT("Change Overlap sensor area bounds")));
167 CommandHandlers.Add(TEXT("changeoverlapposition"), FCommand(&UROSCommands::HandleChangeOverlapSensorPosition, 0.05f, TEXT("Change Overlap sensor relative position")));
168
169 // Walker commands
170 CommandHandlers.Add(TEXT("movewalkerto"), FCommand(&UROSCommands::HandleMoveWalkerToAndStop, 0.05f, TEXT("ID (position or position,rotation)")));
171 CommandHandlers.Add(TEXT("movewalkertoanddestroy"), FCommand(&UROSCommands::HandleMoveWalkerToAndDestroy, 0.05f, TEXT("ID (position or position,rotation)")));
172 CommandHandlers.Add(TEXT("stopwalker"), FCommand(&UROSCommands::HandleStopWalker, 0.05f, TEXT("ID of the Walker")));
173 CommandHandlers.Add(TEXT("resumewalker"), FCommand(&UROSCommands::HandleResumeWalker, 0.05f, TEXT("ID of the Walker")));
174
175 // Drone commands
176 CommandHandlers.Add(TEXT("movedroneto"), FCommand(&UROSCommands::HandleMoveDroneToAndStop, 0.05f, TEXT("ID (position)")));
177}
void HandleTeleportActorByID(const FString &Variable)
void HandleUnrealCommand(const FString &Variable)
void HandleChangeOverlapSensorBounds(const FString &Variable)
void HandleTeleportSpectator(const FString &Variable)
void HandlePrintAllVehicles(const FString &Variable)
void HandlePrintAllSensors(const FString &Variable)
void HandleDestroyActorsArea(const FString &Variable)
static TMap< FString, FCommand > CommandHandlers
Definition: ROSCommands.h:73
void HandleAdvanceOneFrame(const FString &Variable)
void HandleUnPauseSimulator(const FString &Variable)
void HandlePrintAvailableCommands(const FString &Variable)
void HandleAdvanceTime(const FString &Variable)
void HandleExportAll(const FString &Variable)
void HandleExportSensors(const FString &Variable)
void HandleExportVehicles(const FString &Variable)
void HandleSetSaveCombinedPointcloudToDisk(const FString &Variable)
void HandleDisableAllSensors(const FString &Variable)
void HandleSetWPO(const FString &Variable)
void HandleChangeMap(const FString &Variable)
void HandleExportWalkers(const FString &Variable)
void HandleResumeWalker(const FString &Variable)
void HandleSetWorldRendering(const FString &Variable)
void HandleSetGlobalTimeDilation(const FString &Variable)
void HandleDestroyAllSensors(const FString &Variable)
void HandleMoveWalkerToAndStop(const FString &Variable)
void HandleExportWeather(const FString &Variable)
void HandleExportFoliage(const FString &Variable)
void HandleQuit(const FString &Variable)
void HandleSetAllSensorsEnabled(const FString &Variable)
void HandleChangeOverlapSensorPosition(const FString &Variable)
void HandleSetSensorEnabled(const FString &Variable)
void HandleTryDestroyObjectByID(const FString &Variable)
void HandleVisualizeOverlapSensorsBounds(const FString &Variable)
void HandleEnableAllSensors(const FString &Variable)
void HandleDestroyAllVehicles(const FString &Variable)
void HandleStopWalker(const FString &Variable)
void HandleMoveDroneToAndStop(const FString &Variable)
void HandleDestroyAllWalkers(const FString &Variable)
void HandleMoveWalkerToAndDestroy(const FString &Variable)
void HandleSetNaniteMaxPixelsPerEdge(const FString &Variable)
void HandlePrintMaps(const FString &Variable)
void HandleSpawnObjects(const FString &Variable)
void HandleDestroyTreesArea(const FString &Variable)
void HandleSetGlobalTargetFrameRate(const FString &Variable)
void HandlePrintIds(const FString &Variable)
void HandleAdvanceFrames(const FString &Variable)
void HandleSetQualityLevel(const FString &Variable)
void HandlePauseSimulator(const FString &Variable)
void HandleExportProps(const FString &Variable)

References CommandHandlers, HandleAdvanceFrames(), HandleAdvanceOneFrame(), HandleAdvanceTime(), HandleChangeMap(), HandleChangeOverlapSensorBounds(), HandleChangeOverlapSensorPosition(), HandleDestroyActorsArea(), HandleDestroyAllSensors(), HandleDestroyAllVehicles(), HandleDestroyAllWalkers(), HandleDestroyTreesArea(), HandleDisableAllSensors(), HandleEnableAllSensors(), HandleExportAll(), HandleExportFoliage(), HandleExportProps(), HandleExportSensors(), HandleExportVehicles(), HandleExportWalkers(), HandleExportWeather(), HandleMoveDroneToAndStop(), HandleMoveWalkerToAndDestroy(), HandleMoveWalkerToAndStop(), HandlePauseSimulator(), HandlePrintAllSensors(), HandlePrintAllVehicles(), HandlePrintAvailableCommands(), HandlePrintIds(), HandlePrintMaps(), HandleQuit(), HandleResumeWalker(), HandleSetAllSensorsEnabled(), HandleSetGlobalTargetFrameRate(), HandleSetGlobalTimeDilation(), HandleSetNaniteMaxPixelsPerEdge(), HandleSetQualityLevel(), HandleSetSaveCombinedPointcloudToDisk(), HandleSetSensorEnabled(), HandleSetWorldRendering(), HandleSetWPO(), HandleSpawnObjects(), HandleStopWalker(), HandleTeleportActorByID(), HandleTeleportSpectator(), HandleTryDestroyObjectByID(), HandleUnPauseSimulator(), HandleUnrealCommand(), and HandleVisualizeOverlapSensorsBounds().

Referenced by Init().

◆ Destroy()

void UROSCommands::Destroy ( )
private

Definition at line 59 of file ROSCommands.cpp.

60{
62}
void DestroyROSTopic()

References DestroyROSTopic().

Referenced by AAgrarsenseGameModeBase::EndPlay().

◆ DestroyROSTopic()

void UROSCommands::DestroyROSTopic ( )
private

Definition at line 193 of file ROSCommands.cpp.

194{
195 if (CommandTopic)
196 {
197 CommandTopic->Unadvertise();
198 CommandTopic->Unsubscribe();
199 CommandTopic->MarkAsDisconnected();
200 CommandTopic->ConditionalBeginDestroy();
201 CommandTopic = nullptr;
202 }
203}
UTopic * CommandTopic
Definition: ROSCommands.h:102

References CommandTopic.

Referenced by Destroy(), and ROSBridgeStateChanged().

◆ GetGameWorld()

UWorld * UROSCommands::GetGameWorld ( )
private

◆ GetSettings()

UAgrarsenseSettings * UROSCommands::GetSettings ( )
private

◆ HandleAdvanceFrames()

void UROSCommands::HandleAdvanceFrames ( const FString &  Variable)
private

Definition at line 376 of file ROSCommands.cpp.

377{
378 int32 FrameCount = 0;
379 if (!Variable.IsNumeric())
380 {
381 return;
382 }
383
384 FrameCount = FCString::Atoi(*Variable);
385 if (FrameCount != 0)
386 {
387 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
388 if (AgrarsenseSettings)
389 {
390 AgrarsenseSettings->AdvanceFrameCount(FrameCount);
391 }
392 }
393}
void AdvanceFrameCount(int32 FramesToAdvance)
UAgrarsenseSettings * GetSettings()
Definition: ROSCommands.cpp:79

References UAgrarsenseSettings::AdvanceFrameCount(), and GetSettings().

Referenced by AddCommands().

◆ HandleAdvanceOneFrame()

void UROSCommands::HandleAdvanceOneFrame ( const FString &  Variable)
private

Definition at line 367 of file ROSCommands.cpp.

368{
369 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
370 if (AgrarsenseSettings)
371 {
372 AgrarsenseSettings->AdvanceFrameCount(1);
373 }
374}

References UAgrarsenseSettings::AdvanceFrameCount(), and GetSettings().

Referenced by AddCommands().

◆ HandleAdvanceTime()

void UROSCommands::HandleAdvanceTime ( const FString &  Variable)
private

Definition at line 395 of file ROSCommands.cpp.

396{
397 float Time = 0.0f;
398 if (!Variable.IsNumeric())
399 {
400 return;
401 }
402
403 Time = FCString::Atof(*Variable);
404 if (Time != 0.0f)
405 {
406 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
407 if (AgrarsenseSettings)
408 {
409 AgrarsenseSettings->AdvanceTime(Time);
410 }
411 }
412}
void AdvanceTime(float TimeToAdvance)

References UAgrarsenseSettings::AdvanceTime(), and GetSettings().

Referenced by AddCommands().

◆ HandleChangeMap()

void UROSCommands::HandleChangeMap ( const FString &  Variable)
private

Definition at line 414 of file ROSCommands.cpp.

415{
416 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
417 if (AgrarsenseSettings)
418 {
419 AgrarsenseSettings->ChangeMapByName(Variable);
420 }
421}
void ChangeMapByName(FString MapName)

References UAgrarsenseSettings::ChangeMapByName(), and GetSettings().

Referenced by AddCommands().

◆ HandleChangeOverlapSensorBounds()

void UROSCommands::HandleChangeOverlapSensorBounds ( const FString &  Variable)
private

Definition at line 880 of file ROSCommands.cpp.

881{
882 FString ID;
883 FString BoundsString;
884
885 TArray<FString> Tokens;
886 Variable.ParseIntoArray(Tokens, TEXT(" "), true);
887
888 if (Tokens.Num() < 2)
889 {
890 // Incoming parameters were invalid, return
891 return;
892 }
893
894 ID = Tokens[0];
895 BoundsString = Tokens[1];
896
897 FVector Bounds;
898 TArray<FString> BoundsTokens;
899 BoundsString.ParseIntoArray(BoundsTokens, TEXT(","), true);
900
901 if (BoundsTokens.Num() >= 3)
902 {
903 Bounds.X = FCString::Atof(*BoundsTokens[0]);
904 Bounds.Y = FCString::Atof(*BoundsTokens[1]);
905 Bounds.Z = FCString::Atof(*BoundsTokens[2]);
906
907 AActor* Actor = IActorInformation::GetActorByID(ID);
908 AOverlapSensor* Sensor = Cast<AOverlapSensor>(Actor);
909 if (Sensor)
910 {
911 Sensor->SetOverlapBounds(Bounds);
912 }
913 }
914}
void SetOverlapBounds(const FVector &NewSize)
static AActor * GetActorByID(const FString &ID)

References IActorInformation::GetActorByID(), and AOverlapSensor::SetOverlapBounds().

Referenced by AddCommands().

◆ HandleChangeOverlapSensorPosition()

void UROSCommands::HandleChangeOverlapSensorPosition ( const FString &  Variable)
private

Definition at line 916 of file ROSCommands.cpp.

917{
918 FString ID;
919 FString BoundsString;
920
921 TArray<FString> Tokens;
922 Variable.ParseIntoArray(Tokens, TEXT(" "), true);
923
924 if (Tokens.Num() < 2)
925 {
926 // Incoming parameters were invalid, return
927 return;
928 }
929
930 ID = Tokens[0];
931 BoundsString = Tokens[1];
932
933 FVector RelativePosition;
934 TArray<FString> BoundsTokens;
935 BoundsString.ParseIntoArray(BoundsTokens, TEXT(","), true);
936
937 if (BoundsTokens.Num() >= 3)
938 {
939 RelativePosition.X = FCString::Atof(*BoundsTokens[0]);
940 RelativePosition.Y = FCString::Atof(*BoundsTokens[1]);
941 RelativePosition.Z = FCString::Atof(*BoundsTokens[2]);
942
943 AActor* Actor = IActorInformation::GetActorByID(ID);
944 AOverlapSensor* Sensor = Cast<AOverlapSensor>(Actor);
945 if (Sensor)
946 {
947 Sensor->SetOverlapRelativePosition(RelativePosition);
948 }
949 }
950}
void SetOverlapRelativePosition(const FVector &Vector)

References IActorInformation::GetActorByID(), and AOverlapSensor::SetOverlapRelativePosition().

Referenced by AddCommands().

◆ HandleDestroyActors()

void UROSCommands::HandleDestroyActors ( const FString &  Variable,
bool  OnlyTrees 
)
private

Definition at line 1253 of file ROSCommands.cpp.

1254{
1255 TArray<FString> ParsedStrings;
1256 Variable.ParseIntoArray(ParsedStrings, TEXT(" "), true);
1257
1258 if (ParsedStrings.Num() != 2)
1259 {
1260 return;
1261 }
1262
1263 // Parse position
1264 TArray<FString> PositionComponents;
1265 ParsedStrings[0].ParseIntoArray(PositionComponents, TEXT(","), true);
1266
1267 if (PositionComponents.Num() != 3)
1268 {
1269 return;
1270 }
1271
1272 FVector Position(FCString::Atof(*PositionComponents[0]), FCString::Atof(*PositionComponents[1]), FCString::Atof(*PositionComponents[2]));
1273
1274 // Parse bounds
1275 TArray<FString> BoundsComponents;
1276 ParsedStrings[1].ParseIntoArray(BoundsComponents, TEXT(","), true);
1277
1278 if (BoundsComponents.Num() != 3)
1279 {
1280 return;
1281 }
1282
1283 FVector Bounds(FCString::Atof(*BoundsComponents[0]), FCString::Atof(*BoundsComponents[1]), FCString::Atof(*BoundsComponents[2]));
1284
1285 FTransform VolumeTransform;
1286 VolumeTransform.SetLocation(Position);
1287
1288 UWorld* World = GetGameWorld();
1289 if (World)
1290 {
1291 ADeletionVolume* Volume = World->SpawnActor<ADeletionVolume>(ADeletionVolume::StaticClass(), VolumeTransform);
1292 if (Volume)
1293 {
1294 // Change volume bounds
1295 Volume->ChangeOverlapBounds(Bounds);
1296
1297 // Destroy overlapping actors,
1298 // this Actor gets deleted automatically after calling this.
1299 Volume->DestroyOverlappingActors(OnlyTrees);
1300 }
1301 }
1302}
void DestroyOverlappingActors(bool OnlyTrees)
void ChangeOverlapBounds(FVector Bounds)
UWorld * GetGameWorld()
Definition: ROSCommands.cpp:69

References ADeletionVolume::ChangeOverlapBounds(), ADeletionVolume::DestroyOverlappingActors(), and GetGameWorld().

Referenced by HandleDestroyActorsArea(), and HandleDestroyTreesArea().

◆ HandleDestroyActorsArea()

void UROSCommands::HandleDestroyActorsArea ( const FString &  Variable)
private

Definition at line 1248 of file ROSCommands.cpp.

1249{
1250 HandleDestroyActors(Variable, false);
1251}
void HandleDestroyActors(const FString &Variable, bool OnlyTrees)

References HandleDestroyActors().

Referenced by AddCommands().

◆ HandleDestroyAllSensors()

void UROSCommands::HandleDestroyAllSensors ( const FString &  Variable)
private

Definition at line 582 of file ROSCommands.cpp.

583{
585}
static void DestroyAllSensors(const UObject *WorldContextObject, bool DestroyDefaultVehicleSensors=false)

References USensorUtilities::DestroyAllSensors(), and GetGameWorld().

Referenced by AddCommands().

◆ HandleDestroyAllVehicles()

void UROSCommands::HandleDestroyAllVehicles ( const FString &  Variable)
private

Definition at line 592 of file ROSCommands.cpp.

593{
594 UWorld* World = GetGameWorld();
595 if (!World)
596 {
597 return;
598 }
599
600 TArray<AActor*> Vehicles;
601 UGameplayStatics::GetAllActorsOfClass(World, AVehicle::StaticClass(), Vehicles);
602 for (AActor* Actor : Vehicles)
603 {
604 AVehicle* Vehicle = Cast<AVehicle>(Actor);
605 if (Vehicle)
606 {
607 Vehicle->Destroy();
608 }
609 }
610}

References GetGameWorld(), and Vehicle.

Referenced by AddCommands().

◆ HandleDestroyAllWalkers()

void UROSCommands::HandleDestroyAllWalkers ( const FString &  Variable)
private

Definition at line 587 of file ROSCommands.cpp.

588{
590}
static void DestroyAllWalkers()

References UAssetLibrary::DestroyAllWalkers().

Referenced by AddCommands().

◆ HandleDestroyTreesArea()

void UROSCommands::HandleDestroyTreesArea ( const FString &  Variable)
private

Definition at line 1243 of file ROSCommands.cpp.

1244{
1245 HandleDestroyActors(Variable, true);
1246}

References HandleDestroyActors().

Referenced by AddCommands().

◆ HandleDisableAllSensors()

void UROSCommands::HandleDisableAllSensors ( const FString &  Variable)
private

Definition at line 1176 of file ROSCommands.cpp.

1177{
1179}
static void DisableAllSensors(const UObject *WorldContextObject)

References USensorUtilities::DisableAllSensors(), and GetGameWorld().

Referenced by AddCommands().

◆ HandleEnableAllSensors()

void UROSCommands::HandleEnableAllSensors ( const FString &  Variable)
private

Definition at line 1171 of file ROSCommands.cpp.

1172{
1174}
static void EnableAllSensors(const UObject *WorldContextObject)

References USensorUtilities::EnableAllSensors(), and GetGameWorld().

Referenced by AddCommands().

◆ HandleExportAll()

void UROSCommands::HandleExportAll ( const FString &  Variable)
private

Definition at line 759 of file ROSCommands.cpp.

760{
761 // Below export functions do not need any incoming variable but require FString
762 FString EmptyString;
763
764 HandleExportWeather(EmptyString);
765 HandleExportWalkers(EmptyString);
766
767 // HandleExportSensors exports vehicles as well
768 //HandleExportVehicles(EmptyString);
769 HandleExportSensors(EmptyString);
770
771 HandleExportFoliage(EmptyString);
772 HandleExportProps(EmptyString);
773}

References HandleExportFoliage(), HandleExportProps(), HandleExportSensors(), HandleExportWalkers(), and HandleExportWeather().

Referenced by AddCommands().

◆ HandleExportFoliage()

void UROSCommands::HandleExportFoliage ( const FString &  Variable)
private

Definition at line 842 of file ROSCommands.cpp.

843{
844 TArray<AInstancedActor*> FoliageActors = UAssetLibrary::GetAllAddedFoliageActors();
845 USimulatorJsonExporter::ExportInstancedActorsToJSON("ExportedFoliage", FoliageActors);
846}
static TArray< AInstancedActor * > GetAllAddedFoliageActors()
static FString ExportInstancedActorsToJSON(FString FileName, const TArray< AInstancedActor * > &Actors)

References USimulatorJsonExporter::ExportInstancedActorsToJSON(), and UAssetLibrary::GetAllAddedFoliageActors().

Referenced by AddCommands(), and HandleExportAll().

◆ HandleExportProps()

void UROSCommands::HandleExportProps ( const FString &  Variable)
private

Definition at line 848 of file ROSCommands.cpp.

849{
850 TArray<AInstancedActor*> PropActors = UAssetLibrary::GetAllAddedPropActors();
851 USimulatorJsonExporter::ExportInstancedActorsToJSON("ExportedProps", PropActors);
852}
static TArray< AInstancedActor * > GetAllAddedPropActors()

References USimulatorJsonExporter::ExportInstancedActorsToJSON(), and UAssetLibrary::GetAllAddedPropActors().

Referenced by AddCommands(), and HandleExportAll().

◆ HandleExportSensors()

void UROSCommands::HandleExportSensors ( const FString &  Variable)
private

Definition at line 809 of file ROSCommands.cpp.

810{
811 UWorld* World = GetGameWorld();
812 if (!World)
813 {
814 return;
815 }
816
817 // Export all Vehicles and attached sensors
818 TArray<AActor*> Vehicles;
819 UGameplayStatics::GetAllActorsOfClass(World, AVehicle::StaticClass(), Vehicles);
820 for (AActor* Actor : Vehicles)
821 {
822 AVehicle* VehiclePtr = Cast<AVehicle>(Actor);
823 if (VehiclePtr)
824 {
825 VehiclePtr->ExportToJsonFile("ExportedVehicle");
826 }
827 }
828
829 // Export all Sensors separately as well
830 TArray<AActor*> Sensors;
831 UGameplayStatics::GetAllActorsOfClass(World, ASensor::StaticClass(), Sensors);
832 for (AActor* Actor : Sensors)
833 {
834 ASensor* SensorPtr = Cast<ASensor>(Actor);
835 if (SensorPtr)
836 {
837 SensorPtr->ExportToJsonFile("ExportedSensor");
838 }
839 }
840}
Definition: Sensor.h:44
FString ExportToJsonFile(const FString &FileName)
Definition: Sensor.cpp:113
FString ExportToJsonFile(const FString &FileName)
Definition: Vehicle.cpp:135

References ASensor::ExportToJsonFile(), AVehicle::ExportToJsonFile(), GetGameWorld(), and Sensors.

Referenced by AddCommands(), and HandleExportAll().

◆ HandleExportVehicles()

void UROSCommands::HandleExportVehicles ( const FString &  Variable)
private

Definition at line 796 of file ROSCommands.cpp.

797{
798 TArray<FVehicleData> Vehicles = UAssetLibrary::GetSpawnedVehicles();
799 for (const FVehicleData& VehicleData : Vehicles)
800 {
801 AVehicle* VehiclePtr = VehicleData.Vehicle.Get();
802 if (VehiclePtr)
803 {
804 VehiclePtr->ExportToJsonFile("ExportedVehicle");
805 }
806 }
807}
static TArray< FVehicleData > GetSpawnedVehicles()

References AVehicle::ExportToJsonFile(), and UAssetLibrary::GetSpawnedVehicles().

Referenced by AddCommands().

◆ HandleExportWalkers()

void UROSCommands::HandleExportWalkers ( const FString &  Variable)
private

Definition at line 784 of file ROSCommands.cpp.

785{
786 TArray<AWalker*> Walkers = UAssetLibrary::GetAllWalkers();
787 for (AWalker* Walker : Walkers)
788 {
789 if (Walker)
790 {
791 Walker->ExportToJsonFile("ExportedWalker");
792 }
793 }
794}
Definition: Walker.h:28
static TArray< AWalker * > GetAllWalkers()

References UAssetLibrary::GetAllWalkers(), and Walker.

Referenced by AddCommands(), and HandleExportAll().

◆ HandleExportWeather()

void UROSCommands::HandleExportWeather ( const FString &  Variable)
private

Definition at line 775 of file ROSCommands.cpp.

776{
778 if (Weather)
779 {
780 Weather->ExportToJSON("ExportedWeather");
781 }
782}
FString ExportToJSON(const FString &FileName)
Definition: Weather.cpp:115
static AWeather * GetWeatherActor(const UObject *WorldContextObject)

References AWeather::ExportToJSON(), GetGameWorld(), and UAgrarsenseStatics::GetWeatherActor().

Referenced by AddCommands(), and HandleExportAll().

◆ HandleMoveDroneTo()

void UROSCommands::HandleMoveDroneTo ( const FString &  Variable,
EDroneEndAction  EndAction 
)
private

Definition at line 1073 of file ROSCommands.cpp.

1074{
1075 // This function overrides the current parameters of the Drone identified by the given ID,
1076 // moving the Drone to the specified x,y,z position and stopping upon reaching the target.
1077 // Usage: "movedroneto drone 0,0,0" where 'drone' is the Drone ID.
1078
1079 FString ID;
1080 FString TransformString;
1081
1082 // Split the ID and rest of the message
1083 TArray<FString> Tokens;
1084 Variable.ParseIntoArray(Tokens, TEXT(" "), true);
1085 if (Tokens.Num() >= 2)
1086 {
1087 ID = Tokens[0];
1088 TransformString = Variable.RightChop(ID.Len() + 1);
1089 }
1090 else
1091 {
1092 return;
1093 }
1094
1095 // Check if this ID matches any Actor
1096 AActor* Actor = IActorInformation::GetActorByID(ID);
1097 if (!Actor)
1098 {
1099 return;
1100 }
1101
1102 APIDDrone* Drone = Cast<APIDDrone>(Actor);
1103 if (!Drone)
1104 {
1105 return;
1106 }
1107
1108 // Parse rest of the string to Transform
1109 TArray<FString> Components;
1110 TransformString.ParseIntoArray(Components, TEXT(","), true);
1111
1112 if (Components.Num() >= 3)
1113 {
1114 FVector Location;
1115 FQuat Rotation;
1116
1117 // Convert the first three components to float values for location
1118 float X = FCString::Atof(*Components[0]);
1119 float Y = FCString::Atof(*Components[1]);
1120 float Z = FCString::Atof(*Components[2]);
1121
1122 Location = FVector(X, Y, Z);
1123
1124 if (Components.Num() >= 6)
1125 {
1126 // If there are six or more components, try to parse them as rotation values
1127 float Pitch = FCString::Atof(*Components[3]);
1128 float Yaw = FCString::Atof(*Components[4]);
1129 float Roll = FCString::Atof(*Components[5]);
1130
1131 // Convert the Euler angles to a quaternion
1132 Rotation = FQuat(FRotator(Pitch, Yaw, Roll));
1133 }
1134
1135 FTransform Transform;
1136 Transform.SetLocation(Location);
1137 Transform.SetRotation(Rotation);
1138
1139 // Create new drone parameters
1140 FDroneParameters NewParams;
1142 NewParams.DroneEndAction = EndAction;
1143 //NewParams.Points.Add(Transform);
1144
1145 Drone->ChangeDroneParameters(NewParams);
1146
1147 // Change drone parameters
1148 Drone->MoveDroneToPosition(Transform);
1149 }
1150}
EDroneEndAction DroneEndAction
EDroneAction DroneAction

References Drone, FDroneParameters::DroneAction, FDroneParameters::DroneEndAction, IActorInformation::GetActorByID(), Roaming, and Transform.

Referenced by HandleMoveDroneToAndStop().

◆ HandleMoveDroneToAndStop()

void UROSCommands::HandleMoveDroneToAndStop ( const FString &  Variable)
private

Definition at line 962 of file ROSCommands.cpp.

963{
965}
void HandleMoveDroneTo(const FString &Variable, EDroneEndAction EndAction)

References HandleMoveDroneTo(), and Stop.

Referenced by AddCommands().

◆ HandleMoveWalkerTo()

void UROSCommands::HandleMoveWalkerTo ( const FString &  Variable,
EWalkerEndAction  EndAction 
)
private

Definition at line 967 of file ROSCommands.cpp.

968{
969 // This function overrides the current parameters of the Walker identified by the given ID,
970 // moving the Walker to the specified x,y,z position and stopping upon reaching the target.
971 // Usage: "movewalkerto reindeer 0,0,0" where 'reindeer' is the Walker ID.
972
973 FString ID;
974 FString TransformString;
975
976 // Split the ID and rest of the message
977 TArray<FString> Tokens;
978 Variable.ParseIntoArray(Tokens, TEXT(" "), true);
979 if (Tokens.Num() >= 2)
980 {
981 ID = Tokens[0];
982 TransformString = Variable.RightChop(ID.Len() + 1);
983 }
984 else
985 {
986 return;
987 }
988
989 // Check if this ID matches any Actor
990 AActor* Actor = IActorInformation::GetActorByID(ID);
991 if (!Actor)
992 {
993 return;
994 }
995
996 AWalker* Walker = Cast<AWalker>(Actor);
997 if (!Walker)
998 {
999 return;
1000 }
1001
1002 // Parse rest of the string to Transform
1003 TArray<FString> Components;
1004 TransformString.ParseIntoArray(Components, TEXT(","), true);
1005
1006 if (Components.Num() >= 3)
1007 {
1008 FVector Location;
1009 FQuat Rotation;
1010
1011 // Convert the first three components to float values for location
1012 float X = FCString::Atof(*Components[0]);
1013 float Y = FCString::Atof(*Components[1]);
1014 float Z = FCString::Atof(*Components[2]);
1015
1016 Location = FVector(X, Y, Z);
1017
1018 if (Components.Num() >= 6)
1019 {
1020 // If there are six or more components, try to parse them as rotation values
1021 float Pitch = FCString::Atof(*Components[3]);
1022 float Yaw = FCString::Atof(*Components[4]);
1023 float Roll = FCString::Atof(*Components[5]);
1024
1025 // Convert the Euler angles to a quaternion
1026 Rotation = FQuat(FRotator(Pitch, Yaw, Roll));
1027 }
1028
1029 FTransform Transform;
1030 Transform.SetLocation(Location);
1031 Transform.SetRotation(Rotation);
1032
1033 // Create new walker parameters
1034 FWalkerParameters NewParams;
1036 NewParams.WalkerEndAction = EndAction;
1037 NewParams.Points.Add(Transform);
1038
1039 // Change Walker parameters
1040 Walker->ChangeWalkerParameters(NewParams);
1041 }
1042}
EWalkerAction WalkerAction
TArray< FTransform > Points
EWalkerEndAction WalkerEndAction

References FollowPath, IActorInformation::GetActorByID(), FWalkerParameters::Points, Transform, Walker, FWalkerParameters::WalkerAction, and FWalkerParameters::WalkerEndAction.

Referenced by HandleMoveWalkerToAndDestroy(), and HandleMoveWalkerToAndStop().

◆ HandleMoveWalkerToAndDestroy()

void UROSCommands::HandleMoveWalkerToAndDestroy ( const FString &  Variable)
private

Definition at line 952 of file ROSCommands.cpp.

953{
955}
void HandleMoveWalkerTo(const FString &Variable, EWalkerEndAction EndAction)

References Destroy, and HandleMoveWalkerTo().

Referenced by AddCommands().

◆ HandleMoveWalkerToAndStop()

void UROSCommands::HandleMoveWalkerToAndStop ( const FString &  Variable)
private

Definition at line 957 of file ROSCommands.cpp.

References HandleMoveWalkerTo(), and Stop.

Referenced by AddCommands().

◆ HandlePauseSimulator()

void UROSCommands::HandlePauseSimulator ( const FString &  Variable)
private

Definition at line 349 of file ROSCommands.cpp.

350{
351 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
352 if (AgrarsenseSettings)
353 {
354 AgrarsenseSettings->PauseSimulationEndOfThisFrame();
355 }
356}

References GetSettings(), and UAgrarsenseSettings::PauseSimulationEndOfThisFrame().

Referenced by AddCommands().

◆ HandlePrintAllSensors()

void UROSCommands::HandlePrintAllSensors ( const FString &  Variable)
private

Definition at line 630 of file ROSCommands.cpp.

631{
632 PrintActorInformation(Variable, ASensor::StaticClass(), "sensor");
633}
void PrintActorInformation(const FString &Variable, UClass *ActorClass, const FString &ActorTypeName)

References PrintActorInformation().

Referenced by AddCommands().

◆ HandlePrintAllVehicles()

void UROSCommands::HandlePrintAllVehicles ( const FString &  Variable)
private

Definition at line 635 of file ROSCommands.cpp.

636{
637 PrintActorInformation(Variable, AVehicle::StaticClass(), "vehicle");
638}

References PrintActorInformation().

Referenced by AddCommands().

◆ HandlePrintAllWalkers()

void UROSCommands::HandlePrintAllWalkers ( const FString &  Variable)
private

Definition at line 640 of file ROSCommands.cpp.

641{
642 PrintActorInformation(Variable, AWalker::StaticClass(), "walker");
643}

References PrintActorInformation().

◆ HandlePrintAvailableCommands()

void UROSCommands::HandlePrintAvailableCommands ( const FString &  Variable)
private

Definition at line 314 of file ROSCommands.cpp.

315{
316 if (!CommandTopic)
317 {
318 return;
319 }
320
321 FString message = "Available Simulator ROS commands {COMMAND} {VALUE} || ";
322
323 for (const TPair<FString, FCommand>& CommandPair : CommandHandlers)
324 {
325 const FString& CommandString = CommandPair.Key;
326 const FCommand& CommandInfo = CommandPair.Value;
327 if (CommandInfo.DefaultValue.IsEmpty())
328 {
329 message += FString::Printf(TEXT("%s || "), *CommandString);
330 }
331 else
332 {
333 message += FString::Printf(TEXT("%s %s || "), *CommandString, *CommandInfo.DefaultValue);
334 }
335 }
336
337 SimulatorLog::Log(message);
338}
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
FString DefaultValue
Definition: ROSCommands.h:34

References CommandHandlers, CommandTopic, FCommand::DefaultValue, and SimulatorLog::Log().

Referenced by AddCommands().

◆ HandlePrintIds()

void UROSCommands::HandlePrintIds ( const FString &  Variable)
private

Definition at line 682 of file ROSCommands.cpp.

683{
685}
static void PrintAllIds()

References IActorInformation::PrintAllIds().

Referenced by AddCommands().

◆ HandlePrintMaps()

void UROSCommands::HandlePrintMaps ( const FString &  Variable)
private

Definition at line 612 of file ROSCommands.cpp.

613{
614 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
615 if (AgrarsenseSettings)
616 {
617 TArray<FString> Maps = AgrarsenseSettings->GetMapNames();
618
619 FString message;
620
621 for (const FString& map : Maps)
622 {
623 message += FString::Printf(TEXT("%s, "), *map);
624 }
625
626 SimulatorLog::Log(message);
627 }
628}
TArray< FString > GetMapNames() const

References UAgrarsenseSettings::GetMapNames(), GetSettings(), and SimulatorLog::Log().

Referenced by AddCommands().

◆ HandleQuit()

void UROSCommands::HandleQuit ( const FString &  Variable)
private

Definition at line 340 of file ROSCommands.cpp.

341{
342 UWorld* World = GetGameWorld();
343 if (GEngine && World)
344 {
345 GEngine->Exec(World, TEXT("quit force"));
346 }
347}

References GetGameWorld().

Referenced by AddCommands().

◆ HandleResumeWalker()

void UROSCommands::HandleResumeWalker ( const FString &  Variable)
private

Definition at line 1049 of file ROSCommands.cpp.

1050{
1051 HandleSetWalkerMovement(Variable, false);
1052}
void HandleSetWalkerMovement(const FString &Variable, bool IsPaused)

References HandleSetWalkerMovement().

Referenced by AddCommands().

◆ HandleSetAllSensorsEnabled()

void UROSCommands::HandleSetAllSensorsEnabled ( const FString &  Variable)
private

Definition at line 1152 of file ROSCommands.cpp.

1153{
1154 bool EnableSensors;
1155 if (!TryParseBoolean(Variable, EnableSensors))
1156 {
1157 // Failed to parse, return
1158 return;
1159 }
1160
1161 if (EnableSensors)
1162 {
1164 }
1165 else
1166 {
1168 }
1169}
bool TryParseBoolean(const FString &String, bool &OutBool)

References USensorUtilities::DisableAllSensors(), USensorUtilities::EnableAllSensors(), GetGameWorld(), and TryParseBoolean().

Referenced by AddCommands().

◆ HandleSetGlobalTargetFrameRate()

void UROSCommands::HandleSetGlobalTargetFrameRate ( const FString &  Variable)
private

Definition at line 687 of file ROSCommands.cpp.

688{
689 if (Variable.IsNumeric())
690 {
691 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
692 if (AgrarsenseSettings)
693 {
694 int32 IntValue = FCString::Atoi(*Variable);
695 AgrarsenseSettings->SetGlobalTargetFrameRate(IntValue);
696 }
697 }
698}
void SetGlobalTargetFrameRate(int NewTargetFrameRate)

References GetSettings(), and UAgrarsenseSettings::SetGlobalTargetFrameRate().

Referenced by AddCommands().

◆ HandleSetGlobalTimeDilation()

void UROSCommands::HandleSetGlobalTimeDilation ( const FString &  Variable)
private

Definition at line 700 of file ROSCommands.cpp.

701{
702 if (Variable.IsNumeric())
703 {
704 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
705 if (AgrarsenseSettings)
706 {
707 float FloatValue = FCString::Atof(*Variable);
708 AgrarsenseSettings->SetGlobalTimeDilation(FloatValue);
709 }
710 }
711}
void SetGlobalTimeDilation(float TimeDilation)

References GetSettings(), and UAgrarsenseSettings::SetGlobalTimeDilation().

Referenced by AddCommands().

◆ HandleSetNaniteMaxPixelsPerEdge()

void UROSCommands::HandleSetNaniteMaxPixelsPerEdge ( const FString &  Variable)
private

Definition at line 1230 of file ROSCommands.cpp.

1231{
1232 if (Variable.IsNumeric())
1233 {
1234 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
1235 if (AgrarsenseSettings)
1236 {
1237 float Value = FCString::Atof(*Variable);
1238 AgrarsenseSettings->SetNaniteMaxPixelsPerEdge(Value);
1239 }
1240 }
1241}
void SetNaniteMaxPixelsPerEdge(float MaxPixelsPerEdge=1.0f)

References GetSettings(), and UAgrarsenseSettings::SetNaniteMaxPixelsPerEdge().

Referenced by AddCommands().

◆ HandleSetQualityLevel()

void UROSCommands::HandleSetQualityLevel ( const FString &  Variable)
private

Definition at line 713 of file ROSCommands.cpp.

714{
715 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
716 if (AgrarsenseSettings)
717 {
718 AgrarsenseSettings->SetQualityLevelFromString(Variable);
719 }
720}
void SetQualityLevelFromString(const FString &QualityLevelString)

References GetSettings(), and UAgrarsenseSettings::SetQualityLevelFromString().

Referenced by AddCommands().

◆ HandleSetSaveCombinedPointcloudToDisk()

void UROSCommands::HandleSetSaveCombinedPointcloudToDisk ( const FString &  Variable)
private

Definition at line 738 of file ROSCommands.cpp.

739{
740 bool Save;
741 if (!TryParseBoolean(Variable, Save))
742 {
743 // Failed to parse, return
744 return;
745 }
746
748 if (LidarManager)
749 {
750 LidarManager->SetSaveCombinedCloudToDisk(Save);
751 }
752}
void SetSaveCombinedCloudToDisk(bool bSaveCombinedCloud)
static ALidarManager * GetLidarManager(const UObject *WorldContextObject)

References GetGameWorld(), UAgrarsenseStatics::GetLidarManager(), ALidarManager::SetSaveCombinedCloudToDisk(), and TryParseBoolean().

Referenced by AddCommands().

◆ HandleSetSensorEnabled()

void UROSCommands::HandleSetSensorEnabled ( const FString &  Variable)
private

Definition at line 1181 of file ROSCommands.cpp.

1182{
1183 TArray<FString> Tokens;
1184 Variable.ParseIntoArray(Tokens, TEXT(" "), true);
1185 if (Tokens.Num() < 2)
1186 {
1187 // Not enough arguments, return
1188 return;
1189 }
1190
1191 const FString& ID = Tokens[0];
1192
1193 AActor* Actor = IActorInformation::GetActorByID(ID);
1194 if (!Actor)
1195 {
1196 return;
1197 }
1198
1199 ASensor* Sensor = Cast<ASensor>(Actor);
1200 if (!Sensor)
1201 {
1202 return;
1203 }
1204
1205 FString BooleanString = Tokens[1].ToLower();
1206
1207 bool SimulateSensor;
1208 if (!TryParseBoolean(BooleanString, SimulateSensor))
1209 {
1210 // Failed to parse, return
1211 return;
1212 }
1213
1214 Sensor->SetSimulateSensor(SimulateSensor);
1215}
void SetSimulateSensor(bool SimulateSensor)
Definition: Sensor.h:151

References IActorInformation::GetActorByID(), ASensor::SetSimulateSensor(), and TryParseBoolean().

Referenced by AddCommands().

◆ HandleSetWalkerMovement()

void UROSCommands::HandleSetWalkerMovement ( const FString &  Variable,
bool  IsPaused 
)
private

Definition at line 1054 of file ROSCommands.cpp.

1055{
1056 AActor* Actor = IActorInformation::GetActorByID(Variable);
1057 AWalker* Walker = Cast<AWalker>(Actor);
1058 if (!Walker)
1059 {
1060 return;
1061 }
1062
1063 if (IsPaused)
1064 {
1065 Walker->PauseWalker();
1066 }
1067 else
1068 {
1069 Walker->ResumeWalker();
1070 }
1071}

References IActorInformation::GetActorByID(), and Walker.

Referenced by HandleResumeWalker(), and HandleStopWalker().

◆ HandleSetWorldRendering()

void UROSCommands::HandleSetWorldRendering ( const FString &  Variable)
private

Definition at line 722 of file ROSCommands.cpp.

723{
724 bool RenderWorld;
725 if (!TryParseBoolean(Variable, RenderWorld))
726 {
727 // Failed to parse, return
728 return;
729 }
730
731 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
732 if (AgrarsenseSettings)
733 {
734 AgrarsenseSettings->SetWorldRendering(RenderWorld);
735 }
736}
void SetWorldRendering(bool enabled)

References GetSettings(), UAgrarsenseSettings::SetWorldRendering(), and TryParseBoolean().

Referenced by AddCommands().

◆ HandleSetWPO()

void UROSCommands::HandleSetWPO ( const FString &  Variable)
private

Definition at line 1217 of file ROSCommands.cpp.

1218{
1219 if (Variable.IsNumeric())
1220 {
1221 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
1222 if (AgrarsenseSettings)
1223 {
1224 int32 IntValue = FCString::Atoi(*Variable);
1225 AgrarsenseSettings->SetWorldPositionOffsetRenderDistance(IntValue);
1226 }
1227 }
1228}
void SetWorldPositionOffsetRenderDistance(int32 WorldPositionOffsetDistance)

References GetSettings(), and UAgrarsenseSettings::SetWorldPositionOffsetRenderDistance().

Referenced by AddCommands().

◆ HandleSpawnObjects()

void UROSCommands::HandleSpawnObjects ( const FString &  Variable)
private

Definition at line 754 of file ROSCommands.cpp.

755{
757}
static void ParseAndOperateJSONFile(const FString &Path)

References USimulatorJsonParser::ParseAndOperateJSONFile().

Referenced by AddCommands().

◆ HandleStopWalker()

void UROSCommands::HandleStopWalker ( const FString &  Variable)
private

Definition at line 1044 of file ROSCommands.cpp.

1045{
1046 HandleSetWalkerMovement(Variable, true);
1047}

References HandleSetWalkerMovement().

Referenced by AddCommands().

◆ HandleTeleportActorByID()

void UROSCommands::HandleTeleportActorByID ( const FString &  Variable)
private

Definition at line 476 of file ROSCommands.cpp.

477{
478 FString ID;
479 FString TransformString;
480
481 // Split the ID and rest of the message
482 TArray<FString> Tokens;
483 Variable.ParseIntoArray(Tokens, TEXT(" "), true);
484 if (Tokens.Num() >= 2)
485 {
486 ID = Tokens[0];
487 TransformString = Variable.RightChop(ID.Len() + 1);
488 }
489 else
490 {
491 // Not valid, return
492 return;
493 }
494
495 // Check if this ID matches any Actor
496 AActor* Actor = IActorInformation::GetActorByID(ID);
497 if (!Actor)
498 {
499 // Not valid, return
500 return;
501 }
502
503 // Parse rest of the string to Transform
504 TArray<FString> Components;
505 TransformString.ParseIntoArray(Components, TEXT(","), true);
506
507 if (Components.Num() >= 3)
508 {
509 FVector Location;
510 FQuat Rotation;
511
512 // Convert the first three components to float values for location
513 float X = FCString::Atof(*Components[0]);
514 float Y = FCString::Atof(*Components[1]);
515 float Z = FCString::Atof(*Components[2]);
516
517 Location = FVector(X, Y, Z);
518
519 if (Components.Num() >= 6)
520 {
521 // If there are six or more components, try to parse them as rotation values
522 float Pitch = FCString::Atof(*Components[3]);
523 float Yaw = FCString::Atof(*Components[4]);
524 float Roll = FCString::Atof(*Components[5]);
525
526 // Convert the Euler angles to a quaternion
527 Rotation = FQuat(FRotator(Pitch, Yaw, Roll));
528 }
529
530 FTransform Transform;
531 Transform.SetLocation(Location);
532 Transform.SetRotation(Rotation);
533
534#if WITH_EDITOR
535 UE_LOG(LogTemp, Warning, TEXT("Teleporting Actor with ID: %s to: %s"), *ID, *TransformString);
536#endif
537
538 // Check if this Actor is Vehicle
539 AVehicle* VehiclePtr = Cast<AVehicle>(Actor);
540 if (VehiclePtr)
541 {
542 // Disable vehicle physics so it can be teleported
543 VehiclePtr->TogglePhysics(false);
544
545 Actor->SetActorTransform(Transform);
546
547 // Enable vehicle physics back on after teleporting vehicle
548 VehiclePtr->TogglePhysics(true);
549 }
550 else
551 {
552 // Else set the Actor transform
553 Actor->SetActorTransform(Transform);
554
555 // If the Actor is InstancedActor, we need to notify it. See InstancedActor.cpp
556 AInstancedActor* InstancedActorPtr = Cast<AInstancedActor>(Actor);
557 if (InstancedActorPtr)
558 {
559 InstancedActorPtr->UpdateTransformPosition();
560 }
561 }
562 }
563}
void UpdateTransformPosition()
void TogglePhysics(bool isOn)

References IActorInformation::GetActorByID(), AVehicle::TogglePhysics(), Transform, and AInstancedActor::UpdateTransformPosition().

Referenced by AddCommands().

◆ HandleTeleportSpectator()

void UROSCommands::HandleTeleportSpectator ( const FString &  Variable)
private

Definition at line 432 of file ROSCommands.cpp.

433{
434 // Split the comma-separated string into components
435 TArray<FString> Components;
436 Variable.ParseIntoArray(Components, TEXT(","), true);
437
438 if (Components.Num() >= 3)
439 {
440 FVector Location;
441 FQuat Rotation;
442
443 // Convert the first three components to float values for location
444 float X = FCString::Atof(*Components[0]);
445 float Y = FCString::Atof(*Components[1]);
446 float Z = FCString::Atof(*Components[2]);
447
448 Location = FVector(X, Y, Z);
449
450 if (Components.Num() >= 6)
451 {
452 // If there are six or more components, try to parse them as rotation values
453 float Pitch = FCString::Atof(*Components[3]);
454 float Yaw = FCString::Atof(*Components[4]);
455 float Roll = FCString::Atof(*Components[5]);
456
457 // Convert the Euler angles to a quaternion
458 Rotation = FQuat(FRotator(Pitch, Yaw, Roll));
459 }
460
461 UWorld* World = GetGameWorld();
462 if (World)
463 {
465 if (Spectator)
466 {
467 FTransform Transform;
468 Transform.SetLocation(Location);
469 Transform.SetRotation(Rotation);
470 Spectator->TeleportSpectator(Transform);
471 }
472 }
473 }
474}
void TeleportSpectator(const FTransform &Transform)
Definition: Spectator.cpp:48
static ASpectator * GetSpectator(const UObject *WorldContextObject)

References GetGameWorld(), UAgrarsenseStatics::GetSpectator(), ASpectator::TeleportSpectator(), and Transform.

Referenced by AddCommands().

◆ HandleTryDestroyObjectByID()

void UROSCommands::HandleTryDestroyObjectByID ( const FString &  Variable)
private

Definition at line 565 of file ROSCommands.cpp.

566{
567 bool success = IActorInformation::DestroyActorByID(Variable);
568
569 FString Message;
570 if (success)
571 {
572 Message = FString::Printf(TEXT("Object with ID %s successfully destroyed."), *Variable);
573 }
574 else
575 {
576 Message = FString::Printf(TEXT("Failed to destroy object with ID %s."), *Variable);
577 }
578
579 SimulatorLog::Log(Message);
580}
static bool DestroyActorByID(const FString &ID)

References IActorInformation::DestroyActorByID(), and SimulatorLog::Log().

Referenced by AddCommands().

◆ HandleUnPauseSimulator()

void UROSCommands::HandleUnPauseSimulator ( const FString &  Variable)
private

Definition at line 358 of file ROSCommands.cpp.

359{
360 UAgrarsenseSettings* AgrarsenseSettings = GetSettings();
361 if (AgrarsenseSettings)
362 {
363 AgrarsenseSettings->UnPauseSimulation();
364 }
365}

References GetSettings(), and UAgrarsenseSettings::UnPauseSimulation().

Referenced by AddCommands().

◆ HandleUnrealCommand()

void UROSCommands::HandleUnrealCommand ( const FString &  Variable)
private

Definition at line 423 of file ROSCommands.cpp.

424{
425 UWorld* World = GetGameWorld();
426 if (GEngine && World)
427 {
428 GEngine->Exec(World, *Variable);
429 }
430}

References GetGameWorld().

Referenced by AddCommands().

◆ HandleVisualizeOverlapSensorsBounds()

void UROSCommands::HandleVisualizeOverlapSensorsBounds ( const FString &  Variable)
private

Definition at line 854 of file ROSCommands.cpp.

855{
856 bool Visualize;
857 if (!TryParseBoolean(Variable, Visualize))
858 {
859 // Failed to parse, return
860 return;
861 }
862
863 UWorld* World = GetGameWorld();
864 if (World)
865 {
866 TArray<AActor*> OverlapSensors;
867 UGameplayStatics::GetAllActorsOfClass(World, AOverlapSensor::StaticClass(), OverlapSensors);
868
869 for (AActor* SensorActor : OverlapSensors)
870 {
871 AOverlapSensor* Sensor = Cast<AOverlapSensor>(SensorActor);
872 if (Sensor)
873 {
874 Sensor->SetVisualizeOverlapArea(Visualize);
875 }
876 }
877 }
878}
void SetVisualizeOverlapArea(bool Visualize)

References GetGameWorld(), AOverlapSensor::SetVisualizeOverlapArea(), and TryParseBoolean().

Referenced by AddCommands().

◆ Init()

void UROSCommands::Init ( )
private

Definition at line 46 of file ROSCommands.cpp.

47{
49
51 if (ROSHandler)
52 {
53 ROSHandler->OnROSStateChanged.AddUniqueDynamic(this, &UROSCommands::ROSBridgeStateChanged);
54 }
55
57}
static UROSHandler * GetROSHandle(const UObject *WorldContextObject)
void AddCommands()
Definition: ROSCommands.cpp:84
void SetupROSCommandTopic()
void ROSBridgeStateChanged(EROSState state)
FROSDelegate_ROState OnROSStateChanged
Definition: ROSHandler.h:81

References AddCommands(), GetGameWorld(), UAgrarsenseStatics::GetROSHandle(), UROSHandler::OnROSStateChanged, ROSBridgeStateChanged(), and SetupROSCommandTopic().

Referenced by AAgrarsenseGameModeBase::SpawnNeededActorsBeginPlay().

◆ ParseIncomingMessage()

void UROSCommands::ParseIncomingMessage ( const FString  Message)
private

Definition at line 241 of file ROSCommands.cpp.

242{
243 // Parse incoming string message into {COMMAND} {VARIABLE} format
244 int32 SpaceIndex;
245 FString Command;
246 FString Variable;
247
248 if (Message.FindChar(' ', SpaceIndex))
249 {
250 // Extract the command as the substring before the first space
251 Command = Message.Left(SpaceIndex).ToLower();
252
253 // Extract the rest of the message as the variable
254 Variable = Message.Mid(SpaceIndex + 1).ToLower();
255 }
256 else
257 {
258 // If no space is found, consider the entire message as the command
259 Command = Message.ToLower();
260 }
261
262#if WITH_EDITOR
263 UE_LOG(LogTemp, Warning, TEXT("ROSCommands.Cpp: Incoming Command: %s with variable: %s"), *Command, *Variable);
264#endif
265
266 FCommand* CommandInfo = CommandHandlers.Find(Command);
267 if (CommandInfo)
268 {
269 // Check if enough time has passed since the last execution.
270 double CurrentTime = FPlatformTime::Seconds();
271 double TimeSinceLastExecution = CurrentTime - CommandInfo->LastExecutionTime;
272
273 if (TimeSinceLastExecution >= CommandInfo->CooldownTime)
274 {
275 // Call the handler function with the variable.
276 (this->*(CommandInfo->Handler))(Variable);
277
278 // Update the last execution time.
279 CommandInfo->LastExecutionTime = CurrentTime;
280 }
281 else
282 {
283 float CoolDownTimeLeft = CommandInfo->CooldownTime - TimeSinceLastExecution;
284 FString Msg = FString::Printf(TEXT("Command '%s' on cooldown. Retry in %.2f sec."), *Command, CoolDownTimeLeft);
286 }
287 }
288 else
289 {
290 FString Msg = FString::Printf(TEXT("Couldn't find command: '%s'"), *Command);
292 }
293}
double LastExecutionTime
Definition: ROSCommands.h:33
float CooldownTime
Definition: ROSCommands.h:32
CommandHandler Handler
Definition: ROSCommands.h:31

References CommandHandlers, FCommand::CooldownTime, FCommand::Handler, FCommand::LastExecutionTime, and SimulatorLog::Log().

Referenced by SetupROSCommandTopic(), and TryExecuteCommand().

◆ PrintActorInformation()

void UROSCommands::PrintActorInformation ( const FString &  Variable,
UClass *  ActorClass,
const FString &  ActorTypeName 
)
private

Definition at line 645 of file ROSCommands.cpp.

646{
647 TArray<AActor*> Actors;
648 UGameplayStatics::GetAllActorsWithInterface(GetGameWorld(), UActorInformation::StaticClass(), Actors);
649
650 TArray<AActor*> TypedActors;
651 for (AActor* Actor : Actors)
652 {
653 if (Actor->IsA(ActorClass))
654 {
655 TypedActors.Add(Actor);
656 }
657 }
658
659 FString Msg;
660 if (!TypedActors.IsEmpty())
661 {
662 Msg = FString::Printf(TEXT("Simulation has %d %ss \n "), TypedActors.Num(), *ActorTypeName);
663 for (AActor* Actor : TypedActors)
664 {
665 if (Actor)
666 {
667 if (IActorInformation* ActorInfo = Cast<IActorInformation>(Actor))
668 {
669 Msg += FString::Printf(TEXT("%s \n \n "), *ActorInfo->GetActorInformation_Implementation());
670 }
671 }
672 }
673 }
674 else
675 {
676 Msg = FString::Printf(TEXT("Simulation has 0 %ss."), *ActorTypeName);
677 }
678
680}

References GetGameWorld(), and SimulatorLog::Log().

Referenced by HandlePrintAllSensors(), HandlePrintAllVehicles(), and HandlePrintAllWalkers().

◆ ROSBridgeStateChanged()

void UROSCommands::ROSBridgeStateChanged ( EROSState  state)
private

Definition at line 179 of file ROSCommands.cpp.

180{
181 switch (state)
182 {
185 break;
186
189 break;
190 }
191}

References Connected, DestroyROSTopic(), Disconnected, and SetupROSCommandTopic().

Referenced by Init().

◆ SetupROSCommandTopic()

void UROSCommands::SetupROSCommandTopic ( )
private

Definition at line 205 of file ROSCommands.cpp.

206{
207 UWorld* World = GetGameWorld();
208 if (!World)
209 {
210 return;
211 }
212
214 if (!CommandTopic && RosInstance && RosInstance->IsROSConnected())
215 {
216 CommandTopic = NewObject<UTopic>(UTopic::StaticClass());
217 CommandTopic->Init(RosInstance->ROSIntegrationCore, TEXT("/agrarsense/in/commands"), TEXT("std_msgs/String"));
218 CommandTopic->Advertise();
219
220 // Create a std::function callback object
221 std::function<void(TSharedPtr<FROSBaseMsg>)> SubscribeCallback = [this](TSharedPtr<FROSBaseMsg> msg) -> void
222 {
223 auto Concrete = StaticCastSharedPtr<ROSMessages::std_msgs::String>(msg);
224 if (Concrete.IsValid())
225 {
226 FString message = *(Concrete->_Data);
227 AsyncTask(ENamedThreads::GameThread, [this, message]()
228 {
229 // Parse message on GameThread since many commands are NOT thread-safe
230 ParseIncomingMessage(message);
231 });
232 }
233 return;
234 };
235
236 // Subscribe to the topic
237 CommandTopic->Subscribe(SubscribeCallback);
238 }
239}
static UROSIntegrationGameInstance * GetROSGameInstance(const UObject *WorldContextObject)
UROSIntegrationGameInstance * RosInstance
Definition: ROSCommands.h:105
void ParseIncomingMessage(const FString Message)

References CommandTopic, GetGameWorld(), UAgrarsenseStatics::GetROSGameInstance(), ParseIncomingMessage(), and RosInstance.

Referenced by Init(), and ROSBridgeStateChanged().

◆ TryExecuteCommand()

void UROSCommands::TryExecuteCommand ( const FString &  Command)

Definition at line 64 of file ROSCommands.cpp.

65{
66 ParseIncomingMessage(Command);
67}

References ParseIncomingMessage().

◆ TryParseBoolean()

bool UROSCommands::TryParseBoolean ( const FString &  String,
bool &  OutBool 
)
private

Attempts to parse a string into a boolean value.

Parameters
StringThe string to parse into a boolean value.
OutBoolA reference to a boolean where the result will be stored if the parsing is successful.
Returns
true if the string was successfully parsed into a boolean value, false otherwise.

Definition at line 295 of file ROSCommands.cpp.

296{
297 FString LoweredString = String.ToLower();
298
299 if (LoweredString.Equals("true") || LoweredString.Equals("1"))
300 {
301 OutBool = true;
302 return true;
303 }
304 else if (LoweredString.Equals("false") || LoweredString.Equals("0"))
305 {
306 OutBool = false;
307 return true;
308 }
309
310 // Invalid boolean value
311 return false;
312}

Referenced by HandleSetAllSensorsEnabled(), HandleSetSaveCombinedPointcloudToDisk(), HandleSetSensorEnabled(), HandleSetWorldRendering(), and HandleVisualizeOverlapSensorsBounds().

Friends And Related Function Documentation

◆ AAgrarsenseGameModeBase

friend class AAgrarsenseGameModeBase
friend

Definition at line 62 of file ROSCommands.h.

Member Data Documentation

◆ CommandHandlers

TMap< FString, FCommand > UROSCommands::CommandHandlers
staticprivate

Definition at line 73 of file ROSCommands.h.

Referenced by AddCommands(), HandlePrintAvailableCommands(), and ParseIncomingMessage().

◆ CommandTopic

UTopic* UROSCommands::CommandTopic = nullptr
private

◆ RosInstance

UROSIntegrationGameInstance* UROSCommands::RosInstance = nullptr
private

Definition at line 105 of file ROSCommands.h.

Referenced by SetupROSCommandTopic().


The documentation for this class was generated from the following files: