-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_input_output.cpp
More file actions
68 lines (57 loc) · 1.99 KB
/
test_input_output.cpp
File metadata and controls
68 lines (57 loc) · 1.99 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
67
68
#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
{
std_msgs::msg::String msg;
msg.data = id->GetParameterValue("data");
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
{
sml::Identifier * il = this->m_pAgent->GetInputLink();
sml::Identifier * pId = il->CreateIdWME(this->m_topic.c_str());
pId->CreateStringWME("data", msg.data.c_str());
}
};
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>();
auto agent = node->addAgent("TestRepublisher", soar_path);
std::shared_ptr<soar_ros::Publisher<std_msgs::msg::String>> p =
std::make_shared<TestOutput>(agent, node, "test");
node->addPublisher(p);
std::shared_ptr<soar_ros::Subscriber<std_msgs::msg::String>> s =
std::make_shared<TestInput>(agent, node, "testinput");
node->addSubscriber(s);
if (!node->get_parameter("debug").as_bool()) {
node->startThread();
}
rclcpp::spin(node);
node->~SoarRunner();
rclcpp::shutdown();
return 0;
}