20 #define APPERTURE 4.712385 // in radian <=> 270 44 m_sensorPose(0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
46 m_beamApperture(.25 *
M_PI / 180.0)
51 CSICKTim561Eth::~CSICKTim561Eth()
53 if (m_connected) m_client.close();
58 void CSICKTim561Eth::initialize()
60 if (!checkIsConnected())
63 "Cannot connect to SICK Tim561 Ethernet Sensor check your " 70 void CSICKTim561Eth::loadConfig_sensorSpecific(
74 C2DRangeFinderAbstract::loadCommonParams(configSource, iniSection);
75 float pose_x, pose_y, pose_z, pose_yaw, pose_pitch, pose_roll;
77 pose_x = configSource.
read_float(iniSection,
"pose_x", 0,
false);
78 pose_y = configSource.
read_float(iniSection,
"pose_y", 0,
false);
79 pose_z = configSource.
read_float(iniSection,
"pose_z", 0,
false);
80 pose_yaw = configSource.
read_float(iniSection,
"pose_yaw", 0,
false);
81 pose_pitch = configSource.
read_float(iniSection,
"pose_pitch", 0,
false);
82 pose_roll = configSource.
read_float(iniSection,
"pose_roll", 0,
false);
84 iniSection,
"ip_address",
"192.168.0.1",
false);
85 m_port = configSource.
read_int(iniSection,
"TCP_port", 2111,
false);
87 configSource.
read_int(iniSection,
string(
"process_rate"), 15,
false);
89 configSource.
read_string(iniSection,
"sensorLabel",
"SICK",
false);
95 bool CSICKTim561Eth::checkIsConnected()
105 m_client.connect(m_ip, m_port);
107 catch (
const std::exception& e)
110 "[SICKTIM561ETH] ERROR TRYING TO OPEN Ethernet DEVICE:\n%s",
119 bool CSICKTim561Eth::rebootDev()
123 char msg[] = {
"sMN SetAccessMode 03 F4724744"};
127 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
135 "SOPAS - Error setting access mode, unexpected response");
141 char msg[] = {
"sMN mSCreboot"};
145 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
153 "SOPAS - Error rebootting scanner, unexpected response.");
160 bool CSICKTim561Eth::turnOff()
162 if (m_client.isConnected()) m_client.close();
168 bool CSICKTim561Eth::turnOn()
189 if (checkIsConnected())
197 char msg[] = {
"sRIO"};
201 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
209 "SOPAS - Error reading variable 'DeviceIdent'.");
216 char msg[] = {
"sRN SerialNumber"};
220 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
228 "SOPAS - Error reading variable 'SerialNumber'.");
235 char msg[] = {
"sRN FirmwareVersion"};
239 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
247 "SOPAS - Error reading variable 'FirmwareVersion'.");
254 char msg[] = {
"sRN SCdevicestate"};
258 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
266 "SOPAS - Error reading variable 'devicestate'.");
329 char msg[] = {
"sEN LMDscandata 1"};
332 size_t read = m_client.readAsync(msgIn, 100, 1000, 1000);
360 catch (
const std::exception& e)
373 void CSICKTim561Eth::sendCommand(
const char* cmd)
378 m_client.writeAsync(&m_cmd[0], m_cmd.size());
382 void CSICKTim561Eth::generateCmd(
const char* cmd)
384 if (strlen(cmd) > 995)
390 m_cmd =
format(
"%c%s%c%c", 0x02, cmd, 0x03, 0);
393 bool CSICKTim561Eth::decodeScan(
397 unsigned int idx = 0;
398 unsigned int scanCount = 0;
401 next =
strtok(buff,
" ", &tmp);
403 while (next && scanCount == 0)
409 if (strncmp(&next[1],
"sRA", 3) && strncmp(&next[1],
"sSN", 3))
415 if (strcmp(next,
"LMDscandata"))
421 if (strcmp(next,
"1"))
425 else if (strcmp(next,
"0"))
436 if (strcmp(next,
"DIST1"))
439 "TIM561 is not configured to send distances");
445 scanCount = strtoul(next,
nullptr, 16);
451 next =
strtok(
nullptr,
" ", &tmp);
458 outObservation.
maxRange = m_maxRange;
464 for (i = 0; i < scanCount && next; i++, next =
strtok(
nullptr,
" ", &tmp))
467 i,
double(strtoul(next,
nullptr, 16)) / 1000.0);
472 return i >= scanCount;
475 void CSICKTim561Eth::doProcessSimple(
481 hardwareError =
true;
482 outThereIsObservation =
false;
485 hardwareError =
false;
487 char msg[] = {
"sRN LMDscandata"};
489 char buffIn[16 * 1024];
491 m_client.readAsync(buffIn,
sizeof(buffIn), 40, 40);
493 if (decodeScan(buffIn, outObservation))
496 C2DRangeFinderAbstract::filterByExclusionAreas(outObservation);
497 C2DRangeFinderAbstract::filterByExclusionAngles(outObservation);
499 C2DRangeFinderAbstract::processPreview(outObservation);
502 outThereIsObservation =
true;
503 hardwareError =
false;
507 hardwareError =
true;
508 outThereIsObservation =
false;
513 void CSICKTim561Eth::doProcess()
516 std::make_shared<CObservation2DRangeScan>();
519 bool isThereObservation, hwError;
520 doProcessSimple(isThereObservation, *obs, hwError);
532 if (isThereObservation)
534 appendObservation(obs);
546 void CSICKTim561Eth::setSensorPose(
const CPose3D& _pose)
548 m_sensorPose = _pose;
#define MRPT_LOG_DEBUG(_STRING)
Use: MRPT_LOG_DEBUG("message");
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
#define MRPT_LOG_ERROR_FMT(_FMT_STRING,...)
#define THROW_EXCEPTION(msg)
float beamAperture
The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid...
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
void setScanRange(const size_t i, const float val)
double DEG2RAD(const double x)
Degrees to radians.
Contains classes for various device interfaces.
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
float stdError
The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid...
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
float maxRange
The maximum range allowed by the device, in meters (e.g.
This class allows loading and storing values and vectors of different types from a configuration text...
#define MRPT_LOG_DEBUG_FMT(_FMT_STRING,...)
Use: MRPT_LOG_DEBUG_FMT("i=%u", i);
float getScanRange(const size_t i) const
char * strtok(char *str, const char *strDelimit, char **context) noexcept
An OS-independent method for tokenizing a string.
This namespace contains representation of robot actions and observations.
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.
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).
#define MRPT_LOG_ERROR(_STRING)
void resizeScan(const size_t len)
Resizes all data vectors to allocate a given number of scan rays.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees)...
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)