29 #include <sensor_msgs/Image.h> 31 #include <sensor_msgs/PointCloud2.h> 32 #include <sensor_msgs/LaserScan.h> 33 #include <sensor_msgs/CameraInfo.h> 35 #include <nav_msgs/Odometry.h> 39 #include <std_srvs/Empty.h> 41 #include <rtabmap_ros/SetGoal.h> 53 bool pauseCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
81 int main(
int argc,
char** argv)
93 std::string frameId =
"base_link";
94 std::string odomFrameId =
"odom";
95 std::string cameraFrameId =
"camera_optical_link";
96 std::string scanFrameId =
"base_laser_link";
98 std::string databasePath =
"";
99 bool publishTf =
true;
102 pnh.
param(
"frame_id", frameId, frameId);
103 pnh.
param(
"odom_frame_id", odomFrameId, odomFrameId);
104 pnh.
param(
"camera_frame_id", cameraFrameId, cameraFrameId);
105 pnh.
param(
"scan_frame_id", scanFrameId, scanFrameId);
106 pnh.
param(
"rate", rate, rate);
107 pnh.
param(
"database", databasePath, databasePath);
108 pnh.
param(
"publish_tf", publishTf, publishTf);
109 pnh.
param(
"start_id", startId, startId);
112 double scanAngleMin, scanAngleMax, scanAngleIncrement, scanTime, scanRangeMin, scanRangeMax;
113 pnh.
param<
double>(
"scan_angle_min", scanAngleMin, -
M_PI);
114 pnh.
param<
double>(
"scan_angle_max", scanAngleMax,
M_PI);
115 pnh.
param<
double>(
"scan_angle_increment", scanAngleIncrement,
M_PI / 720.0);
116 pnh.
param<
double>(
"scan_time", scanTime, 0);
117 pnh.
param<
double>(
"scan_range_min", scanRangeMin, 0.0);
118 pnh.
param<
double>(
"scan_range_max", scanRangeMax, 60);
120 ROS_INFO(
"frame_id = %s", frameId.c_str());
121 ROS_INFO(
"odom_frame_id = %s", odomFrameId.c_str());
122 ROS_INFO(
"camera_frame_id = %s", cameraFrameId.c_str());
123 ROS_INFO(
"scan_frame_id = %s", scanFrameId.c_str());
125 ROS_INFO(
"publish_tf = %s", publishTf?
"true":
"false");
126 ROS_INFO(
"start_id = %d", startId);
128 if(databasePath.empty())
130 ROS_ERROR(
"Parameter \"database\" must be set (path to a RTAB-Map database).");
134 if(databasePath.size() && databasePath.at(0) !=
'/')
138 ROS_INFO(
"database = %s", databasePath.c_str());
143 ROS_ERROR(
"Cannot open database \"%s\".", databasePath.c_str());
170 double acquisitionTime = timer.
ticks();
173 ROS_INFO(
"Reading sensor data %d...", odom.
data().
id());
177 sensor_msgs::CameraInfo camInfoA;
178 sensor_msgs::CameraInfo camInfoB;
180 camInfoA.K.assign(0);
181 camInfoA.K[0] = camInfoA.K[4] = camInfoA.K[8] = 1;
182 camInfoA.R.assign(0);
183 camInfoA.R[0] = camInfoA.R[4] = camInfoA.R[8] = 1;
184 camInfoA.P.assign(0);
187 camInfoA.header.frame_id = cameraFrameId;
188 camInfoA.header.stamp = time;
197 ROS_WARN(
"Multi-cameras detected in database but this node cannot send multi-images yet...");
204 camInfoA.D.resize(5,0);
221 if(depthPub.
getTopic().empty()) depthPub = it.
advertise(
"depth_registered/image", 1);
222 if(rgbCamInfoPub.
getTopic().empty()) rgbCamInfoPub = nh.
advertise<sensor_msgs::CameraInfo>(
"rgb/camera_info", 1);
223 if(depthCamInfoPub.
getTopic().empty()) depthCamInfoPub = nh.
advertise<sensor_msgs::CameraInfo>(
"depth_registered/camera_info", 1);
231 camInfoA.D.resize(8,0);
250 if(leftCamInfoPub.
getTopic().empty()) leftCamInfoPub = nh.
advertise<sensor_msgs::CameraInfo>(
"left/camera_info", 1);
251 if(rightCamInfoPub.
getTopic().empty()) rightCamInfoPub = nh.
advertise<sensor_msgs::CameraInfo>(
"right/camera_info", 1);
266 if(scanPub.
getTopic().empty()) scanPub = nh.
advertise<sensor_msgs::LaserScan>(
"scan", 1);
281 if(!localTransform.
isNull())
284 baseToCamera.child_frame_id = cameraFrameId;
285 baseToCamera.header.frame_id = frameId;
286 baseToCamera.header.stamp = time;
294 odomToBase.child_frame_id = frameId;
295 odomToBase.header.frame_id = odomFrameId;
296 odomToBase.header.stamp = time;
304 baseToLaserScan.child_frame_id = scanFrameId;
305 baseToLaserScan.header.frame_id = frameId;
306 baseToLaserScan.header.stamp = time;
313 if(odometryPub.
getTopic().empty()) odometryPub = nh.
advertise<nav_msgs::Odometry>(
"odom", 1);
317 nav_msgs::Odometry odomMsg;
318 odomMsg.child_frame_id = frameId;
319 odomMsg.header.frame_id = odomFrameId;
320 odomMsg.header.stamp = time;
322 UASSERT(odomMsg.pose.covariance.size() == 36 &&
325 memcpy(odomMsg.pose.covariance.begin(), odom.
covariance().data, 36*
sizeof(double));
334 rgbCamInfoPub.
publish(camInfoA);
338 leftCamInfoPub.
publish(camInfoA);
342 depthCamInfoPub.
publish(camInfoB);
346 rightCamInfoPub.
publish(camInfoB);
362 sensor_msgs::ImagePtr imageRosMsg = img.
toImageMsg();
363 imageRosMsg->header.frame_id = cameraFrameId;
364 imageRosMsg->header.stamp = time;
377 leftCamInfoPub.
publish(camInfoA);
393 sensor_msgs::ImagePtr imageRosMsg = img.
toImageMsg();
394 imageRosMsg->header.frame_id = cameraFrameId;
395 imageRosMsg->header.stamp = time;
398 depthCamInfoPub.
publish(camInfoB);
406 sensor_msgs::ImagePtr imageRosMsg = img.
toImageMsg();
407 imageRosMsg->header.frame_id = cameraFrameId;
408 imageRosMsg->header.stamp = time;
411 rightCamInfoPub.
publish(camInfoB);
417 sensor_msgs::LaserScan msg;
418 msg.header.frame_id = scanFrameId;
419 msg.header.stamp = time;
421 msg.angle_min = scanAngleMin;
422 msg.angle_max = scanAngleMax;
423 msg.angle_increment = scanAngleIncrement;
424 msg.time_increment = 0.0;
425 msg.scan_time = scanTime;
426 msg.range_min = scanRangeMin;
427 msg.range_max = scanRangeMax;
429 uint32_t rangesSize =
std::ceil((msg.angle_max - msg.angle_min) / msg.angle_increment);
430 msg.ranges.assign(rangesSize, 0.0);
433 for (
int i=0; i<scan.cols; ++i)
435 const float * ptr = scan.ptr<
float>(0,i);
436 double range =
hypot(ptr[0], ptr[1]);
437 if (range >= scanRangeMin && range <=scanRangeMax)
440 if (angle >= msg.angle_min && angle <= msg.angle_max)
442 int index = (angle - msg.angle_min) / msg.angle_increment;
443 if (index>=0 && index<rangesSize && (range < msg.ranges[index] || msg.ranges[index]==0))
445 msg.ranges[index] = range;
463 std::list<std::string> strs =
uSplit(goalStr,
':');
466 int goalId = atoi(strs.rbegin()->c_str());
470 ROS_WARN(
"Goal %d detected, calling rtabmap's set_goal service!", goalId);
471 rtabmap_ros::SetGoal setGoalSrv;
472 setGoalSrv.request.node_id = goalId;
473 setGoalSrv.request.node_label =
"";
476 ROS_ERROR(
"Can't call \"set_goal\" service");
493 data = reader.takeImage(&cameraInfo);
496 acquisitionTime = timer.
ticks();
static std::string homeDir()
const cv::Mat & data() const
void publish(const boost::shared_ptr< M > &message) const
const LaserScan & laserScanCompressed() const
std::string uReplaceChar(const std::string &str, char before, char after)
int main(int argc, char **argv)
bool call(const std::string &service_name, MReq &req, MRes &res)
void transformToGeometryMsg(const rtabmap::Transform &transform, geometry_msgs::Transform &msg)
bool resumeCallback(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
INLINE Rall1d< T, V, S > hypot(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
const LaserScan & laserScanRaw() const
const cv::Mat & imageRaw() const
uint32_t getNumSubscribers() const
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
#define UASSERT(condition)
bool pauseCallback(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
const Transform & pose() const
static std::string currentDir(bool trailingSeparator=false)
bool isValidForProjection() const
const CameraModel & left() const
image_transport::Publisher imagePub
void publish(const sensor_msgs::Image &message) const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
const std::string TYPE_32FC1
const std::string TYPE_16UC1
Transform localTransform() const
const cv::Mat & depthOrRightRaw() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
const cv::Mat & userDataRaw() const
GLM_FUNC_QUALIFIER T atan2(T x, T y)
const cv::Mat & covariance() const
void transformToPoseMsg(const rtabmap::Transform &transform, geometry_msgs::Pose &msg)
void uSleep(unsigned int ms)
const std::vector< CameraModel > & cameraModels() const
uint32_t getNumSubscribers() const
const CameraModel & right() const
const StereoCameraModel & stereoCameraModel() const
std::string getTopic() const
ROSCPP_DECL void spinOnce()
std::string getTopic() const
GLM_FUNC_DECL genType ceil(genType const &x)
sensor_msgs::ImagePtr toImageMsg() const
const Transform & localTransform() const