Skip to content

Commit

Permalink
Applied review
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Pełka <[email protected]>
  • Loading branch information
michalpelka committed Aug 22, 2024
1 parent 3c3bc60 commit 4db0d1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace ExposeConsoleToRos
{

AZ_COMPONENT_IMPL(ExposeConsoleToRosSystemComponent, "ExposeConsoleToRosSystemComponent", ExposeConsoleToRosSystemComponentTypeId);

void ExposeConsoleToRosSystemComponent::Reflect(AZ::ReflectContext* context)
Expand Down Expand Up @@ -34,20 +35,26 @@ namespace ExposeConsoleToRos

void ExposeConsoleToRosSystemComponent::Activate()
{
#if defined(AZ_DEBUG_BUILD) || defined(AZ_PROFILE_BUILD)
auto ros2Node = ROS2::ROS2Interface::Get()->GetNode();
AZ_Assert(ros2Node, "ROS2 node is not available");
m_consolePublisher = ros2Node->create_publisher<std_msgs::msg::String>("o3de_console_out", 10);
m_consoleSubscription = ros2Node->create_subscription<std_msgs::msg::String>("o3de_console_in", 10,
[](const std_msgs::msg::String::SharedPtr msg) {
AZ_Printf("ExposeConsoleToRos", "Received message: %s", msg->data.c_str());
m_consoleSubscription = ros2Node->create_subscription<std_msgs::msg::String>(
"o3de_console_in",
10,
[](const std_msgs::msg::String::SharedPtr msg)
{
AZ_Info("ExposeConsoleToRos", "Received message: %s", msg->data.c_str());
AzFramework::ConsoleRequestBus::Broadcast(&AzFramework::ConsoleRequests::ExecuteConsoleCommand, msg->data.c_str());
});
AzFramework::ConsoleNotificationBus::Handler::BusConnect();
#endif
}

void ExposeConsoleToRosSystemComponent::OnConsoleCommandExecuted(const char* command)
{
if (m_consolePublisher){
if (m_consolePublisher)
{
std_msgs::msg::String msg;
msg.data = command;
m_consolePublisher->publish(msg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#pragma once

#include <AzCore/Component/Component.h>
#include <AzCore/Component/TickBus.h>
#include "ROS2/ROS2Bus.h"
#include "std_msgs/msg/string.hpp"
#include <AzCore/Component/Component.h>
#include <AzCore/Component/TickBus.h>
#include <AzFramework/Components/ConsoleBus.h>

namespace ExposeConsoleToRos
Expand Down

0 comments on commit 4db0d1a

Please sign in to comment.