'How to write ros2 subscriber in test such as soon as It receives messages It should set flag or something and test case will pass
How to write ros2 subscriber in test such as soon as It receives messages It should set flag or something and test case will pass
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
TEST_CASE("Compare message")
{
using std::placeholders::_1;
//using Subscriber::ShapesSubscriberROS2;
class ShapesSubscriberROS2 : public rclcpp::Node
{
public:
ShapesSubscriberROS2()
: Node("shapes_subscriber")
{
constexpr int qos_no = 10;
subscription_ = this->create_subscription<man_msgs::msg::Shapes>("topic3",qos_no,std::bind(&ShapesSubscriberROS2::TopicCallback,this,_1));
}
private:
void TopicCallback(const man_msgs::msg::Shapes::SharedPtr msg) const
{
RCLCPP_INFO(this->get_logger(), "Connected to :: '%s'. Header frame id '%s'", msg->str_message.c_str(), msg->header.frame_id.c_str());
temp_cout=1;
}
rclcpp::Subscription<man_msgs::msg::Shapes>::SharedPtr subscription_;
};
rclcpp::init(0, nullptr);
rclcpp::spin(std::make_shared<ShapesSubscriberROS2>());
REQUIRE(temp_cout== 1);
rclcpp::shutdown();
}
Above is code in test folder
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
