-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_input_output.cpp
More file actions
66 lines (55 loc) · 1.91 KB
/
test_input_output.cpp
File metadata and controls
66 lines (55 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>
#include <ament_index_cpp/get_package_share_directory.hpp>
#include "soar_ros/soar_ros.hpp"
#include <sml_Client.h>
#include <fstream>
class TestOutput : public soar_ros::Publisher<std_msgs::msg::String>
{
public:
using Publisher<std_msgs::msg::String>::Publisher;
std_msgs::msg::String parse(sml::Identifier *id) override
{
auto msg = soar_ros::msg::fromSoar<std_msgs::msg::String>(id);
std::cout << id->GetCommandName() << " " << msg.data << std::endl;
return msg;
}
};
class TestInput : public soar_ros::Subscriber<std_msgs::msg::String>
{
public:
using Subscriber<std_msgs::msg::String>::Subscriber;
void parse(std_msgs::msg::String msg) override
{
soar_ros::msg::toSoar(this->m_pAgent->GetInputLink(), this->m_topic.c_str(), msg);
}
};
int main(int argc, char *argv[])
{
rclcpp::init(argc, argv);
const std::string package_name = "soar_ros";
const std::string share_directory = ament_index_cpp::get_package_share_directory(package_name);
std::string soar_path = share_directory + "/Soar/test_input_output.soar";
std::cout << "Soar file path: " << soar_path << std::endl;
std::ifstream soar_file(soar_path);
if (!soar_file.is_open())
{
std::cerr << "Error: Soar file not found at " << soar_path << std::endl;
return 1;
}
auto node = std::make_shared<soar_ros::SoarRunner>("soar_ros");
auto agent = node->addAgent("TestRepublisher", soar_path);
std::shared_ptr<soar_ros::Publisher<std_msgs::msg::String>> p =
std::make_shared<TestOutput>(agent->getSmlAgent(), node, "test");
agent->addPublisher(p);
std::shared_ptr<soar_ros::Subscriber<std_msgs::msg::String>> s =
std::make_shared<TestInput>(agent->getSmlAgent(), node, "testinput");
agent->addSubscriber(s);
if (!node->get_parameter("debug").as_bool())
{
node->startThread();
}
rclcpp::spin(node);
rclcpp::shutdown();
return 0;
}