40 const std::string &port,
44 scan_and_cloud_parser_(parser),
45 cloud_pub_(nh_.advertise<
sensor_msgs::PointCloud2>(
"cloud", 300)),
46 diagnosed_cloud_publisher_(cloud_pub_, diagnostics_,
47 diagnostic_updater::FrequencyStatusParam(&expectedFrequency_, &expectedFrequency_, 0.1, 10),
48 diagnostic_updater::TimeStampStatusParam(-1, 1.3 * 1.0/expectedFrequency_ - config_.time_offset)
64 unsigned char receiveBuffer[65536];
65 int actual_length = 0;
66 static unsigned int iteration_count = 0;
68 int result =
get_datagram(receiveBuffer, 65536, &actual_length);
71 ROS_ERROR(
"Read Error when getting datagram: %i.", result);
72 diagnostics_.
broadcast(diagnostic_msgs::DiagnosticStatus::ERROR,
"Read Error when getting datagram.");
75 if(actual_length <= 0)
79 if (iteration_count++ % (
config_.skip + 1) != 0)
84 std_msgs::String datagram_msg;
85 datagram_msg.data = std::string(reinterpret_cast<char*>(receiveBuffer));
89 sensor_msgs::LaserScan scan;
94 char* buffer_pos = (
char*)receiveBuffer;
96 while( (dstart = strchr(buffer_pos, 0x02)) && (dend = strchr(dstart + 1, 0x03)) )
98 size_t dlength = dend - dstart;
101 sensor_msgs::PointCloud2 cloud;
111 if(cloud.header.frame_id !=
"")
114 <<
" points in the frame \"" << cloud.header.frame_id <<
"\".");
123 if(scan.header.frame_id !=
"")
129 buffer_pos = dend + 1;
146 std::vector<unsigned char> access_reply;
147 int result =
sendSOPASCommand(
"\x02sMN SetAccessMode 03 F4724744\x03\0", &access_reply);
150 ROS_ERROR(
"SOPAS - Error setting access mode");
151 diagnostics_.
broadcast(diagnostic_msgs::DiagnosticStatus::ERROR,
"SOPAS - Error setting access mode.");
155 if (access_reply_str !=
"sAN SetAccessMode 1")
157 ROS_ERROR_STREAM(
"SOPAS - Error setting access mode, unexpected response : " << access_reply_str);
158 diagnostics_.
broadcast(diagnostic_msgs::DiagnosticStatus::ERROR,
"SOPAS - Error setting access mode.");
165 const char setActiveApplication[] = {
"\x02sWN SetActiveApplications 1 RANG 1\x03\0"};
166 std::vector<unsigned char> activeApplicationReply;
170 ROS_ERROR(
"SOPAS - SetActiveApplications failed 'sWN SetActiveApplications'.");
171 diagnostics_.
broadcast(diagnostic_msgs::DiagnosticStatus::ERROR,
"SOPAS - 'sWN SetActiveApplications 1 RANG 1'.");
174 std::string activeApplicationReplyStr =
replyToString(activeApplicationReply);
175 ROS_INFO_STREAM(
"active application reply: " << activeApplicationReplyStr);
180 const char requestScanData[] = {
"\x02sEN LMDscandata 1\x03\0"};
184 ROS_ERROR(
"SOPAS - Error starting to stream 'LMDscandata'.");
185 diagnostics_.
broadcast(diagnostic_msgs::DiagnosticStatus::ERROR,
"SOPAS - Error starting to stream 'LMDscandata'.");
ScanAndCloudParser * scan_and_cloud_parser_
void publish(const boost::shared_ptr< M > &message) const
virtual int init_scanner()
ros::Publisher datagram_pub_
double expectedFrequency_
virtual void publish(const boost::shared_ptr< T > &message)
diagnostic_updater::DiagnosedPublisher< sensor_msgs::LaserScan > * diagnosticPub_
static std::string replyToString(const std::vector< unsigned char > &reply)
Converts reply from sendSOPASCommand to string.
virtual int get_datagram(unsigned char *receiveBuffer, int bufferSize, int *actual_length)
Read a datagram from the device.
diagnostic_updater::DiagnosedPublisher< sensor_msgs::PointCloud2 > diagnosed_cloud_publisher_
diagnostic_updater::Updater diagnostics_
#define ROS_DEBUG_STREAM(args)
virtual int sendSOPASCommand(const char *request, std::vector< unsigned char > *reply)
Send a SOPAS command to the device and print out the response to the console.
virtual int parse_datagram(char *datagram, size_t datagram_length, SickTimConfig &config, sensor_msgs::LaserScan &scan, sensor_msgs::PointCloud2 &cloud)=0
#define ROS_INFO_STREAM(args)
void broadcast(int lvl, const std::string msg)
#define ROS_ERROR_STREAM(args)
virtual int init_scanner()
SickMrs1000Communication(const std::string &hostname, const std::string &port, int &timelimit, ScanAndCloudParser *parser)
virtual ~SickMrs1000Communication()