10 #include <condition_variable> 17 #define REALSENSE_ROS_EMBEDDED_VERSION_STR (VAR_ARG_STRING(VERSION: REALSENSE_ROS_MAJOR_VERSION.REALSENSE_ROS_MINOR_VERSION.REALSENSE_ROS_PATCH_VERSION)) 24 std::ostringstream ss;
25 if (version / 10000 == 0)
28 ss << (version / 10000) <<
"." << (version % 10000) / 100 <<
"." << (version % 100);
39 ROS_INFO_STREAM(
"Running with LibRealSense v" << running_librealsense_version);
42 ROS_WARN(
"***************************************************");
43 ROS_WARN(
"** running with a different librealsense version **");
44 ROS_WARN(
"** than the one the wrapper was compiled with! **");
45 ROS_WARN(
"***************************************************");
48 auto severity = rs2_log_severity::RS2_LOG_SEVERITY_WARN;
50 if (rs2_log_severity::RS2_LOG_SEVERITY_DEBUG ==
severity)
68 std::regex self_regex(
"(?:[^ ]+/usb[0-9]+[0-9./-]*/){0,1}([0-9.-]+)(:){0,1}[^ ]*", std::regex_constants::ECMAScript);
69 std::smatch base_match;
70 bool found = std::regex_match(line, base_match, self_regex);
73 port_id = base_match[1].str();
74 if (base_match[2].
str().
size() == 0)
76 std::regex end_regex = std::regex(
".+(-[0-9]+$)", std::regex_constants::ECMAScript);
77 bool found_end = std::regex_match(port_id, base_match, end_regex);
80 port_id = port_id.substr(0, port_id.size() - base_match[1].str().size());
93 ROS_WARN(
"No RealSense devices were found!");
106 catch(
const std::exception& ex)
112 ROS_INFO_STREAM(
"Device with serial number " << sn <<
" was found."<<std::endl);
116 std::vector<std::string> results;
121 std::stringstream
msg;
122 msg <<
"Error extracting usb port from device with physical ID: " << pn << std::endl <<
"Please report on github issue at https://github.com/IntelRealSense/realsense-ros";
135 ROS_INFO_STREAM(
"Device with port number " << port_id <<
" was found.");
137 bool found_device_type(
true);
140 std::smatch match_results;
141 std::regex device_type_regex(
_device_type.c_str(), std::regex::icase);
142 found_device_type = std::regex_search(name, match_results, device_type_regex);
156 std::string
msg (
"The requested device with ");
180 msg +=
" is NOT found. Will Try again.";
189 if (usb_type.find(
"2.") != std::string::npos)
191 ROS_WARN_STREAM(
"Device " <<
_serial_no <<
" is connected using a " << usb_type <<
" port. Reduced performance is expected.");
199 if (remove_tm2_handle)
213 catch(
const std::exception& ex)
224 ROS_ERROR(
"The device has been disconnected!");
252 std::cout <<
"Attach to Process: " << getpid() << std::endl;
253 std::cout <<
"Press <ENTER> key to continue." << std::endl;
258 privateNh.param(
"serial_no",
_serial_no, std::string(
""));
259 privateNh.param(
"usb_port_id",
_usb_port_id, std::string(
""));
260 privateNh.param(
"device_type",
_device_type, std::string(
""));
266 std::string rosbag_filename(
"");
267 privateNh.param(
"rosbag_filename", rosbag_filename, std::string(
""));
269 if (!rosbag_filename.empty())
272 ROS_INFO_STREAM(
"publish topics from rosbag file: " << rosbag_filename.c_str());
273 auto pipe = std::make_shared<rs2::pipeline>();
275 cfg.enable_device_from_file(rosbag_filename.c_str(),
false);
276 cfg.enable_all_streams();
278 _device = pipe->get_active_profile().get_device();
293 double reconnect_timeout;
294 privateNh.param(
"reconnect_timeout", reconnect_timeout, 6.0);
295 double wait_for_device_timeout;
296 privateNh.param(
"wait_for_device_timeout", wait_for_device_timeout, -1.0);
297 std::chrono::milliseconds timespan(static_cast<int>(reconnect_timeout*1e3));
310 std::chrono::milliseconds actual_timespan(timespan);
311 if (wait_for_device_timeout > 0)
313 auto time_to_timeout(wait_for_device_timeout - (
ros::Time::now() - first_try_time).toSec());
314 if (time_to_timeout < 0)
316 ROS_ERROR_STREAM(
"wait for device timeout of " << wait_for_device_timeout <<
" secs expired");
321 double max_timespan_secs(std::chrono::duration_cast<std::chrono::seconds>(timespan).
count());
322 actual_timespan = std::chrono::milliseconds (static_cast<int>(std::min(max_timespan_secs, time_to_timeout) * 1e3));
325 std::this_thread::sleep_for(actual_timespan);
335 catch(
const std::exception& ex)
431 static const char* severity_var_name =
"LRS_LOG_LEVEL";
432 auto content = getenv(severity_var_name);
436 std::string content_str(content);
437 std::transform(content_str.begin(), content_str.end(), content_str.begin(), ::toupper);
442 std::transform(current.begin(), current.end(), current.begin(), ::toupper);
443 if (content_str == current)
std::thread _query_thread
const char * rs2_log_severity_to_string(rs2_log_severity severity)
bool handleReset(std_srvs::Empty::Request &request, std_srvs::Empty::Response &response)
GLenum GLuint GLenum severity
RS2_CAMERA_INFO_PHYSICAL_PORT
const char * get_info(rs2_camera_info info) const
const uint16_t RS430_MM_RGB_PID
RS2_CAMERA_INFO_SERIAL_NUMBER
const uint16_t RS_L515_PID_PRE_PRQ
RS2_CAMERA_INFO_PRODUCT_ID
ros::NodeHandle & getNodeHandle() const
std::string api_version_to_string(int version)
const uint16_t RS_T265_PID
bool toggle_sensor_callback(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)
const uint16_t RS_USB2_PID
ros::ServiceServer toggle_sensor_srv
void unload_tracking_module()
ros::NodeHandle & getPrivateNodeHandle() const
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
device_list query_devices() const
void initialize(const ros::WallTimerEvent &ignored)
static std::string parse_usb_port(std::string line)
const uint16_t RS420_MM_PID
WallTimer createWallTimer(WallDuration period, void(T::*callback)(const WallTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
void tryGetLogSeverity(rs2_log_severity &severity) const
const uint16_t SR300v2_PID
RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR
const uint16_t RS430_MM_PID
#define ROS_FATAL_STREAM(args)
std::shared_ptr< InterfaceRealSenseNode > _realSenseNode
constexpr auto realsense_ros_camera_version
const uint16_t RS435_RGB_PID
virtual ~RealSenseNodeFactory()
#define ROS_WARN_STREAM(args)
const uint16_t RS_L515_PID
const uint16_t RS_L535_PID
int rs2_get_api_version(rs2_error **error) BEGIN_API_CALL
#define REALSENSE_ROS_EMBEDDED_VERSION_STR
void log_to_console(rs2_log_severity min_severity)
ros::ServiceServer _reset_srv
bool supports(rs2_camera_info info) const
#define ROS_INFO_STREAM(args)
void change_device_callback(rs2::event_information &info)
#define RS2_API_VERSION_STR
#define REALSENSE_ROS_VERSION_STR
void set_devices_changed_callback(T callback)
ros::WallTimer _init_timer
ROSCPP_DECL void shutdown()
int stoi(const std::string &value)
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
#define ROS_ERROR_STREAM(args)
const uint16_t RS435i_RGB_PID
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual void onInit() override
#define ROSCONSOLE_DEFAULT_NAME
void getDevice(rs2::device_list list)