00001 00018 #include "Laserscanner/laserscanner_lms400.h" 00019 #include <stdio.h> // standard input / output functions 00020 #include <stdlib.h> 00021 #include <string.h> // string function definitions 00022 #include <unistd.h> // UNIX standard function definitions 00023 #include <fcntl.h> // File control definitions 00024 #include <errno.h> // Error number definitions 00025 #include <stdint.h> // UINT 00026 #ifndef Q_MOC_RUN 00027 #include <ros/ros.h> 00028 #endif 00029 00030 00031 LaserScanner_LMS400::LaserScanner_LMS400(std::string hostname, int framerate) : Abstract_LaserScanner() 00032 { 00033 this->framerate = framerate; 00034 this->hostname = hostname; 00035 const char * h = hostname.c_str(); 00036 sickLMS400 = asr_sick_lms_400::asr_sick_lms_400((char *)h, 2111, 2); 00037 00038 if (sickLMS400.Connect() != 0) 00039 { 00040 ROS_ERROR("Could not connect to LMS400!"); 00041 } 00042 else 00043 { 00044 calibration_starting_angle = SCANNER_STARTING_ANGLE; 00045 calibration_angle_spread = SCANNER_ANGLE_SPREAD; 00046 00047 sickLMS400.SetResolutionAndFrequency(360.0, SCANNER_TARGET_RESOLUTION, SCANNER_STARTING_ANGLE,SCANNER_ANGLE_SPREAD); 00048 //LMS400ConfigByAngle( Socket, 3, (char*)"B18244B6",SCANNER_TARGET_RESOLUTION, 2,SCANNER_STARTING_ANGLE, SCANNER_ANGLE_SPREAD, &LMSError, &real_scan_freq, &scanner_actual_resolution, &MQuality); 00049 //calibration_scan_values = (SCANNER_STARTING_ANGLE/scanner_actual_resolution); 00050 //calibration_scan_values = 70 / scanner_actual_resolution; //für 0.1 00051 calibration_scan_values = 560; //für 0.2 00052 //calibration_scan_values = 140; //für 0.5 00053 //calibration_scan_values = 70; //für 1.0 00054 //std::cout << "Value count: " << calibration_scan_values << std::endl; 00055 sickLMS400.SetMeanFilterParameters(0); 00056 ROS_INFO("LMS400: Initialization successful"); 00057 } 00058 00059 } 00060 00061 void LaserScanner_LMS400::run() 00062 { 00063 unsigned int microseconds = 20000; 00064 ROS_INFO("LMS400: Start Measurement..."); 00065 if (sickLMS400.StartMeasurement(false) != 0) 00066 { 00067 ROS_ERROR("LMS400: Could not start Measurement!"); 00068 return; 00069 } 00070 active = true; 00071 sensor_msgs::LaserScan msg; 00072 unsigned int i = 1; 00073 while (active) 00074 { 00075 msg = sickLMS400.ReadMeasurement(); 00076 00077 ROS_INFO_STREAM("Got " << msg.ranges.size() << " ranges"); 00078 if (msg.ranges.size() == 0) 00079 { 00080 ROS_ERROR("Received data is invalid! Using old data instead."); 00081 } 00082 else 00083 { msg_ptr = sensor_msgs::LaserScan::Ptr(new sensor_msgs::LaserScan()); 00084 msg_ptr->header.stamp = ros::Time(); 00085 msg_ptr->header.frame_id = "map"; 00086 msg_ptr->header.seq = msg.header.seq; 00087 msg_ptr->header.stamp = ros::Time(); 00088 msg_ptr->angle_min = msg.angle_min; 00089 msg_ptr->angle_max = msg.angle_max; 00090 msg_ptr->angle_increment = msg.angle_increment; 00091 msg_ptr->range_max= msg.range_max; 00092 msg_ptr->range_min= msg.range_min; 00093 msg_ptr->time_increment = msg.time_increment; 00094 msg_ptr->scan_time = msg.scan_time; 00095 for (unsigned int i = 0; i< msg.ranges.size(); i++) 00096 { 00097 msg_ptr->ranges.push_back(msg.ranges[i]); 00098 //ROS_INFO_STREAM("Range: " << msg.ranges[i]); 00099 } 00100 } 00101 ROS_INFO_STREAM("Range " << i); 00102 newData(msg_ptr); 00103 usleep(microseconds); 00104 ros::spinOnce(); 00105 i++; 00106 } 00107 } 00108 00109 void LaserScanner_LMS400::stop() 00110 { 00111 ROS_INFO("LMS400: Stop Measurement..."); 00112 active = false; 00113 if (sickLMS400.StopMeasurement() != 0) 00114 { 00115 ROS_ERROR("LMS400: Could not stop Measurement!"); 00116 return; 00117 } 00118 }