|
4 | 4 | #include "rosbridge2cpp/ros_topic.h"
|
5 | 5 | #include "Conversion/Messages/BaseMessageConverter.h"
|
6 | 6 | #include "Conversion/Messages/std_msgs/StdMsgsStringConverter.h"
|
| 7 | +#include "Conversion/Messages/std_msgs/StdMsgsBoolConverter.h" |
| 8 | +#include "Conversion/Messages/geometry_msgs/GeometryMsgsVector3Converter.h" |
| 9 | +#include "Conversion/Messages/geometry_msgs/GeometryMsgsPointConverter.h" |
| 10 | +#include "Conversion/Messages/geometry_msgs/GeometryMsgsPoseConverter.h" |
| 11 | + |
| 12 | + |
| 13 | + |
7 | 14 |
|
8 | 15 | static TMap<FString, UBaseMessageConverter*> TypeConverterMap;
|
9 | 16 | static TMap<EMessageType, FString> SupportedMessageTypes;
|
@@ -174,8 +181,19 @@ UTopic::UTopic(const FObjectInitializer& ObjectInitializer)
|
174 | 181 |
|
175 | 182 | if (SupportedMessageTypes.Num() == 0)
|
176 | 183 | {
|
177 |
| - SupportedMessageTypes.Add(EMessageType::String, TEXT("std_msgs/String")); |
178 |
| - SupportedMessageTypes.Add(EMessageType::Float32, TEXT("std_msgs/Float32")); |
| 184 | + SupportedMessageTypes.Add(EMessageType::String, TEXT("std_msgs/String")); |
| 185 | + SupportedMessageTypes.Add(EMessageType::Float32, TEXT("std_msgs/Float32")); |
| 186 | + SupportedMessageTypes.Add(EMessageType::Bool, TEXT("std_msgs/Bool")); |
| 187 | + SupportedMessageTypes.Add(EMessageType::Float64, TEXT("std_msgs/Float64")); |
| 188 | + SupportedMessageTypes.Add(EMessageType::Int32, TEXT("std_msgs/Int32")); |
| 189 | + SupportedMessageTypes.Add(EMessageType::Int64, TEXT("std_msgs/Int64")); |
| 190 | + |
| 191 | + SupportedMessageTypes.Add(EMessageType::Vector3, TEXT("geometry_msgs/Vector3")); |
| 192 | + SupportedMessageTypes.Add(EMessageType::Point, TEXT("geometry_msgs/Point")); |
| 193 | + SupportedMessageTypes.Add(EMessageType::Pose, TEXT("geometry_msgs/Pose")); |
| 194 | + SupportedMessageTypes.Add(EMessageType::Quaternion, TEXT("geometry_msgs/Quaternion")); |
| 195 | + SupportedMessageTypes.Add(EMessageType::Twist, TEXT("geometry_msgs/Twist")); |
| 196 | + |
179 | 197 | }
|
180 | 198 | }
|
181 | 199 |
|
@@ -345,6 +363,154 @@ bool UTopic::Subscribe()
|
345 | 363 | }
|
346 | 364 | break;
|
347 | 365 | }
|
| 366 | + case EMessageType::Bool: |
| 367 | + { |
| 368 | + auto ConcreteBoolMessage = StaticCastSharedPtr<ROSMessages::std_msgs::Bool>(msg); |
| 369 | + if (ConcreteBoolMessage.IsValid()) |
| 370 | + { |
| 371 | + const bool Data = ConcreteBoolMessage->_Data; |
| 372 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 373 | + AsyncTask(ENamedThreads::GameThread, [this, Data, SelfPtr]() |
| 374 | + { |
| 375 | + if (!SelfPtr.IsValid()) return; |
| 376 | + OnBoolMessage(Data); |
| 377 | + }); |
| 378 | + } |
| 379 | + break; |
| 380 | + } |
| 381 | + case EMessageType::Float64: |
| 382 | + { |
| 383 | + auto ConcreteDoubleMessage = StaticCastSharedPtr<ROSMessages::std_msgs::Float32>(msg); |
| 384 | + if (ConcreteDoubleMessage.IsValid()) |
| 385 | + { |
| 386 | + const double Data = ConcreteDoubleMessage->_Data; |
| 387 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 388 | + AsyncTask(ENamedThreads::GameThread, [this, Data, SelfPtr]() |
| 389 | + { |
| 390 | + if (!SelfPtr.IsValid()) return; |
| 391 | + OnFloat64Message(Data); |
| 392 | + }); |
| 393 | + } |
| 394 | + break; |
| 395 | + } |
| 396 | + case EMessageType::Int32: |
| 397 | + { |
| 398 | + auto ConcreteInt32Message = StaticCastSharedPtr<ROSMessages::std_msgs::Int32>(msg); |
| 399 | + if (ConcreteInt32Message.IsValid()) |
| 400 | + { |
| 401 | + const int32 Data = ConcreteInt32Message->_Data; |
| 402 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 403 | + AsyncTask(ENamedThreads::GameThread, [this, Data, SelfPtr]() |
| 404 | + { |
| 405 | + if (!SelfPtr.IsValid()) return; |
| 406 | + OnInt32Message(Data); |
| 407 | + }); |
| 408 | + } |
| 409 | + break; |
| 410 | + } |
| 411 | + case EMessageType::Int64: |
| 412 | + { |
| 413 | + auto ConcreteInt64Message = StaticCastSharedPtr<ROSMessages::std_msgs::Int64>(msg); |
| 414 | + if (ConcreteInt64Message.IsValid()) |
| 415 | + { |
| 416 | + const int64 Data = ConcreteInt64Message->_Data; |
| 417 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 418 | + AsyncTask(ENamedThreads::GameThread, [this, Data, SelfPtr]() |
| 419 | + { |
| 420 | + if (!SelfPtr.IsValid()) return; |
| 421 | + OnInt64Message(Data); |
| 422 | + }); |
| 423 | + } |
| 424 | + break; |
| 425 | + } |
| 426 | + case EMessageType::Vector3: |
| 427 | + { |
| 428 | + auto ConcreteVectorMessage = StaticCastSharedPtr<ROSMessages::geometry_msgs::Vector3>(msg); |
| 429 | + if (ConcreteVectorMessage.IsValid()) |
| 430 | + { |
| 431 | + const float x = ConcreteVectorMessage->x; |
| 432 | + const float y = ConcreteVectorMessage->y; |
| 433 | + const float z = ConcreteVectorMessage->z; |
| 434 | + FVector Data(x,y,z); |
| 435 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 436 | + AsyncTask(ENamedThreads::GameThread, [this, Data, SelfPtr]() |
| 437 | + { |
| 438 | + if (!SelfPtr.IsValid()) return; |
| 439 | + OnVector3Message(Data); |
| 440 | + }); |
| 441 | + } |
| 442 | + break; |
| 443 | + } |
| 444 | + case EMessageType::Point: |
| 445 | + { |
| 446 | + auto ConcreteVectorMessage = StaticCastSharedPtr<ROSMessages::geometry_msgs::Point>(msg); |
| 447 | + if (ConcreteVectorMessage.IsValid()) |
| 448 | + { |
| 449 | + const float x = ConcreteVectorMessage->x; |
| 450 | + const float y = ConcreteVectorMessage->y; |
| 451 | + const float z = ConcreteVectorMessage->z; |
| 452 | + FVector Data(x, y, z); |
| 453 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 454 | + AsyncTask(ENamedThreads::GameThread, [this, Data, SelfPtr]() |
| 455 | + { |
| 456 | + if (!SelfPtr.IsValid()) return; |
| 457 | + OnPointMessage(Data); |
| 458 | + }); |
| 459 | + } |
| 460 | + break; |
| 461 | + } |
| 462 | + case EMessageType::Pose: |
| 463 | + { |
| 464 | + auto ConcreteVectorMessage = StaticCastSharedPtr<ROSMessages::geometry_msgs::Pose>(msg); |
| 465 | + if (ConcreteVectorMessage.IsValid()) |
| 466 | + { |
| 467 | + const auto p = ConcreteVectorMessage->position; |
| 468 | + const auto q = ConcreteVectorMessage->orientation; |
| 469 | + const FVector position(p.x, p.y, p.z); |
| 470 | + const FVector4 orientation(q.x,q.y,q.z,q.w); |
| 471 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 472 | + AsyncTask(ENamedThreads::GameThread, [this, position, orientation, SelfPtr]() |
| 473 | + { |
| 474 | + if (!SelfPtr.IsValid()) return; |
| 475 | + OnPoseMessage(position, orientation); |
| 476 | + }); |
| 477 | + } |
| 478 | + break; |
| 479 | + } |
| 480 | + case EMessageType::Quaternion: |
| 481 | + { |
| 482 | + auto ConcreteVectorMessage = StaticCastSharedPtr<ROSMessages::geometry_msgs::Quaternion>(msg); |
| 483 | + if (ConcreteVectorMessage.IsValid()) |
| 484 | + { |
| 485 | + const auto q = ConcreteVectorMessage; |
| 486 | + const FVector4 orientation(q->x, q->y, q->z, q->w); |
| 487 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 488 | + AsyncTask(ENamedThreads::GameThread, [this, orientation, SelfPtr]() |
| 489 | + { |
| 490 | + if (!SelfPtr.IsValid()) return; |
| 491 | + OnQuaternionMessage(orientation); |
| 492 | + }); |
| 493 | + } |
| 494 | + break; |
| 495 | + } |
| 496 | + case EMessageType::Twist: |
| 497 | + { |
| 498 | + auto ConcreteVectorMessage = StaticCastSharedPtr<ROSMessages::geometry_msgs::Twist>(msg); |
| 499 | + if (ConcreteVectorMessage.IsValid()) |
| 500 | + { |
| 501 | + const auto p = ConcreteVectorMessage->linear; |
| 502 | + const auto q = ConcreteVectorMessage->angular; |
| 503 | + const FVector linear(p.x, p.y, p.z); |
| 504 | + const FVector angular(q.x, q.y, q.z); |
| 505 | + TWeakPtr<UTopic, ESPMode::ThreadSafe> SelfPtr(_SelfPtr); |
| 506 | + AsyncTask(ENamedThreads::GameThread, [this, linear, angular, SelfPtr]() |
| 507 | + { |
| 508 | + if (!SelfPtr.IsValid()) return; |
| 509 | + OnTwistMessage(linear, angular); |
| 510 | + }); |
| 511 | + } |
| 512 | + break; |
| 513 | + } |
348 | 514 | default:
|
349 | 515 | unimplemented();
|
350 | 516 | break;
|
|
0 commit comments