ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
For more complicated cases, here's what I use:
sensor_msgs::PointCloud2ConstPtr pcl;
auto sub = nh.subscribe<sensor_msgs::PointCloud2>("scan", 10, [&](const sensor_msgs::PointCloud2ConstPtr& msg){pcl=msg;});
// publish
#define WAIT_FOR_MESSAGE(msg) \
while (ros::ok() && msg == nullptr) \
{ \
ros::spinOnce(); \
ros::WallDuration(0.01).sleep(); \
}
WAIT_FOR_MESSAGE(pcl)
2 | No.2 Revision |
For more complicated cases, here's what I use:
sensor_msgs::PointCloud2ConstPtr pcl;
auto sub = nh.subscribe<sensor_msgs::PointCloud2>("scan", 10, [&](const sensor_msgs::PointCloud2ConstPtr& msg){pcl=msg;});
// publish
#define WAIT_FOR_MESSAGE(msg) \
while (ros::ok() && msg == nullptr) \
{ \
ros::spinOnce(); \
ros::WallDuration(0.01).sleep(); \
}
WAIT_FOR_MESSAGE(pcl)
You can of course limit the maximum waiting time.
3 | No.3 Revision |
For more complicated cases, here's what I use:
sensor_msgs::PointCloud2ConstPtr pcl;
auto sub = nh.subscribe<sensor_msgs::PointCloud2>("scan", 10, [&](const sensor_msgs::PointCloud2ConstPtr& msg){pcl=msg;});
// publish
#define WAIT_FOR_MESSAGE(msg) \
{ size_t i = 0;\
while (ros::ok() && msg == nullptr) nullptr && i < 100) \
{ \
ros::spinOnce(); \
ros::WallDuration(0.01).sleep(); \
++i;\
} \
if (i == 100) ADD_FAILURE(); \
}
WAIT_FOR_MESSAGE(pcl)
You can of course limit the maximum waiting time.