merge Heigth sensor into main #4

Merged
SemvdH merged 34 commits from heigth_sensor into main 2023-04-25 09:12:28 +00:00
Showing only changes of commit 31503b8b70 - Show all commits

View File

@@ -13,8 +13,8 @@ public:
{
publisher_ = this->create_publisher<std_msgs::msg::String>("height_sensor", 10);
timer_ = this->create_wall_timer(
500ms, std::bind(&HeightSensorPublisher::timer_callback, this));
RCLCPP_INFO(this->get_logger(), "Constructor of height sensor publisher");
20ms, std::bind(&HeightSensorPublisher::timer_callback, this));
RCLCPP_INFO(this->get_logger(), "Starting height sensor publisher");
setup_serial_port();
}
@@ -34,7 +34,10 @@ private:
char *readdata = new char[1];
serial_port.read(readdata, 1);
auto message = std_msgs::msg::String();
message.data = "Height: " + std::to_string((int)readdata[0]);
message.data = "Height: " + (char)readdata[0];
if (readdata[0] == 'T') {
RCLCPP_INFO(this->get_logger(), "got start of measurement");
}
RCLCPP_INFO(this->get_logger(), "Publishing: %s", message.data.c_str());
publisher_->publish(message);
}
@@ -48,7 +51,7 @@ private:
serial_port.open("/dev/ttyACM0", std::ios::in);
if (!serial_port.is_open())
{
RCLCPP_ERROR(this->get_logger(), "Could not open serial port");
RCLCPP_ERROR(this->get_logger(), "ERROR Could not open serial port");
return;
}
else
@@ -73,11 +76,6 @@ int main(int argc, char *argv[])
executor.add_node(node);
executor.spin();
// rclcpp::spin(std::make_shared<HeightSensorPublisher>());
while (true)
{
node.get()->test();
}
rclcpp::shutdown();
return 0;