30 #include <boost/bind.hpp> 31 #include <boost/chrono.hpp> 32 #include <boost/thread.hpp> 33 #include <boost/thread/lock_guard.hpp> 34 #include <boost/thread/mutex.hpp> 35 #include <boost/asio.hpp> 42 #include <sensor_msgs/PointCloud.h> 43 #include <sensor_msgs/PointCloud2.h> 45 #include <sensor_msgs/MagneticField.h> 46 #include <sensor_msgs/Imu.h> 60 const boost::posix_time::ptime &time_read)
67 if (
cloud_.points.size() == 0)
74 for (
int i = 0; i < index[range_index.
nspots]; i++)
80 geometry_msgs::Point32 point;
81 point.x = points[i].x;
82 point.y = points[i].y;
83 point.z = points[i].z;
84 cloud_.points.push_back(point);
85 cloud_.channels[0].values.push_back(points[i].i);
101 float *data =
reinterpret_cast<float *
>(&
cloud2_.data[0]);
103 for (
int i = 0; i < index[range_index.
nspots]; i++)
109 *(data++) = points[i].x;
110 *(data++) = points[i].y;
111 *(data++) = points[i].z;
112 *(data++) = points[i].i;
125 ROS_INFO(
"Dropping timestamp jump backed cloud");
133 cloud_.channels[0].values.clear();
140 ROS_INFO(
"Dropping timestamp jump backed cloud2");
158 const std::string &message,
159 const boost::posix_time::ptime &time_read)
165 const boost::posix_time::ptime &time_read)
177 std::sort(sorted_timstamp_base.begin(), sorted_timstamp_base.end());
180 timestamp_base_ = sorted_timstamp_base[sorted_timstamp_base.size() / 2];
190 const boost::posix_time::ptime &time_read)
200 imu_.header.stamp = stamp;
201 for (
int i = 0; i < aux_header.
data_count; i++)
203 imu_.orientation_covariance[0] = -1.0;
204 imu_.angular_velocity.x = auxs[i].ang_vel.x;
205 imu_.angular_velocity.y = auxs[i].ang_vel.y;
206 imu_.angular_velocity.z = auxs[i].ang_vel.z;
207 imu_.linear_acceleration.x = auxs[i].lin_acc.x;
208 imu_.linear_acceleration.y = auxs[i].lin_acc.y;
209 imu_.linear_acceleration.z = auxs[i].lin_acc.z;
212 ROS_INFO(
"Dropping timestamp jump backed imu");
219 imu_.header.stamp += ros::Duration(aux_header.
data_ms * 0.001);
225 mag_.header.stamp = stamp;
226 for (
int i = 0; i < aux_header.
data_count; i++)
228 mag_.magnetic_field.x = auxs[i].mag.x;
229 mag_.magnetic_field.y = auxs[i].mag.y;
230 mag_.magnetic_field.z = auxs[i].mag.z;
233 ROS_INFO(
"Dropping timestamp jump backed mag");
240 mag_.header.stamp += ros::Duration(aux_header.
data_ms * 0.001);
277 ROS_WARN(
"'interlace' parameter is deprecated. Use horizontal_interlace instead.");
292 std::string output_cycle;
293 pnh_.
param(
"output_cycle", output_cycle, std::string(
"field"));
295 if (output_cycle.compare(
"frame") == 0)
297 else if (output_cycle.compare(
"field") == 0)
299 else if (output_cycle.compare(
"line") == 0)
303 ROS_ERROR(
"Unknown output_cycle value %s", output_cycle.c_str());
317 sensor_msgs::ChannelFloat32 channel;
318 channel.name = std::string(
"intensity");
319 cloud_.channels.push_back(channel);
326 sensor_msgs::PointField::FLOAT32,
"z", 1, sensor_msgs::PointField::FLOAT32,
327 "intensity", 1, sensor_msgs::PointField::FLOAT32);
371 ROS_DEBUG(
"PointCloud2 output disabled");
383 void cbTimer(
const boost::system::error_code& error)
396 boost::posix_time::milliseconds(500));
403 boost::thread thread(
404 boost::bind(&boost::asio::io_service::run, &
io_));
429 sensor_msgs::MagneticField
mag_;
443 boost::asio::io_service
io_;
469 int main(
int argc,
char **argv)
ros::Time mag_stamp_last_
void setAutoReset(const bool enable)
static const uint32_t AX_MASK_MAG
std::deque< ros::Time > timestamp_base_buffer_
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
sensor_msgs::PointCloud2 cloud2_
void publish(const boost::shared_ptr< M > &message) const
void requestData(const bool intensity=1, const bool start=1)
void cbConnect(bool success)
void registerAuxCallback(decltype(cb_aux_) cb)
boost::mutex connect_mutex_
void requestVerticalTable(const int itl=1)
void setHorizontalInterlace(const int itl)
void setTimeout(const double to)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setVerticalInterlace(const int itl)
static const uint32_t AX_MASK_ANGVEL
void setPointCloud2Fields(int n_fields,...)
void cbPing(const vssp::Header &header, const boost::posix_time::ptime &time_read)
void registerCallback(decltype(cb_point_) cb)
sensor_msgs::PointCloud cloud_
void registerErrorCallback(decltype(cb_error_) cb)
boost::asio::io_service io_
int horizontal_interlace_
void cbAux(const vssp::Header &header, const vssp::AuxHeader &aux_header, const boost::shared_array< vssp::Aux > &auxs, const boost::posix_time::ptime &time_read)
void requestAuxData(const bool start=1)
void cbTimer(const boost::system::error_code &error)
void cbError(const vssp::Header &header, const std::string &message, const boost::posix_time::ptime &time_read)
ros::Time timestamp_base_
std::string mag_frame_id_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void registerPingCallback(decltype(cb_ping_) cb)
std::string imu_frame_id_
void requestHorizontalTable()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static const uint32_t AX_MASK_LINACC
boost::asio::deadline_timer timer_
ros::Time imu_stamp_last_
uint32_t getNumSubscribers() const
void connect(const char *ip, const unsigned int port, decltype(cb_connect_) cb)
void cbPoint(const vssp::Header &header, const vssp::RangeHeader &range_header, const vssp::RangeIndex &range_index, const boost::shared_array< uint16_t > &index, const boost::shared_array< vssp::XYZI > &points, const boost::posix_time::ptime &time_read)
static Time fromBoost(const boost::posix_time::ptime &t)
ROSCPP_DECL void shutdown()
bool hasParam(const std::string &key) const
sensor_msgs::MagneticField mag_
ros::Time cloud_stamp_last_
int main(int argc, char **argv)