sick_scan_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013, Osnabrück University
3  * Copyright (C) 2017, Ing.-Buero Dr. Michael Lehning, Hildesheim
4  * Copyright (C) 2017, SICK AG, Waldkirch
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of Osnabrück University nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Created on: 24.05.2012
32  *
33  * Authors:
34  * Jochen Sprickerhof <jochen@sprickerhof.de>
35  * Martin Günther <mguenthe@uos.de>
36  * Michael Lehning <michael.lehning@lehning.de>
37  *
38  * Based on the TiM communication example by SICK AG.
39  *
40  */
41 
42 #ifndef SICK_SCAN_COMMON_H_
43 #define SICK_SCAN_COMMON_H_
44 
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string>
48 #include <string.h>
49 #include <vector>
50 
51 #include <boost/asio.hpp>
52 
53 #include <ros/ros.h>
54 #include <sensor_msgs/LaserScan.h>
55 #include <sensor_msgs/PointCloud.h>
56 #include <sensor_msgs/PointCloud2.h>
57 #include <std_msgs/String.h>
58 
59 #include <thread>
60 #include <mutex>
61 
66 
67 #ifndef _MSC_VER
68 
69 #include <dynamic_reconfigure/server.h>
70 #include <sick_scan/SickScanConfig.h>
71 
72 #endif
73 
76 
77 #include "sick_scan/Encoder.h"
80 
81 void swap_endian(unsigned char *ptr, int numBytes);
82 
83 namespace sick_scan
84 {
85 
87  {
88  public:
89  enum SOPAS_CMD
90  {
92  CMD_DEVICE_IDENT, // for MRS6124
131 
134 
135  CMD_START_IMU_DATA, // start of IMU data
136  CMD_STOP_IMU_DATA, // start of IMU data
137 
138  // start of radar specific commands
139  CMD_SET_TRANSMIT_RAWTARGETS_ON, // transmit raw target for radar
140  CMD_SET_TRANSMIT_RAWTARGETS_OFF, // do not transmit raw target for radar
141 
142  CMD_SET_TRANSMIT_OBJECTS_ON, // transmit raw target for radar
143  CMD_SET_TRANSMIT_OBJECTS_OFF, // do not transmit raw target for radar
144 
145  CMD_SET_TRACKING_MODE_0, // set radar tracking mode to "BASIC"
146  CMD_SET_TRACKING_MODE_1, // set radar tracking mode to "TRAFFIC"
147 
148  CMD_LOAD_APPLICATION_DEFAULT, // load application default
151  // end of radar specific commands
161  CMD_GET_ANGLE_COMPENSATION_PARAM, // Angle Compensation Parameter for NAV lidar
162  CMD_SET_TO_COLA_A_PROTOCOL, // sWN EIHstCola 1 // Cola B sWN EIHstCola 0 // Cola A
164  CMD_GET_SAFTY_FIELD_CFG,// gets the safty fields cfg olny tim 7xxs supported at the moment
165 
166  CMD_SET_LFEREC_ACTIVE, // activate LFErec messages, send "sEN LFErec 1"
167  CMD_SET_LID_OUTPUTSTATE_ACTIVE, // activate LIDoutputstate messages, send "sEN LIDoutputstate 1"
168  CMD_SET_LID_INPUTSTATE_ACTIVE, // activate LIDinputstate messages, send "sEN LIDinputstate 1"
169 
170  // ML: Add above new CMD-Identifier
171  //
172  //
173  CMD_END // CMD_END is a tag for end of enum - never (re-)move it. It must be the last element.
174  };
175 // --- START KEYWORD DEFINITIONS ---
176 #define PARAM_MIN_ANG "min_ang"
177 #define PARAM_MAX_ANG "max_ang"
178 #define PARAM_RES_ANG "res_ang"
179 // --- END KEYWORD DEFINITIONS ---
180 
181 
182  SickScanCommon(SickGenericParser *parser);
183 
184  virtual ~SickScanCommon();
185 
186  int setParticleFilter(bool _active, int _particleThreshold);//actualy only 500 mm is working.
192  std::string generateExpectedAnswerString(const std::vector<unsigned char> requestStr);
193 
194  int sendSopasAndCheckAnswer(std::string request, std::vector<unsigned char> *reply, int cmdId);
195 
196  int sendSopasAndCheckAnswer(std::vector<unsigned char> request, std::vector<unsigned char> *reply, int cmdId);
197 
198  int setAligmentMode(int _AligmentMode);
199 
200  int setMeanFilter(bool _active, int _numberOfScans);
201 
202  int setApplicationMode(bool _active, int _mode); //0=RANG (Ranging) 1=FEVL (Field Application).
203  int ActivateStandBy(void);
204 
205  bool testSettingIpAddress();
206 
207  bool testsetParticleFilter();
208 
209  bool testsetMeanFilter();
210 
211  bool testsetAligmentMode();
212 
213  bool testsetActivateStandBy();
214 
215  bool testsetApplicationMode();
216 
217  int getReadTimeOutInMs();
218 
219  void setReadTimeOutInMs(int timeOutInMs);
220 
221  int getProtocolType(void);
222 
223  void setProtocolType(SopasProtocol cola_dialect_id);
224 
225  virtual int init();
226 
227  int loopOnce();
228 
229  void check_angle_range(SickScanConfig &conf);
230 
231  void update_config(sick_scan::SickScanConfig &new_config, uint32_t level = 0);
232 
233  double get_expected_frequency() const
234  { return expectedFrequency_; }
235 
236  int convertAscii2BinaryCmd(const char *requestAscii, std::vector<unsigned char> *requestBinary);
237 
238  int init_cmdTables();
239 
241 
244  virtual bool rebootScanner();
245 
247 
251  bool changeIPandreboot(boost::asio::ip::address_v4 IpAdress);
252 
254 
255  SickScanConfig *getConfigPtr()
256  {
257  return (&config_);
258  }
259 
261 
265  std::string sopasReplyToString(const std::vector<unsigned char> &reply)
266  {
267  return replyToString(reply);
268  }
269 
270 
271  // move back to private
272  /* FÜR MRS10000 brauchen wir einen Publish und eine NAchricht */
273  // Should we publish laser or point cloud?
274  // ros::Publisher cloud_pub_;
278  // sensor_msgs::PointCloud cloud_;
279  sensor_msgs::PointCloud2 cloud_;
281  // Dynamic Reconfigure
282  SickScanConfig config_;
283  protected:
284  virtual int init_device() = 0;
285 
286  virtual int init_scanner();
287 
288  virtual int stop_scanner();
289 
290  virtual int close_device() = 0;
291 
293 
298  virtual int sendSOPASCommand(const char *request, std::vector<unsigned char> *reply, int cmdLen = -1) = 0;
300 
307  virtual int get_datagram(ros::Time &recvTimeStamp, unsigned char *receiveBuffer, int bufferSize, int *actual_length,
308  bool isBinaryProtocol, int *numberOfRemainingFifoEntries) = 0;
309 
311 
315  std::string replyToString(const std::vector<unsigned char> &reply);
316 
322  unsigned long convertBigEndianCharArrayToUnsignedLong(const unsigned char *vecArr);
323 
329  int checkForBinaryAnswer(const std::vector<unsigned char> *reply);
330 
336  bool isCompatibleDevice(const std::string identStr) const;
337 
338  bool dumpDatagramForDebugging(unsigned char *buffer, int bufLen);
339 
341 
342 
343  private:
345  // ROS
350 
356 
357  // Diagnostics
360 
361 
362 #ifndef _MSC_VER
363  dynamic_reconfigure::Server<sick_scan::SickScanConfig> dynamic_reconfigure_server_;
364 #endif
365  // Parser
367  std::vector<std::string> sopasCmdVec;
368  std::vector<std::string> sopasCmdMaskVec;
369  std::vector<std::string> sopasReplyVec;
370  std::vector<std::vector<unsigned char> > sopasReplyBinVec;
371  std::vector<std::string> sopasReplyStrVec;
372  std::vector<std::string> sopasCmdErrMsg;
373  std::vector<int> sopasCmdChain;
374 
376 
377  bool checkForProtocolChangeAndMaybeReconnect(bool &useBinaryCmdNow);
378 
379  void setSensorIsRadar(bool _isRadar);
380 
381  bool getSensorIsRadar(void);
382 
383  bool setNewIpAddress(boost::asio::ip::address_v4 ipNewIPAddr, bool useBinaryCmd);
384 
385  bool setNTPServerAndStart(boost::asio::ip::address_v4 ipNewIPAddr, bool useBinaryCmd);
386 
388 
389  std::mutex sopasSendMutex; // mutex to lock sendSopasAndCheckAnswer
390 
391  private:
393 
395  };
396 
397 } /* namespace sick_scan */
398 #endif /* SICK_TIM3XX_COMMON_H_ */
bool changeIPandreboot(boost::asio::ip::address_v4 IpAdress)
Send a SOPAS command to the scanner that logs in the authorized client, changes the ip adress and the...
void setReadTimeOutInMs(int timeOutInMs)
set timeout in milliseconds
std::vector< std::string > sopasCmdErrMsg
void check_angle_range(SickScanConfig &conf)
check angle setting in the config and adjust the min_ang to the max_ang if min_ang greater than max_a...
int loopOnce()
parsing datagram and publishing ros messages
virtual int init_scanner()
initialize scanner
std::vector< std::string > sopasCmdMaskVec
std::vector< std::string > sopasReplyStrVec
std::vector< std::string > sopasCmdVec
int getReadTimeOutInMs()
get timeout in milliseconds
void update_config(sick_scan::SickScanConfig &new_config, uint32_t level=0)
updating configuration
ros::Publisher lidoutputstate_pub_
bool dumpDatagramForDebugging(unsigned char *buffer, int bufLen)
SickScanCommon(SickGenericParser *parser)
Construction of SickScanCommon.
int convertAscii2BinaryCmd(const char *requestAscii, std::vector< unsigned char > *requestBinary)
Convert ASCII-message to Binary-message.
virtual int init_device()=0
Interface for TCP/IP.
SickScanConfig * getConfigPtr()
bool setNewIpAddress(boost::asio::ip::address_v4 ipNewIPAddr, bool useBinaryCmd)
dynamic_reconfigure::Server< sick_scan::SickScanConfig > dynamic_reconfigure_server_
void swap_endian(unsigned char *ptr, int numBytes)
Universal swapping function.
diagnostic_updater::Updater diagnostics_
std::vector< std::string > sopasReplyVec
bool checkForProtocolChangeAndMaybeReconnect(bool &useBinaryCmdNow)
checks the current protocol type and gives information about necessary change
virtual bool rebootScanner()
Send a SOPAS command to the scanner that should cause a soft reset.
int getProtocolType(void)
get protocol type as enum
void setProtocolType(SopasProtocol cola_dialect_id)
set protocol type as enum
std::vector< int > sopasCmdChain
std::string replyToString(const std::vector< unsigned char > &reply)
Converts reply from sendSOPASCommand to string.
bool setNTPServerAndStart(boost::asio::ip::address_v4 ipNewIPAddr, bool useBinaryCmd)
std::string generateExpectedAnswerString(const std::vector< unsigned char > requestStr)
Generate expected answer string from the command string.
std::string sopasReplyToString(const std::vector< unsigned char > &reply)
Converts reply from sendSOPASCommand to string.
SickGenericParser * parser_
int checkForBinaryAnswer(const std::vector< unsigned char > *reply)
Check block for correct framing and starting sequence of a binary message.
void setSensorIsRadar(bool _isRadar)
virtual ~SickScanCommon()
Destructor of SickScanCommon.
virtual int close_device()=0
SickScanMarker * cloud_marker_
int sendSopasAndCheckAnswer(std::string request, std::vector< unsigned char > *reply, int cmdId)
send command and check answer
unsigned long convertBigEndianCharArrayToUnsignedLong(const unsigned char *vecArr)
Convert little endian to big endian (should be replaced by swap-routine)
virtual int init()
init routine of scanner
int setParticleFilter(bool _active, int _particleThreshold)
double get_expected_frequency() const
virtual int stop_scanner()
Stops sending scan data.
virtual int get_datagram(ros::Time &recvTimeStamp, unsigned char *receiveBuffer, int bufferSize, int *actual_length, bool isBinaryProtocol, int *numberOfRemainingFifoEntries)=0
Read a datagram from the device.
int setMeanFilter(bool _active, int _numberOfScans)
bool isCompatibleDevice(const std::string identStr) const
check the identification string
diagnostic_updater::DiagnosedPublisher< sensor_msgs::LaserScan > * diagnosticPub_
SopasProtocol
sensor_msgs::PointCloud2 cloud_
int setApplicationMode(bool _active, int _mode)
std::vector< std::vector< unsigned char > > sopasReplyBinVec
AngleCompensator * angleCompensator
int setAligmentMode(int _AligmentMode)
int init_cmdTables()
init command tables and define startup sequence
virtual int sendSOPASCommand(const char *request, std::vector< unsigned char > *reply, int cmdLen=-1)=0
Send a SOPAS command to the device and print out the response to the console.


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Wed May 5 2021 03:05:48