add test calling method while node spinning

This commit is contained in:
Sem van der Hoeven
2023-03-03 13:37:31 +01:00
parent 4df0d69b53
commit b88d8beb39

View File

@@ -13,15 +13,18 @@ class HeightSensorPublisher : public rclcpp::Node
{
publisher_ = this->create_publisher<std_msgs::msg::String>("height_sensor", 10);
timer_ = this->create_wall_timer(
1ms, std::bind(&HeightSensorPublisher::timer_callback, this));
500ms, std::bind(&HeightSensorPublisher::timer_callback, this));
RCLCPP_INFO(this->get_logger(), "Constructor of height sensor publisher");
setup_serial_port();
}
void test()
{
RCLCPP_INFO(this->get_logger(), "Je moeder is een plopkoek");
}
private:
/**
* @brief Timer callback function to publish the height sensor data
*
@@ -56,10 +59,6 @@ class HeightSensorPublisher : public rclcpp::Node
serial_port.close();
}
void test()
{
RCLCPP_INFO(this->get_logger(), "Je moeder is een plopkoek");
}
rclcpp::TimerBase::SharedPtr timer_;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
std::fstream serial_port; // serial port for reading from device
@@ -70,14 +69,16 @@ int main(int argc, char *argv[])
rclcpp::init(argc, argv);
rclcpp::executors::SingleThreadedExecutor executor;
auto node = std::make_shared<HeightSensorPublisher>();
node.get()->setup_serial_port();
rclcpp::Node::SharedPtr node = std::make_shared<HeightSensorPublisher>();
executor.add_node(node);
executor.spin();
// rclcpp::spin(std::make_shared<HeightSensorPublisher>());
while (true)
{
node->test();
}
rclcpp::shutdown();
return 0;
}