LuxBase.hpp
Go to the documentation of this file.
1 //
2 // LuxBase.hpp
3 //
4 // Created on: 18.07.2011
5 // Author: sick
6 //
7 
8 #ifndef LUXBASE_HPP
9 #define LUXBASE_HPP
10 
11 #include "../BasicDatatypes.hpp"
12 #include "../manager.hpp"
13 #include "../interfaces/tcp.hpp"
14 #include "../interfaces/file.hpp"
15 #include "../tools/SickThread.hpp"
16 #include "../datatypes/Position3D.hpp"
17 #include "../datatypes/Point2D.hpp"
18 #include "../datatypes/Scan.hpp"
19 
20 
21 namespace devices
22 {
23 
24 #define MRS_INPUTBUFFERSIZE 65536 // Size of the main input buffer
25 #define MRS_CMDREPLYBUFFERSIZE 8192 // Size of the command reply buffer (some bytes should be enough...)
26 
27 using namespace datatypes;
28 
30 {
31  // Common MRS commands
32  CmdMrsReset = 0x0000
33  , CmdMrsGetStatus = 0x0001
34  , CmdMrsSetMode = 0x0002
35  , CmdMrsSetConfig = 0x0003
36  , CmdMrsSaveConfig = 0x0004
37  , CmdMrsReadConfig = 0x0005
38  , CmdMrsFlashFirmware = 0x0006
39 
40  // Specific commands
41  , CmdMrsSetParameter = 0x0010
42  , CmdMrsGetParameter = 0x0011
44  , CmdMrsStartMeasure = 0x0020
45  , CmdMrsStopMeasure = 0x0021
48 };
49 
50 // Parameters of the MRS
52 {
53  ParaDataOutputFlag = 0x1012 // Sets the output flags to enable or disable scans, objects, ...
54  , ParaContourPointDensity = 0x1014 // 0: closest point only, 1: low density, 2: high density
55  , ParaMinimumObjectAge = 0x1017 // Minimum tracking age (number of scans) of an object to be transmitted. valid: 0..65535
56  , ParaMaximumPredictionAge = 0x1018 // Maximum prediction age (number of scans) of an object to be transmitted after last observation. valid: 0..65535
57  , ParaScanFrequency = 0x1102 // Sets the scan frequency, in 1/256 Hz (valid = 3200 (12.5 Hz),6400 (25.0 Hz) and 12800 (50 Hz)
58  , ParaStartAngle = 0x1100 // 1/32 deg, Valid is 1600..-1919; Start angle > end angle!
59  , ParaEndAngle = 0x1101 // 1/32 deg, Valid is 1599..-1920; Start angle > end angle!
60  , ParaSyncAngleOffset = 0x1103 // 1/32 deg, Valid is -5760..5759; angle under which the LD-MRS measures at the time of the external sync pulse
61  , ParaAngularResolutionType = 0x1104 // angular resolution type: 0=focused, 1=constant(0.25°), 2=FlexRes
62  , ParaRangeReduction = 0x1108 // Available for LDMRS800001.S01 only; 0: full sensitivity (default), 1: lower 4 layers reduced, 2: upper 4 layers reduced, 3: both reduced
63  , ParaUpsideDownMode = 0x1109 // UpsideDown mode on/off (0=off, 1=on)
64  , ParaIgnoreNearRange = 0x110A // Available for LDMRS800001.S01 only; 0: do not ignore points in near range (up to 15m), 1: ignore points in near range if 0x1108 is 1
65  , ParaSensitivityControl = 0x110B // 0: not active (default), 1: Sensitivity will be reduced dynamically down to 60% in case of direct sun light.
66  , ParaMountingX = 0x1200 // X-Pos of the scanner, in [cm]
67  , ParaMountingY = 0x1201 // Y-Pos of the scanner, in [cm]
68  , ParaMountingZ = 0x1202 // Z-Pos of the scanner, in [cm]
69  , ParaMountingYaw = 0x1203 // Yaw angle
70  , ParaMountingPitch = 0x1204 // Pitch angle
71  , ParaMountingRoll = 0x1205 // Roll angle
72  , ParaBeamTilt = 0x3302 // Beam tilt angle, in [compressedRadians]
73  , ParaNumSectors = 0x4000 // Flex Resolution number of sectors
74  , ParaSector1StartAngle = 0x4001 // Flex Resolution sector 1 start angle
75  , ParaSector2StartAngle = 0x4002 // Flex Resolution sector 2 start angle
76  , ParaSector3StartAngle = 0x4003 // Flex Resolution sector 3 start angle
77  , ParaSector4StartAngle = 0x4004 // Flex Resolution sector 4 start angle
78  , ParaSector5StartAngle = 0x4005 // Flex Resolution sector 5 start angle
79  , ParaSector6StartAngle = 0x4006 // Flex Resolution sector 6 start angle
80  , ParaSector7StartAngle = 0x4007 // Flex Resolution sector 7 start angle
81  , ParaSector8StartAngle = 0x4008 // Flex Resolution sector 8 start angle
82  , ParaSector1Resolution = 0x4009 // Flex Resolution sector 1 resolution
83  , ParaSector2Resolution = 0x400A // Flex Resolution sector 2 resolution
84  , ParaSector3Resolution = 0x400B // Flex Resolution sector 3 resolution
85  , ParaSector4Resolution = 0x400C // Flex Resolution sector 4 resolution
86  , ParaSector5Resolution = 0x400D // Flex Resolution sector 5 resolution
87  , ParaSector6Resolution = 0x400E // Flex Resolution sector 6 resolution
88  , ParaSector7Resolution = 0x400F // Flex Resolution sector 7 resolution
89  , ParaSector8Resolution = 0x4010 // Flex Resolution sector 8 resolution
90  , ParaOperatingMinutes = 0x3500 // Operating minutes
91  , ParaDetailedError = 0x7000 // detailed error number
92 };
93 
94 // This list is not complete. Just an excerpt.
96 {
104 };
105 
106 // Object classes
108 {
113  , ClassBike = 4
114  , ClassCar = 5
116 };
117 
119 {
123 };
124 
125 
126 //
127 // Generic device class of the LD-MRS Laserscanner
128 //
129 class LuxBase
130 {
131 public:
132  typedef void (*OnScanReceiveCallbackFunction)(void*);
133 // typedef void () OnScanReceiveCallbackFunction;
134 
135  // Tools, in generelle Klasse verschieben und inline machen!
136  void memreadLE(BYTE*& buffer, UINT16& value);
137  void memreadLE(BYTE*& buffer, UINT32& value);
138 
139 private:
140  // ----- member variables -----
141 
145  //
146  // Attention: If reply is received from a LUX3, this member contains the SVN-Revision-Number
147  // of current LUX3-Firmware.
148  // The Error value is not needed anymore for LUX3.
149  //
151  //
152  // Attention: If reply is received from a LUX3, this member contains the scanner type.
153  // The Error value is not needed anymore for LUX3.
154  //
157  UINT16 m_serialNumber[3]; // 0608 5600 0F00
158  UINT16 m_FPGATimestamp[3]; // 2007 1212 1840
159  UINT16 m_firmwareTimestamp[3]; // 2007 1002 1000
166  OnScanReceiveCallbackFunction m_onScanReceiveCallback;
168 
169  // Updates the device status including temperature
170  void updateThreadFunction(bool& endThread, UINT16& sleepTimeMs);
173 
175  std::string m_longName;
177  std::string m_ipAddress;
180  std::string m_inputFileName;
181 
185  double m_offsetX;
186  double m_offsetY;
187  double m_offsetZ;
188  double m_yawAngle;
189  double m_pitchAngle;
190  double m_rollAngle;
193 
194  // Input stuff
195  UINT8 m_inputBuffer[MRS_INPUTBUFFERSIZE];
196  UINT32 m_inBufferLevel; // Bytes in input buffer
198  // The CMD REPLY buffer is a separate buffer for everything except scans and object data
199  UINT32 m_cmdBufferLevel; // Bytes in reply input buffer
200  UINT8 m_cmdReplyBuffer[MRS_CMDREPLYBUFFERSIZE];
201 
206 
207  // error values
208  static const UINT16 Err_IF_SPORT = 0x0001;
209  static const UINT16 Err_IF_FPGAcontrol = 0x0002;
210  static const UINT16 Err_SPORTdata = 0x0004;
211  static const UINT16 Err_FPGAkonfiguration = 0x0008;
212  static const UINT16 Err_ConfReg = 0x0010;
213  static const UINT16 Err_Parameter = 0x0020;
214  static const UINT16 Err_Timing = 0x0040;
215  static const UINT16 Err_TrackingTimeout = 0x0080;
216  static const UINT16 Err_CANMessageLost = 0x0100;
217  static const UINT16 Err_FlexResParameter = 0x0200;
218 
219  // ----- Command and decode functions -----
220  bool sendMrsCommand(MrsCommandId cmd, UINT16 para = 0, UINT32 value = 0);
221  bool receiveMrsReply(MrsCommandId cmd, UINT32 timeoutMs, UINT32* value = NULL);
222  UINT32 buildDataHeader(UINT8* buffer, UINT32 sizeofThisMsg, UINT8 deviceId, UINT16 dataType);
223  UINT32 writeValueToBufferBE(UINT8* buffer, UINT32 value, UINT8 bytes);
224  UINT32 writeValueToBufferLE(UINT8* buffer, UINT32 value, UINT8 bytes);
225  UINT32 readUValueLE(UINT8* buffer, UINT8 bytes);
226  UINT64 readUINT64ValueLE(UINT8* buffer);
227  INT32 readValueLE(UINT8* buffer, UINT8 bytes);
228  UINT32 readUValueBE(UINT8* buffer, UINT8 bytes);
229  UINT16 decodeAnswerInInputBuffer(); // Decodes the general input buffer
230  UINT16 decodeAnswerInCmdReplyBuffer(); // Decodes the reply buffer (everything except scnas & objects)
231  void removeAnswerFromInputBuffer();
232  bool decodeGetStatus();
233  bool decodeGetParameter(UINT32* value);
234  void decodeObjects();
235  void decodeScan();
236  void decodeSensorInfo();
237  void decodeErrorMessage();
238  double convertTicktsToAngle(INT16 angleTicks);
239  Point2D readPoint2D(UINT8* buffer);
240  Point2D readSize2D(UINT8* buffer);
241  bool readBeamTilt();
242  bool readUpsideDown();
243  double getVAngleOfLayer(bool isRearMirrorSide, UINT8 layerNumber, double hAngle);
244 
245 
246 
247  static void readCallbackFunctionS(void* obj, BYTE* buffer, UINT32& numOfBytes);
248  void readCallbackFunction(BYTE* buffer, UINT32& numOfBytes);
249  void removeDataFromInputBuffer(UINT32 bytesToBeRemoved);
250  void moveDataFromInputToCmdBuffer(UINT32 bytesToBeMoved);
251  void makeIntValueEven(INT16& value);
252 
253  static std::string int2Version (UINT16 val);
254  static std::string version2string (UINT16 version, const UINT16 timestamp[3]);
255  static bool isValidVersion (UINT16 version) { return (version != 0x0000) && (version != 0xFFFF); }
256 
257  bool m_weWantScanData; // Flag if received data is to be decoded.
258  bool m_weWantObjectData; // Flag if received data is to be decoded.
259 // TimeOffsetFilter m_timeOffsetFilter;
261 
262 public:
263  LuxBase (Manager* manager, const UINT8 deviceID, const std::string longName,
264  std::string ipAddress, UINT16 tcpPortNumber,
265  double scanFrequency, double scanStartAngle, double scanEndAngle, double offsetX,
266  double offsetY, double offsetZ, double yawAngle, double pitchAngle, double rollAngle,
267  bool beVerbose, std::string inputFileName);
268  virtual ~LuxBase();
269 
270  virtual bool initFile(File::DisconnectFunction function, void* obj); // , bool beVerbose = false);
271  virtual bool initTcp(Tcp::DisconnectFunction function, void* obj); // , bool beVerbose = false);
272  virtual bool run(bool weWantScanData = true, bool weWantObjectData = true);
273  virtual bool isRunning();
274  virtual bool stop();
275 
276  void setOnScanReceiveCallbackFunction(OnScanReceiveCallbackFunction function, void* obj);
277 
278  bool cmd_getStatus();
279  bool cmd_stopMeasure();
280  bool cmd_startMeasure(bool weWantScanData = true, bool weWantObjectData = true);
281  bool cmd_getParameter(MrsParameterId parameter, UINT32* value);
282  bool cmd_setParameter(MrsParameterId parameter, UINT32 value);
283  bool cmd_setMountingPos(Position3D mp);
284  bool cmd_setScanAngles(double startAngle, double endAngle);
285  bool cmd_setSyncAngleOffset(double syncAngle);
286  bool cmd_setScanFrequency(double scanFreq);
287  bool cmd_setDataOutputFlags();
288  bool cmd_saveConfiguration();
289  bool cmd_setNtpTimestamp(UINT32 seconds, UINT32 fractionalSec);
290 
291  std::string getFPGAVersion () { ScopedLock lock(&m_updateMutex); return version2string (m_FPGAVersion , m_FPGATimestamp ); }
292  std::string getFirmwareVersion() { ScopedLock lock(&m_updateMutex); return version2string (m_firmwareVersion, m_firmwareTimestamp); }
293  UINT16 getFPGAError() { ScopedLock lock(&m_updateMutex); return m_FPGAError; }
294  UINT16 getDSPError() { ScopedLock lock(&m_updateMutex); return m_DSPError; }
295  double getTemperature();
296  UINT16 getScannerStatus() { ScopedLock lock(&m_updateMutex); return m_scannerStatus; }
297  std::string getSerialNumber();
298 
299  UINT16 getErrorRegister1() { return m_errorRegister1; }
300  UINT16 getErrorRegister2() { return m_errorRegister2; }
301  UINT16 getWarnRegister1() { return m_warnRegister1; }
302  UINT16 getWarnRegister2() { return m_warnRegister2; }
303 
304  void dumpHeader();
305  void dumpMessage();
306 
307  static const UINT32 ANGULAR_TICKS_PER_ROTATION = 11520; // [ticks], 360*32= 11520 ticks;
308 };
309 
310 } // namespace devices
311 
312 #endif // LUXBASE_HPP
0x0010 = sets a parameter in the sensor
Definition: LuxBase.hpp:41
MrsCommandId
Definition: LuxBase.hpp:29
UINT16 getWarnRegister2()
Definition: LuxBase.hpp:302
unsigned char BYTE
void * m_disconnectFunctionObjPtr
Definition: LuxBase.hpp:165
UINT16 m_FPGAVersion
Definition: LuxBase.hpp:143
std::string getFirmwareVersion()
Definition: LuxBase.hpp:292
std::string getFPGAVersion()
Definition: LuxBase.hpp:291
0x0004 = ID of the SaveConfig command
Definition: LuxBase.hpp:36
Mutex m_inputBufferMutex
Definition: LuxBase.hpp:197
uint16_t UINT16
A Position with orientation.
Definition: Position3D.hpp:149
0x0031 = sets NTP fractional seconds
Definition: LuxBase.hpp:47
std::string m_inputFileName
Definition: LuxBase.hpp:180
#define MRS_CMDREPLYBUFFERSIZE
Definition: LuxBase.hpp:25
double m_beamTiltAngle
Definition: LuxBase.hpp:191
UINT16 m_DSPError
Definition: LuxBase.hpp:155
void(* DisconnectFunction)(void *obj)
Definition: tcp.hpp:53
uint32_t UINT32
File::DisconnectFunction m_fileDisconnectFunction
Definition: LuxBase.hpp:164
0x001A = resets all parameters to the factory defaults
Definition: LuxBase.hpp:43
Definition: Mutex.hpp:16
double m_scanFrequency
Definition: LuxBase.hpp:182
0x0001 = ID of the GetStatus command
Definition: LuxBase.hpp:33
UINT32 m_inBufferLevel
Definition: LuxBase.hpp:196
bool m_weWantObjectData
Definition: LuxBase.hpp:258
double m_offsetZ
Definition: LuxBase.hpp:187
double m_scanStartAngle
Definition: LuxBase.hpp:183
double m_rollAngle
Definition: LuxBase.hpp:190
MrsParameterId
Definition: LuxBase.hpp:51
double m_scanEndAngle
Definition: LuxBase.hpp:184
UINT16 m_firmwareVersion
Definition: LuxBase.hpp:142
0x0000 = ID of the Reset command
Definition: LuxBase.hpp:32
0x0030 = sets NTP seconds
Definition: LuxBase.hpp:46
MrsObjectClasses
Definition: LuxBase.hpp:107
Mutex m_updateMutex
Access mutex for update.
Definition: LuxBase.hpp:172
UINT32 m_cmdBufferLevel
Definition: LuxBase.hpp:199
Manager * m_manager
Definition: LuxBase.hpp:174
UINT16 getErrorRegister2()
Definition: LuxBase.hpp:300
bool m_upsideDownActive
Definition: LuxBase.hpp:192
AngularResolutionType
Definition: LuxBase.hpp:118
UINT16 getWarnRegister1()
Definition: LuxBase.hpp:301
UINT16 m_warnRegister1
Definition: LuxBase.hpp:204
UINT16 getScannerStatus()
Definition: LuxBase.hpp:296
UINT16 m_errorRegister1
Definition: LuxBase.hpp:202
UINT16 m_FPGAError
Definition: LuxBase.hpp:150
0x0003 = ID of the SetConfig command
Definition: LuxBase.hpp:35
Definition: tcp.hpp:30
0x0002 = ID of the SetMode command
Definition: LuxBase.hpp:34
UINT16 m_scannerStatus
Definition: LuxBase.hpp:144
0x0006 = ID of the FlashFirmware command
Definition: LuxBase.hpp:38
0x0020 = starts the measurement with the currenly configured settings
Definition: LuxBase.hpp:44
int32_t INT32
0x0005 = ID of the ReadConfig command
Definition: LuxBase.hpp:37
UINT16 m_temperature
Definition: LuxBase.hpp:156
void(* DisconnectFunction)(void *obj)
Definition: file.hpp:46
UINT16 m_tcpPortNumber
Definition: LuxBase.hpp:178
bool m_weWantScanData
Definition: LuxBase.hpp:257
OnScanReceiveCallbackFunction m_onScanReceiveCallback
Definition: LuxBase.hpp:166
double m_offsetY
Definition: LuxBase.hpp:186
UINT16 m_warnRegister2
Definition: LuxBase.hpp:205
UINT16 m_errorRegister2
Definition: LuxBase.hpp:203
Tcp::DisconnectFunction m_tcpDisconnectFunction
Definition: LuxBase.hpp:163
UINT16 getDSPError()
Definition: LuxBase.hpp:294
#define MRS_INPUTBUFFERSIZE
Definition: LuxBase.hpp:24
double m_offsetX
Definition: LuxBase.hpp:185
UINT16 getErrorRegister1()
Definition: LuxBase.hpp:299
DetailedErrorNumber
Definition: LuxBase.hpp:95
std::string m_ipAddress
Definition: LuxBase.hpp:177
int16_t INT16
void * m_onScanReceiveCallbackObjPtr
Definition: LuxBase.hpp:167
Definition: file.hpp:31
static bool isValidVersion(UINT16 version)
Definition: LuxBase.hpp:255
uint64_t UINT64
0x0011 = reads a parameter from the sensor
Definition: LuxBase.hpp:42
double m_yawAngle
Definition: LuxBase.hpp:188
SickThread< LuxBase,&LuxBase::updateThreadFunction > m_updateThread
Definition: LuxBase.hpp:171
UINT16 getFPGAError()
Definition: LuxBase.hpp:293
uint8_t UINT8
double m_pitchAngle
Definition: LuxBase.hpp:189
std::string m_longName
Definition: LuxBase.hpp:175
0x0021 = stops the measurement
Definition: LuxBase.hpp:45
Wrapper class for posix threads.
Definition: SickThread.hpp:80


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Mon Oct 26 2020 03:27:30