laserscanner_lms400.cpp
Go to the documentation of this file.
1 
19 #include <stdio.h> // standard input / output functions
20 #include <stdlib.h>
21 #include <string.h> // string function definitions
22 #include <unistd.h> // UNIX standard function definitions
23 #include <fcntl.h> // File control definitions
24 #include <errno.h> // Error number definitions
25 #include <stdint.h> // UINT
26 #ifndef Q_MOC_RUN
27 #include <ros/ros.h>
28 #endif
29 
30 
31 LaserScanner_LMS400::LaserScanner_LMS400(std::string hostname, int framerate) : Abstract_LaserScanner()
32 {
33  this->framerate = framerate;
34  this->hostname = hostname;
35  const char * h = hostname.c_str();
36  sickLMS400 = asr_sick_lms_400::asr_sick_lms_400((char *)h, 2111, 2);
37 
38  if (sickLMS400.Connect() != 0)
39  {
40  ROS_ERROR("Could not connect to LMS400!");
41  }
42  else
43  {
46 
48  //LMS400ConfigByAngle( Socket, 3, (char*)"B18244B6",SCANNER_TARGET_RESOLUTION, 2,SCANNER_STARTING_ANGLE, SCANNER_ANGLE_SPREAD, &LMSError, &real_scan_freq, &scanner_actual_resolution, &MQuality);
49  //calibration_scan_values = (SCANNER_STARTING_ANGLE/scanner_actual_resolution);
50  //calibration_scan_values = 70 / scanner_actual_resolution; //für 0.1
51  calibration_scan_values = 560; //für 0.2
52  //calibration_scan_values = 140; //für 0.5
53  //calibration_scan_values = 70; //für 1.0
54  //std::cout << "Value count: " << calibration_scan_values << std::endl;
55  sickLMS400.SetMeanFilterParameters(0);
56  ROS_INFO("LMS400: Initialization successful");
57  }
58 
59 }
60 
62 {
63  unsigned int microseconds = 20000;
64  ROS_INFO("LMS400: Start Measurement...");
65  if (sickLMS400.StartMeasurement(false) != 0)
66  {
67  ROS_ERROR("LMS400: Could not start Measurement!");
68  return;
69  }
70  active = true;
71  sensor_msgs::LaserScan msg;
72  unsigned int i = 1;
73  while (active)
74  {
75  msg = sickLMS400.ReadMeasurement();
76 
77  ROS_INFO_STREAM("Got " << msg.ranges.size() << " ranges");
78  if (msg.ranges.size() == 0)
79  {
80  ROS_ERROR("Received data is invalid! Using old data instead.");
81  }
82  else
83  { msg_ptr = sensor_msgs::LaserScan::Ptr(new sensor_msgs::LaserScan());
84  msg_ptr->header.stamp = ros::Time();
85  msg_ptr->header.frame_id = "map";
86  msg_ptr->header.seq = msg.header.seq;
87  msg_ptr->header.stamp = ros::Time();
88  msg_ptr->angle_min = msg.angle_min;
89  msg_ptr->angle_max = msg.angle_max;
90  msg_ptr->angle_increment = msg.angle_increment;
91  msg_ptr->range_max= msg.range_max;
92  msg_ptr->range_min= msg.range_min;
93  msg_ptr->time_increment = msg.time_increment;
94  msg_ptr->scan_time = msg.scan_time;
95  for (unsigned int i = 0; i< msg.ranges.size(); i++)
96  {
97  msg_ptr->ranges.push_back(msg.ranges[i]);
98  //ROS_INFO_STREAM("Range: " << msg.ranges[i]);
99  }
100  }
101  ROS_INFO_STREAM("Range " << i);
102  newData(msg_ptr);
103  usleep(microseconds);
104  ros::spinOnce();
105  i++;
106  }
107 }
108 
110 {
111  ROS_INFO("LMS400: Stop Measurement...");
112  active = false;
113  if (sickLMS400.StopMeasurement() != 0)
114  {
115  ROS_ERROR("LMS400: Could not stop Measurement!");
116  return;
117  }
118 }
sensor_msgs::LaserScan::Ptr msg_ptr
LaserScanner_LMS400(std::string hostname, int framerate)
static constexpr float SCANNER_TARGET_RESOLUTION
static constexpr float SCANNER_ANGLE_SPREAD
static constexpr float SCANNER_STARTING_ANGLE
void newData(const sensor_msgs::LaserScan::ConstPtr &msg)
#define ROS_INFO(...)
#define ROS_INFO_STREAM(args)
asr_sick_lms_400::asr_sick_lms_400 sickLMS400
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)


asr_mild_calibration_tool
Author(s): Aumann Florian, Heller Florian, Meißner Pascal
autogenerated on Mon Dec 2 2019 03:11:43