19 #define APPERTURE 4.712385 // in radian <=> 270° 39 m_sensorPose(0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
41 m_beamApperture(.25*
M_PI/180.0)
43 setVerbosityLevel(mrpt::utils::LVL_DEBUG);
46 CLMS100Eth::~CLMS100Eth()
54 void CLMS100Eth::initialize()
56 if(!checkIsConnected())
58 THROW_EXCEPTION(
"Can't connect to LMS100 Ethernet Sensor check your configuration file.");
66 C2DRangeFinderAbstract::loadCommonParams(configSource, iniSection);
67 float pose_x, pose_y, pose_z, pose_yaw, pose_pitch, pose_roll;
69 pose_x = configSource.
read_float(iniSection,
"pose_x",0,
false);
70 pose_y = configSource.
read_float(iniSection,
"pose_y",0,
false);
71 pose_z = configSource.
read_float(iniSection,
"pose_z",0,
false);
72 pose_yaw = configSource.
read_float(iniSection,
"pose_yaw",0,
false);
73 pose_pitch = configSource.
read_float(iniSection,
"pose_pitch",0,
false);
74 pose_roll = configSource.
read_float(iniSection,
"pose_roll",0,
false);
75 m_ip = configSource.
read_string(iniSection,
"ip_address",
"192.168.0.1",
false);
76 m_port = configSource.
read_int(iniSection,
"TCP_port", 2111,
false);
77 m_process_rate = configSource.
read_int(iniSection,
string(
"process_rate"), 10,
false);
78 m_sensorLabel = configSource.
read_string(iniSection,
"sensorLabel",
"SICK",
false);
79 m_sensorPose =
CPose3D( pose_x, pose_y, pose_z,
84 bool CLMS100Eth::checkIsConnected(
void)
86 if(m_connected)
return true;
90 m_client.connect(m_ip, m_port);
91 }
catch(std::exception &e)
101 bool CLMS100Eth::turnOff()
103 if(m_client.isConnected())
110 bool CLMS100Eth::turnOn()
120 if(checkIsConnected())
124 char msg[] = {
"sMN SetAccessMode 03 F4724744"};
128 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
134 if(!read)
return false;
137 char msg[] = {
"sMN mLMPsetscancfg +2500 +1 +2500 -450000 +2250000"};
141 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
147 if(!read)
return false;
150 char msg[] = {
"sWN LMDscandatacfg 01 00 0 1 0 00 00 0 0 0 0 +1"};
154 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
160 if(!read)
return false;
163 char msg[] = {
"sMN LMCstartmeas"};
166 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
170 if(!read)
return false;
174 char msg[] = {
"sRN STlms"};
177 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
183 if(!read)
return false;
184 }
while(msgIn[11] !=
'7');
187 }
catch(std::exception &e)
199 void CLMS100Eth::sendCommand(
const char *cmd)
203 m_client.writeAsync(&m_cmd[0], m_cmd.size());
208 void CLMS100Eth::generateCmd(
const char *cmd)
210 if(strlen(cmd) > 995)
215 m_cmd =
format(
"%c%s%c",0x02,cmd,0x03);
222 unsigned int idx = 0;
223 unsigned int scanCount = 0;
227 next =
strtok(buff,
" ", &tmp);
229 while (next && scanCount == 0)
235 if (strncmp(&next[1],
"sRA", 3) && strncmp(&next[1],
"sSN", 3))
239 if (strcmp(next,
"LMDscandata"))
return false;
242 if (!strcmp(next,
"1"))
246 else if (!strcmp(next,
"4"))
249 "Contamination error on LMS100: '%s'", next);
257 if (strcmp(next,
"DIST1"))
260 "LMS100 is not configured to send distances.");
269 scanCount = strtoul(next,
nullptr, 16);
275 next =
strtok(
nullptr,
" ", &tmp);
282 outObservation.
maxRange = m_maxRange;
288 for(i = 0 ; i < scanCount && next; i++, next =
strtok(NULL,
" ", &tmp))
290 outObservation.
setScanRange(i,
double(strtoul(next, NULL, 16))/1000.0);
301 hardwareError =
true;
302 outThereIsObservation =
false;
305 hardwareError =
false;
307 char msg[] = {
"sRN LMDscandata"};
309 char buffIn[16*1024];
314 m_client.readAsync(buffIn,
sizeof(buffIn), 40, 40);
316 if(decodeScan(buffIn, outObservation))
319 C2DRangeFinderAbstract::filterByExclusionAreas( outObservation );
320 C2DRangeFinderAbstract::filterByExclusionAngles( outObservation );
322 C2DRangeFinderAbstract::processPreview(outObservation);
324 outThereIsObservation =
true;
325 hardwareError =
false;
328 hardwareError =
true;
329 outThereIsObservation =
false;
335 void CLMS100Eth::doProcess( )
337 CObservation2DRangeScanPtr obs= CObservation2DRangeScan::Create();
340 bool isThereObservation, hwError;
341 doProcessSimple(isThereObservation, *obs, hwError);
342 if(hwError) m_state = ssError;
343 else m_state = ssWorking;
345 if(isThereObservation)
347 appendObservation( obs );
359 void CLMS100Eth::setSensorPose(
const CPose3D& _pose)
361 m_sensorPose = _pose;
This "software driver" implements the communication protocol for interfacing a SICK LMS100 laser scan...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
float beamAperture
The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid...
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
void setScanRange(const size_t i, const float val)
#define THROW_EXCEPTION(msg)
#define MRPT_LOG_DEBUG_FMT(_FMT_STRING,...)
Contains classes for various device interfaces.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
float stdError
The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid...
#define MRPT_LOG_ERROR_FMT(_FMT_STRING,...)
This class allows loading and storing values and vectors of different types from a configuration text...
float maxRange
The maximum range allowed by the device, in meters (e.g. 80m, 50m,...)
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
float getScanRange(const size_t i) const
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
This namespace contains representation of robot actions and observations.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define MRPT_LOG_DEBUG(_STRING)
GLsizei const GLchar ** string
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp. Where available, this should contain the accurate satellite-based time...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void resizeScan(const size_t len)
Resizes all data vectors to allocate a given number of scan rays.
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees)...
#define MRPT_LOG_ERROR(_STRING)
char BASE_IMPEXP * strtok(char *str, const char *strDelimit, char **context) MRPT_NO_THROWS
An OS-independent method for tokenizing a string.
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
bool rightToLeft
The scanning direction: true=counterclockwise; false=clockwise.
void setScanRangeValidity(const size_t i, const bool val)