add test calling method while node spinning
This commit is contained in:
@@ -13,15 +13,18 @@ class HeightSensorPublisher : public rclcpp::Node
|
|||||||
{
|
{
|
||||||
publisher_ = this->create_publisher<std_msgs::msg::String>("height_sensor", 10);
|
publisher_ = this->create_publisher<std_msgs::msg::String>("height_sensor", 10);
|
||||||
timer_ = this->create_wall_timer(
|
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");
|
RCLCPP_INFO(this->get_logger(), "Constructor of height sensor publisher");
|
||||||
|
|
||||||
setup_serial_port();
|
setup_serial_port();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test()
|
||||||
|
{
|
||||||
|
RCLCPP_INFO(this->get_logger(), "Je moeder is een plopkoek");
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer callback function to publish the height sensor data
|
* @brief Timer callback function to publish the height sensor data
|
||||||
*
|
*
|
||||||
@@ -56,10 +59,6 @@ class HeightSensorPublisher : public rclcpp::Node
|
|||||||
serial_port.close();
|
serial_port.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test()
|
|
||||||
{
|
|
||||||
RCLCPP_INFO(this->get_logger(), "Je moeder is een plopkoek");
|
|
||||||
}
|
|
||||||
rclcpp::TimerBase::SharedPtr timer_;
|
rclcpp::TimerBase::SharedPtr timer_;
|
||||||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
|
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
|
||||||
std::fstream serial_port; // serial port for reading from device
|
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::init(argc, argv);
|
||||||
|
|
||||||
rclcpp::executors::SingleThreadedExecutor executor;
|
rclcpp::executors::SingleThreadedExecutor executor;
|
||||||
auto node = std::make_shared<HeightSensorPublisher>();
|
rclcpp::Node::SharedPtr node = std::make_shared<HeightSensorPublisher>();
|
||||||
node.get()->setup_serial_port();
|
|
||||||
executor.add_node(node);
|
executor.add_node(node);
|
||||||
executor.spin();
|
executor.spin();
|
||||||
// rclcpp::spin(std::make_shared<HeightSensorPublisher>());
|
// rclcpp::spin(std::make_shared<HeightSensorPublisher>());
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
node->test();
|
||||||
|
}
|
||||||
rclcpp::shutdown();
|
rclcpp::shutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user