1+ // name?
2+
3+ #include < rclcpp/rclcpp.hpp>
4+ #include < sensor_msgs/msg/joy.hpp>
5+ #include < example_interfaces/msg/int32.hpp>
6+ #include < catch2/catch_all.hpp>
7+
8+ // Class definition
9+ class IntegrationTestNode : public rclcpp ::Node {
10+ public:
11+ IntegrationTestNode (); // Constructor is defined in .cpp.
12+
13+ private:
14+ // SUBS AND PUBS
15+ rclcpp::Publisher<sensor_msgs::msg::Joy>::SharedPtr joy_publisher;
16+
17+ rclcpp::Publisher<example_interfaces::msg::Int32>::SharedPtr checker_pub;
18+ rclcpp::Subscription<example_interfaces::msg::Int32>::SharedPtr checker_sub;
19+
20+ // Callbacks
21+ void test_callback (example_interfaces::msg::Int32 msg);
22+
23+ };
24+
25+ // Constructor
26+ IntegrationTestNode::IntegrationTestNode () : Node(" integration_test_node" )
27+ { // We create a class using rclcpp::Node as a base class. You can still use another base class if you need, albeit sometimes with difficulties in passing args..
28+
29+ // Quality of service example
30+ auto qos = rclcpp::QoS (rclcpp::KeepLast (1 )).transient_local ();
31+
32+ joy_publisher = this ->create_publisher <sensor_msgs::msg::Joy>(
33+ " /joy" , qos);
34+
35+ checker_pub = this ->create_publisher <example_interfaces::msg::Int32>(
36+ " /integration/test_int" , qos);
37+
38+ checker_sub = this ->create_subscription <example_interfaces::msg::Int32>(
39+ " /integration/test_int" , qos, std::bind (&IntegrationTestNode::test_callback, this , std::placeholders::_1));
40+
41+ }
42+
43+ // Main function (entry point of node)
44+ int main (int argc, char *argv[])
45+ {
46+ // Init ros2 with args.
47+ rclcpp::init (argc, argv);
48+
49+ // Instatiate your node
50+ auto node = std::make_shared<IntegrationTestNode>();
51+ // Spin it! (this is what runs pubs and subs. This is a blocking function)
52+ rclcpp::spin (node);
53+ // There is also rclcpp::spinSome(node) if you need more control over when the node spins / need to not block while spinning.
54+
55+ // Code only reaches here if we crash or shutdown the node
56+ rclcpp::shutdown ();
57+ return 0 ;
58+ }
59+
60+ void IntegrationTestNode::test_callback (example_interfaces::msg::Int32 msg)
61+ {
62+
63+ }
0 commit comments