Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Forwarding for Realsense connections #1

Open
wants to merge 4 commits into
base: noetic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion realsense2_camera/include/realsense_node_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace realsense2_camera
const stream_index_pair GYRO{RS2_STREAM_GYRO, 0};
const stream_index_pair ACCEL{RS2_STREAM_ACCEL, 0};
const stream_index_pair POSE{RS2_STREAM_POSE, 0};
const stream_index_pair CONFIDENCE{RS2_STREAM_CONFIDENCE, 0};
const stream_index_pair CONFIDENCE{RS2_STREAM_CONFIDENCE, 0};

const std::vector<stream_index_pair> IMAGE_STREAMS = {DEPTH, INFRA0, INFRA1, INFRA2,
COLOR,
Expand Down Expand Up @@ -79,6 +79,7 @@ namespace realsense2_camera
std::thread _query_thread;
bool _is_alive;
ros::ServiceServer toggle_sensor_srv;
ros::Publisher health_pub;

};
}//end namespace
26 changes: 21 additions & 5 deletions realsense2_camera/src/realsense_node_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <signal.h>
#include <thread>
#include <regex>
#include <std_msgs/String.h>

using namespace realsense2_camera;

Expand Down Expand Up @@ -90,7 +91,13 @@ void RealSenseNodeFactory::getDevice(rs2::device_list list)
{
if (0 == list.size())
{
ROS_WARN("No RealSense devices were found!");
std::stringstream ss;
ss << "ERROR: No Realsense device found";
ROS_ERROR_STREAM(ss.str());

std_msgs::String msg;
msg.data = ss.str();
health_pub.publish(msg);
}
else
{
Expand Down Expand Up @@ -132,7 +139,7 @@ void RealSenseNodeFactory::getDevice(rs2::device_list list)
}
else
{
ROS_INFO_STREAM("Device with port number " << port_id << " was found.");
ROS_INFO_STREAM("Device with port number " << port_id << " was found.");
}
bool found_device_type(true);
if (!_device_type.empty())
Expand Down Expand Up @@ -209,7 +216,7 @@ void RealSenseNodeFactory::getDevice(rs2::device_list list)
ROS_INFO("Resetting device...");
_device.hardware_reset();
_device = rs2::device();

}
catch(const std::exception& ex)
{
Expand All @@ -222,8 +229,15 @@ void RealSenseNodeFactory::change_device_callback(rs2::event_information& info)
{
if (info.was_removed(_device))
{
ROS_ERROR("The device has been disconnected!");
_realSenseNode.reset(nullptr);
std::stringstream ss;
ss << "ERROR: Realsense device removed";
ROS_ERROR_STREAM(ss.str());

std_msgs::String msg;
msg.data = ss.str();
health_pub.publish(msg);

_realSenseNode.reset(nullptr);
_device = rs2::device();
}
if (!_device)
Expand Down Expand Up @@ -270,6 +284,8 @@ void RealSenseNodeFactory::onInit()
std::string rosbag_filename("");
privateNh.param("rosbag_filename", rosbag_filename, std::string(""));

health_pub = nh.advertise<std_msgs::String>("health", 1, true);

if (!rosbag_filename.empty())
{
{
Expand Down