6 #include <boost/thread.hpp>
10 #include <sensor_msgs/CameraInfo.h>
11 #include <sensor_msgs/PointCloud2.h>
13 #include <std_msgs/ByteMultiArray.h>
32 std::shared_ptr<diagnostic_updater::Updater>
updater;
52 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"driver running");
72 sensor_msgs::CameraInfo ci;
86 for (
int i = 0;
i < 9;
i++)
96 for (
int i = 0;
i < 12;
i++)
110 std::vector<uint16_t> vec = dataHandler.
getZMap();
112 memcpy(m.data, vec.data(), vec.size() *
sizeof(uint16_t));
113 sensor_msgs::ImagePtr
msg =
124 memcpy(m.data, vec.data(), vec.size() *
sizeof(uint16_t));
125 sensor_msgs::ImagePtr
msg =
134 std::vector<uint32_t> vec = dataHandler.
getRGBAMap();
136 memcpy(m.data, vec.data(), vec.size() *
sizeof(uint32_t));
137 sensor_msgs::ImagePtr
msg =
150 cloudMsg->header =
header;
151 cloudMsg->height = dataHandler.
getHeight();
152 cloudMsg->width = dataHandler.
getWidth();
153 cloudMsg->is_dense =
false;
154 cloudMsg->is_bigendian =
false;
156 cloudMsg->fields.resize(5);
157 cloudMsg->fields[0].name =
"x";
158 cloudMsg->fields[1].name =
"y";
159 cloudMsg->fields[2].name =
"z";
160 cloudMsg->fields[3].name =
"confidence";
161 cloudMsg->fields[4].name =
"rgba";
163 for (
size_t d = 0;
d < 3; ++
d, offset +=
sizeof(float))
165 cloudMsg->fields[
d].offset = offset;
166 cloudMsg->fields[
d].datatype = int(sensor_msgs::PointField::FLOAT32);
167 cloudMsg->fields[
d].count = 1;
170 cloudMsg->fields[3].offset = offset;
171 cloudMsg->fields[3].datatype = int(sensor_msgs::PointField::UINT16);
172 cloudMsg->fields[3].count = 1;
173 offset +=
sizeof(uint16_t);
175 cloudMsg->fields[4].offset = offset;
176 cloudMsg->fields[4].datatype = int(sensor_msgs::PointField::UINT32);
177 cloudMsg->fields[4].count = 1;
178 offset +=
sizeof(uint32_t);
180 cloudMsg->point_step = offset;
181 cloudMsg->row_step = cloudMsg->point_step * cloudMsg->width;
182 cloudMsg->data.resize(cloudMsg->height * cloudMsg->row_step);
184 std::vector<PointXYZ> pointCloud;
191 std::vector<uint16_t>::const_iterator itConf = dataHandler.
getConfidenceMap().begin();
192 std::vector<uint32_t>::const_iterator itRGBA = dataHandler.
getRGBAMap().begin();
193 std::vector<PointXYZ>::const_iterator itPC = pointCloud.begin();
195 for (
size_t index = 0; index < cloudSize; ++index, ++itConf, ++itRGBA, ++itPC)
197 memcpy(&cloudMsg->data[index * cloudMsg->point_step + cloudMsg->fields[0].offset], &*itPC,
sizeof(
PointXYZ));
199 memcpy(&cloudMsg->data[index * cloudMsg->point_step + cloudMsg->fields[3].offset], &*itConf,
sizeof(uint16_t));
200 memcpy(&cloudMsg->data[index * cloudMsg->point_step + cloudMsg->fields[4].offset], &*itRGBA,
sizeof(uint32_t));
207 bool publishedAnything =
false;
215 publishedAnything =
true;
221 publishedAnything =
true;
227 publishedAnything =
true;
233 publishedAnything =
true;
239 publishedAnything =
true;
244 if (publishedAnything)
271 void thr_receive_frame(std::shared_ptr<VisionaryDataStream> pDataStream, std::shared_ptr<VisionarySData> pDataHandler)
275 if (!pDataStream->getNextFrame())
286 ROS_INFO(
"skipping frame with number %d", pDataHandler->getFrameNum());
324 int main(
int argc,
char** argv)
326 ros::init(argc, argv,
"sick_visionary_s");
330 std::string remoteDeviceIp =
"192.168.1.10";
340 std::shared_ptr<VisionarySData> pDataHandler = std::make_shared<VisionarySData>();
341 std::shared_ptr<VisionaryDataStream> pDataStream = std::make_shared<VisionaryDataStream>(pDataHandler);
342 gControl = std::make_shared<VisionaryControl>();
344 ROS_INFO(
"Connecting to device at %s", remoteDeviceIp.c_str());
345 if (!
gControl->open(VisionaryControl::ProtocolType::COLA_B, remoteDeviceIp.c_str(), 5000 ))
347 ROS_ERROR(
"Connection with devices control channel failed");
353 if (!pDataStream->open(remoteDeviceIp.c_str(), 2114))
355 ROS_ERROR(
"Connection with devices data channel failed");
360 ROS_INFO(
"Connected with Visionary-S");
398 double min_freq = desiredFreq * 0.9;
399 double max_freq = desiredFreq * 1.1;
433 boost::thread rec_thr(boost::bind(&
thr_receive_frame, pDataStream, pDataHandler));
443 pDataStream->close();