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 
62 
63 
64 #ifndef _MSC_VER
65 #include <dynamic_reconfigure/server.h>
66 #include <sick_scan/SickScanConfig.h>
67 #endif
70 
71 void swap_endian(unsigned char *ptr, int numBytes);
72 
73 namespace sick_scan
74 {
75 
77  {
78  public:
79  enum SOPAS_CMD
80  {
82  CMD_DEVICE_IDENT, // for MRS6124
112 
113  CMD_START_IMU_DATA, // start of IMU data
114  CMD_STOP_IMU_DATA, // start of IMU data
115 
116  // start of radar specific commands
117  CMD_SET_TRANSMIT_RAWTARGETS_ON, // transmit raw target for radar
118  CMD_SET_TRANSMIT_RAWTARGETS_OFF, // do not transmit raw target for radar
119 
120  CMD_SET_TRANSMIT_OBJECTS_ON, // transmit raw target for radar
121  CMD_SET_TRANSMIT_OBJECTS_OFF, // do not transmit raw target for radar
122 
123  CMD_SET_TRACKING_MODE_0, // set radar tracking mode to "BASIC"
124  CMD_SET_TRACKING_MODE_1, // set radar tracking mode to "TRAFFIC"
125 
126  CMD_LOAD_APPLICATION_DEFAULT, // load application default
129  // end of radar specific commands
138  CMD_SET_TO_COLA_A_PROTOCOL, // sWN EIHstCola 1 // Cola B sWN EIHstCola 0 // Cola A
140  // ML: Add above new CMD-Identifier
141  //
142  //
143  CMD_END // CMD_END is a tag for end of enum - never (re-)move it. It must be the last element.
144  };
145 // --- START KEYWORD DEFINITIONS ---
146 #define PARAM_MIN_ANG "min_ang"
147 #define PARAM_MAX_ANG "max_ang"
148 #define PARAM_RES_ANG "res_ang"
149 // --- END KEYWORD DEFINITIONS ---
150 
151 
152  SickScanCommon(SickGenericParser* parser);
153  virtual ~SickScanCommon();
154 
155  int setParticleFilter(bool _active, int _particleThreshold);//actualy only 500 mm is working.
161  std::string generateExpectedAnswerString(const std::vector<unsigned char> requestStr);
162  int sendSopasAndCheckAnswer(std::string request, std::vector<unsigned char> *reply, int cmdId);
163  int sendSopasAndCheckAnswer(std::vector<unsigned char> request, std::vector<unsigned char> *reply, int cmdId);
164 
165  int setAligmentMode(int _AligmentMode);
166  int setMeanFilter(bool _active, int _numberOfScans);
167  int setApplicationMode(bool _active, int _mode); //0=RANG (Ranging) 1=FEVL (Field Application).
168  int ActivateStandBy(void);
169  bool testSettingIpAddress();
170  bool testsetParticleFilter();
171  bool testsetMeanFilter();
172  bool testsetAligmentMode();
173  bool testsetActivateStandBy();
174  bool testsetApplicationMode();
175  int getReadTimeOutInMs();
176  void setReadTimeOutInMs(int timeOutInMs);
177  int getProtocolType(void);
178  void setProtocolType(SopasProtocol cola_dialect_id);
179  virtual int init();
180  int loopOnce();
181  void check_angle_range(SickScanConfig &conf);
182  void update_config(sick_scan::SickScanConfig &new_config, uint32_t level = 0);
183 
184  double get_expected_frequency() const { return expectedFrequency_; }
185  int convertAscii2BinaryCmd(const char *requestAscii, std::vector<unsigned char>* requestBinary);
186  int init_cmdTables();
187 
189 
192  virtual bool rebootScanner();
193 
195 
199  bool changeIPandreboot(boost::asio::ip::address_v4 IpAdress);
200 
202 
203  SickScanConfig* getConfigPtr()
204  {
205  return(&config_);
206  }
207 
208  // move back to private
209  /* FÜR MRS10000 brauchen wir einen Publish und eine NAchricht */
210  // Should we publish laser or point cloud?
211  // ros::Publisher cloud_pub_;
217  // sensor_msgs::PointCloud cloud_;
218  sensor_msgs::PointCloud2 cloud_;
220  // Dynamic Reconfigure
221  SickScanConfig config_;
222  protected:
223  virtual int init_device() = 0;
224  virtual int init_scanner();
225  virtual int stop_scanner();
226  virtual int close_device() = 0;
227 
229 
234  virtual int sendSOPASCommand(const char* request, std::vector<unsigned char> * reply, int cmdLen = -1) = 0;
236 
243  virtual int get_datagram(ros::Time &recvTimeStamp, unsigned char *receiveBuffer, int bufferSize, int *actual_length,
244  bool isBinaryProtocol, int *numberOfRemainingFifoEntries) = 0;
245 
247 
251  std::string replyToString(const std::vector<unsigned char> &reply);
257  unsigned long convertBigEndianCharArrayToUnsignedLong(const unsigned char *vecArr);
258 
264  int checkForBinaryAnswer(const std::vector<unsigned char>* reply);
265 
271  bool isCompatibleDevice(const std::string identStr) const;
272 
273  bool dumpDatagramForDebugging(unsigned char *buffer, int bufLen);
274 
276 
277 
278 
279 
280  private:
282  // ROS
287 
288 
289  // Diagnostics
292 
293 
294 #ifndef _MSC_VER
295  dynamic_reconfigure::Server<sick_scan::SickScanConfig> dynamic_reconfigure_server_;
296 #endif
297  // Parser
299  std::vector<std::string> sopasCmdVec;
300  std::vector<std::string> sopasCmdMaskVec;
301  std::vector<std::string> sopasReplyVec;
302  std::vector<std::vector<unsigned char> > sopasReplyBinVec;
303  std::vector<std::string> sopasReplyStrVec;
304  std::vector<std::string> sopasCmdErrMsg;
305  std::vector<int> sopasCmdChain;
306 
308  bool checkForProtocolChangeAndMaybeReconnect(bool& useBinaryCmdNow);
309  void setSensorIsRadar(bool _isRadar);
310  bool getSensorIsRadar(void);
311  bool setNewIpAddress(boost::asio::ip::address_v4 ipNewIPAddr, bool useBinaryCmd);
312  bool setNTPServerAndStart(boost::asio::ip::address_v4 ipNewIPAddr, bool useBinaryCmd);
313 
315 private:
317  };
318 
319 } /* namespace sick_scan */
320 #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
bool dumpDatagramForDebugging(unsigned char *buffer, int bufLen)
ros::Publisher cloud_radar_track_pub_
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_
ros::Publisher cloud_radar_rawtarget_pub_
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.
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
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
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 Tue Jul 9 2019 04:55:32