ros_driver.cpp
Go to the documentation of this file.
1 
34 #include <functional>
35 
36 #include <multisense_ros/laser.h>
37 #include <multisense_ros/camera.h>
38 #include <multisense_ros/pps.h>
39 #include <multisense_ros/imu.h>
40 #include <multisense_ros/status.h>
43 #include <ros/ros.h>
44 
45 using namespace crl::multisense;
46 
47 int main(int argc, char** argvPP)
48 {
49  ros::init(argc, argvPP, "multisense_driver");
50  ros::NodeHandle nh;
51  ros::NodeHandle nh_private_("~");
52 
53  //
54  // Get parameters from ROS/command-line
55 
56  std::string sensor_ip;
57  std::string tf_prefix;
58  int sensor_mtu;
59  int head_id;
60  int timeout_s;
61 
62 
63  nh_private_.param<std::string>("sensor_ip", sensor_ip, "10.66.171.21");
64  nh_private_.param<std::string>("tf_prefix", tf_prefix, "multisense");
65  nh_private_.param<int>("sensor_mtu", sensor_mtu, 1500);
66  nh_private_.param<int>("head_id", head_id, -1);
67  nh_private_.param<int>("camera_timeout_s", timeout_s, -1);
68 
69  Channel *d = NULL;
70 
71  try {
72 
73  RemoteHeadChannel rh_channel = 0;
74  switch(head_id) {
75  case 0:
76  rh_channel = Remote_Head_0;
77  break;
78  case 1:
79  rh_channel = Remote_Head_1;
80  break;
81  case 2:
82  rh_channel = Remote_Head_2;
83  break;
84  case 3:
85  rh_channel = Remote_Head_3;
86  break;
87  default:
88  rh_channel = Remote_Head_VPB;
89  break;
90  }
91 
92  d = Channel::Create(sensor_ip, rh_channel);
93  if (NULL == d) {
94  ROS_ERROR("multisense_ros: failed to create communication channel to sensor @ \"%s\" with head ID %d",
95  sensor_ip.c_str(), rh_channel);
96  return -2;
97  }
98 
99  Status status = d->setMtu(sensor_mtu);
100  if (Status_Ok != status) {
101  ROS_ERROR("multisense_ros: failed to set sensor MTU to %d: %s",
102  sensor_mtu, Channel::statusString(status));
104  return -3;
105  }
106 
107  //
108  // Anonymous namespace so objects can deconstruct before channel is destroyed
109  {
110  multisense_ros::Laser laser(d, tf_prefix);
111  multisense_ros::Camera camera(d, tf_prefix);
112  multisense_ros::Pps pps(d);
113  multisense_ros::Imu imu(d, tf_prefix);
114  multisense_ros::Status status(d);
115  multisense_ros::Statistics statistics(d);
117  std::bind(&multisense_ros::Camera::updateConfig, &camera, std::placeholders::_1),
118  std::bind(&multisense_ros::Camera::borderClipChanged, &camera,
119  std::placeholders::_1, std::placeholders::_2),
121  std::placeholders::_1),
122  std::bind(&multisense_ros::Camera::extrinsicsChanged, &camera,
123  std::placeholders::_1),
125  std::placeholders::_1),
126  std::bind(&multisense_ros::Camera::timeSyncChanged, &camera,
127  std::placeholders::_1, std::placeholders::_2));
128 
129  ros::Rate rate(50);
130  ros::Time last_status{ros::Time::now()};
131  const ros::Duration timeout{static_cast<double>(timeout_s)};
132 
133  ros::Time last_warning{};
134  ros::Duration warn_delay{1.1};
135  while (ros::ok()) {
136  ros::spinOnce();
137 
138  system::StatusMessage statusMessage;
139  const auto status_result = d->getDeviceStatus(statusMessage);
140  if (Status_Ok != status_result) {
141 
142  if (ros::Time::now() - last_warning > warn_delay) {
143  ROS_WARN("multisense_ros: missed camera status message");
144  last_warning = ros::Time::now();
145  }
146 
147  if (timeout > ros::Duration{0} && ros::Time::now() - last_status > timeout) {
148  ROS_ERROR("multisense_ros: shutting down due to connection timeout");
150  return -5;
151  }
152 
153  } else {
154  last_warning = ros::Time::now();
155  last_status = ros::Time::now();
156  }
157 
158  rate.sleep();
159  }
160  }
161 
163  return 0;
164 
165  } catch (const std::exception& e) {
166  ROS_ERROR("multisense_ros: caught exception: %s", e.what());
168  return -4;
169  }
170 }
multisense_ros::Camera::borderClipChanged
void borderClipChanged(const BorderClip &borderClipType, double borderClipValue)
Definition: camera.cpp:764
crl::multisense::Status_Ok
static CRL_CONSTEXPR Status Status_Ok
Status
Status
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
crl::multisense::Remote_Head_0
static CRL_CONSTEXPR RemoteHeadChannel Remote_Head_0
reconfigure.h
crl::multisense::Channel::Destroy
static void Destroy(Channel *instanceP)
ros.h
multisense_ros::Pps
Definition: pps.h:43
multisense_ros::Imu
Definition: imu.h:48
multisense_ros::Camera::timeSyncChanged
void timeSyncChanged(bool ptp_enabled, int32_t ptp_time_offset_sec)
Definition: camera.cpp:778
ros::spinOnce
ROSCPP_DECL void spinOnce()
crl::multisense::Remote_Head_VPB
static CRL_CONSTEXPR RemoteHeadChannel Remote_Head_VPB
statistics.h
ros::ok
ROSCPP_DECL bool ok()
laser.h
crl::multisense::Remote_Head_3
static CRL_CONSTEXPR RemoteHeadChannel Remote_Head_3
crl::multisense::Remote_Head_1
static CRL_CONSTEXPR RemoteHeadChannel Remote_Head_1
imu.h
multisense_ros::Reconfigure
Definition: reconfigure.h:70
multisense_ros::Status
Definition: status.h:43
multisense_ros::Camera::extrinsicsChanged
void extrinsicsChanged(crl::multisense::system::ExternalCalibration extrinsics)
Definition: camera.cpp:784
crl::multisense::Channel::statusString
static const char * statusString(Status status)
d
d
ROS_WARN
#define ROS_WARN(...)
pps.h
crl::multisense::Channel::Create
static Channel * Create(const std::string &sensorAddress)
multisense_ros::Camera::updateConfig
void updateConfig(const crl::multisense::image::Config &config)
Definition: camera.cpp:2202
multisense_ros::Camera::groundSurfaceSplineDrawParametersChanged
void groundSurfaceSplineDrawParametersChanged(const ground_surface_utilities::SplineDrawParameters &spline_draw_params)
Definition: camera.cpp:814
ros::Rate::sleep
bool sleep()
crl::multisense::Remote_Head_2
static CRL_CONSTEXPR RemoteHeadChannel Remote_Head_2
main
int main(int argc, char **argvPP)
Definition: ros_driver.cpp:47
multisense_ros::Statistics
Definition: statistics.h:43
camera.h
crl::multisense::Channel
ros::Time
multisense_ros::Camera
Definition: camera.h:60
multisense_ros::Camera::maxPointCloudRangeChanged
void maxPointCloudRangeChanged(double range)
Definition: camera.cpp:773
ROS_ERROR
#define ROS_ERROR(...)
crl::multisense
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
multisense_ros::Laser
Definition: laser.h:51
ros::Rate
ros::Duration
RemoteHeadChannel
int16_t RemoteHeadChannel
status.h
ros::NodeHandle
crl::multisense::system::StatusMessage
ros::Time::now
static Time now()


multisense_ros
Author(s):
autogenerated on Thu Apr 17 2025 02:49:25