5#include <condition_variable>
6#include <opencv2/opencv.hpp>
7#include <cv_bridge/cv_bridge.hpp>
11#include <sensor_msgs/msg/image.hpp>
12#include <image_transport/image_transport.hpp>
34 void initialize(
const rclcpp::Node::SharedPtr& node)
override
37 node->declare_parameter(
"driver.vision.DefaultDriver.name",
"DefaultDriver");
38 node->declare_parameter(
"driver.vision.DefaultDriver.topic",
"/camera/raw");
41 name_ = node->get_parameter(
"driver.vision.DefaultDriver.name").as_string();
42 interface_name_ = node->get_parameter(
"driver.vision.DefaultDriver.topic").as_string();
48 RCLCPP_INFO(
node_->get_logger(),
"Assigned driver name: %s",
name_.c_str());
51 RCLCPP_INFO(
node_->get_logger(),
"DefaultDriver subscribing on topic %s",
interface_name_.c_str());
53 image_transport::ImageTransport transport(
node_);
61 [
this](diagnostic_updater::DiagnosticStatusWrapper& status) {
produce_diagnostics(status); });
64 RCLCPP_INFO(
node_->get_logger(),
"Started. Subscribed to image topic: %s",
interface_name_.c_str());
75 RCLCPP_INFO(
node_->get_logger(),
"DefaultDriver unsubscribed from topic: %s",
interface_name_.c_str());
97 frame.
image = cv_ptr->image.clone();
99 catch (
const cv_bridge::Exception& e)
111 RCLCPP_INFO(
node_->get_logger(),
"DefaultDriver test function called");
118 cv::imwrite(
"test/default_vision_image.jpg",
captureFrame().image);
120 catch (
const cv_bridge::Exception& e)
125 RCLCPP_INFO(
node_->get_logger(),
"Test image saved to test/default_vision_image.jpg. Test completed.");
140 sensor_msgs::msg::Image::ConstSharedPtr image;
147 status.summary(diagnostic_msgs::msg::DiagnosticStatus::WARN,
"Waiting for image frames");
149 status.summary(diagnostic_msgs::msg::DiagnosticStatus::OK,
"Receiving image frames");
153 status.add(
"latest_frame_available", image ?
"true" :
"false");
156 status.add(
"latest_frame_id", image->header.frame_id);
157 status.add(
"latest_stamp_sec", image->header.stamp.sec);
158 status.add(
"latest_stamp_nanosec", image->header.stamp.nanosec);
159 status.add(
"latest_width",
static_cast<int>(image->width));
160 status.add(
"latest_height",
static_cast<int>(image->height));
Definition default_vision_driver.hpp:18
~DefaultDriver()
Definition default_vision_driver.hpp:22
vision_frame captureFrame() override
Get the latest image data from the driver.
Definition default_vision_driver.hpp:84
void initialize(const rclcpp::Node::SharedPtr &node) override
Initialize the driver.
Definition default_vision_driver.hpp:34
void test() override
Test function to check the driver functionality by writing the image to a file.
Definition default_vision_driver.hpp:109
image_transport::Subscriber image_sub_
Definition default_vision_driver.hpp:165
std::string interface_name_
Definition default_vision_driver.hpp:164
void produce_diagnostics(diagnostic_updater::DiagnosticStatusWrapper &status)
Definition default_vision_driver.hpp:138
std::atomic< uint64_t > received_image_count_
Definition default_vision_driver.hpp:167
void imageCallback(const sensor_msgs::msg::Image::ConstSharedPtr &msg)
Definition default_vision_driver.hpp:129
void deinitialize() override
Stop driver streaming.
Definition default_vision_driver.hpp:71
sensor_msgs::msg::Image::ConstSharedPtr latest_image_
Definition default_vision_driver.hpp:166
void check_directory(std::string folder_name)
Check if the test directory exists, create it if not.
Definition driver_base.hpp:68
std::mutex buffer_mutex_
Mutex to protect access to the driver data.
Definition driver_base.hpp:149
std::string name_
Name of the driver.
Definition driver_base.hpp:143
std::condition_variable buffer_cv_
Condition variable to notify when new data is available.
Definition driver_base.hpp:155
rclcpp::Node::SharedPtr node_
ROS node for the driver.
Definition driver_base.hpp:138
void initialize_base(const rclcpp::Node::SharedPtr &node)
Initializer base driver in place of constructor due to plugin semantics.
Definition driver_base.hpp:95
void disable_diagnostics()
Definition driver_base.hpp:129
bool diagnostics_enabled() const
Definition driver_base.hpp:105
void enable_diagnostics(const std::string &hardware_id, const std::string &task_name, std::function< void(diagnostic_updater::DiagnosticStatusWrapper &)> task, std::chrono::milliseconds period=std::chrono::seconds(1))
Definition driver_base.hpp:110
Definition vision_source_driver.hpp:10
Definition audio_buffer.hpp:16
Base class for driver exceptions.
Definition exceptions.hpp:14
Definition structs.hpp:12
cv::Mat image
Definition structs.hpp:13
rclcpp::Time stamp
Definition structs.hpp:15
std::string frame_id
Definition structs.hpp:14