sick_scan_common.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013, Osnabrück University
00003  * Copyright (C) 2017, Ing.-Buero Dr. Michael Lehning, Hildesheim
00004  * Copyright (C) 2017, SICK AG, Waldkirch
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of Osnabrück University nor the names of its
00016  *       contributors may be used to endorse or promote products derived from
00017  *       this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  *  Created on: 24.05.2012
00032  *
00033  *      Authors:
00034  *         Jochen Sprickerhof <jochen@sprickerhof.de>
00035  *         Martin Günther <mguenthe@uos.de>
00036  *         Michael Lehning <michael.lehning@lehning.de>
00037  *
00038  * Based on the TiM communication example by SICK AG.
00039  *
00040  */
00041 
00042 #ifndef SICK_SCAN_COMMON_H_
00043 #define SICK_SCAN_COMMON_H_
00044 
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <string>
00048 #include <string.h>
00049 #include <vector>
00050 
00051 #include <boost/asio.hpp>
00052 
00053 #include <ros/ros.h>
00054 #include <sensor_msgs/LaserScan.h>
00055 #include <sensor_msgs/PointCloud.h>
00056 #include <sensor_msgs/PointCloud2.h>
00057 #include <std_msgs/String.h>
00058 
00059 #include <diagnostic_updater/diagnostic_updater.h>
00060 #include <diagnostic_updater/publisher.h>
00061 #include <sick_scan/sick_scan_common_nw.h>
00062 
00063 
00064 #ifndef _MSC_VER
00065 #include <dynamic_reconfigure/server.h>
00066 #include <sick_scan/SickScanConfig.h>
00067 #endif
00068 #include "sick_scan/sick_generic_parser.h"
00069 #include "sick_scan/sick_scan_common_nw.h"
00070 
00071 void swap_endian(unsigned char *ptr, int numBytes);
00072 
00073 namespace sick_scan
00074 {
00075 
00076         class SickScanCommon
00077         {
00078         public:
00079                 enum SOPAS_CMD
00080                 {
00081                         CMD_DEVICE_IDENT_LEGACY,
00082                         CMD_DEVICE_IDENT,  // for MRS6124
00083                         CMD_SERIAL_NUMBER,
00084                         CMD_REBOOT,
00085                         CMD_WRITE_EEPROM,
00086                         CMD_FIRMWARE_VERSION,
00087                         CMD_DEVICE_STATE,
00088                         CMD_OPERATION_HOURS,
00089                         CMD_POWER_ON_COUNT,
00090                         CMD_LOCATION_NAME,
00091                         CMD_ACTIVATE_STANDBY,
00092                         CMD_SET_PARTICLE_FILTER,
00093                         CMD_SET_MEAN_FILTER,
00094                         CMD_ALIGNMENT_MODE,
00095                         CMD_APPLICATION_MODE,
00096       CMD_APPLICATION_MODE_FIELD_ON,
00097                         CMD_APPLICATION_MODE_FIELD_OFF,
00098                         CMD_APPLICATION_MODE_RANGING_ON,
00099                         CMD_SET_ACCESS_MODE_3,
00100                         CMD_SET_OUTPUT_RANGES,
00101                         CMD_GET_OUTPUT_RANGES,
00102                         CMD_RUN,
00103                         CMD_SET_PARTIAL_SCAN_CFG,
00104                         CMD_GET_PARTIAL_SCAN_CFG,
00105                         CMD_GET_PARTIAL_SCANDATA_CFG,
00106                         CMD_SET_PARTIAL_SCANDATA_CFG,
00107                         CMD_STOP_SCANDATA,
00108                         CMD_START_SCANDATA,
00109                         CMD_START_RADARDATA,
00110       CMD_ACTIVATE_NTP_CLIENT,
00111                         CMD_SET_NTP_INTERFACE_ETH,
00112 
00113       CMD_START_IMU_DATA, // start of IMU data
00114       CMD_STOP_IMU_DATA, // start of IMU data
00115 
00116         // start of radar specific commands
00117                         CMD_SET_TRANSMIT_RAWTARGETS_ON,  // transmit raw target for radar
00118                 CMD_SET_TRANSMIT_RAWTARGETS_OFF, // do not transmit raw target for radar
00119 
00120       CMD_SET_TRANSMIT_OBJECTS_ON,  // transmit raw target for radar
00121       CMD_SET_TRANSMIT_OBJECTS_OFF, // do not transmit raw target for radar
00122 
00123                         CMD_SET_TRACKING_MODE_0,  // set radar tracking mode to "BASIC"
00124                         CMD_SET_TRACKING_MODE_1,  // set radar tracking mode to "TRAFFIC"
00125 
00126       CMD_LOAD_APPLICATION_DEFAULT, // load application default
00127       CMD_DEVICE_TYPE,
00128       CMD_ORDER_NUMBER,
00129       // end of radar specific commands
00130                         CMD_START_MEASUREMENT,
00131                         CMD_STOP_MEASUREMENT,
00132                         CMD_SET_ECHO_FILTER,
00133       CMD_SET_NTP_UPDATETIME,
00134                         CMD_SET_NTP_TIMEZONE,
00135             CMD_SET_IP_ADDR,
00136             CMD_SET_GATEWAY,
00137                         CMD_SET_NTP_SERVER_IP_ADDR,
00138                         CMD_SET_TO_COLA_A_PROTOCOL,  //         sWN EIHstCola 1  // Cola B      sWN EIHstCola 0  // Cola A 
00139                         CMD_SET_TO_COLA_B_PROTOCOL,  // 
00140                         // ML: Add above new CMD-Identifier
00141                         //
00142                         //
00143                         CMD_END // CMD_END is a tag for end of enum - never (re-)move it. It must be the last element.
00144                 };
00145 // --- START KEYWORD DEFINITIONS ---
00146 #define PARAM_MIN_ANG "min_ang"
00147 #define PARAM_MAX_ANG "max_ang"
00148 #define PARAM_RES_ANG "res_ang"
00149 // --- END KEYWORD DEFINITIONS ---
00150 
00151 
00152                 SickScanCommon(SickGenericParser* parser);
00153                 virtual ~SickScanCommon();
00154 
00155                 int setParticleFilter(bool _active, int _particleThreshold);//actualy only 500 mm is working.
00161                 std::string generateExpectedAnswerString(const std::vector<unsigned char> requestStr);
00162                 int sendSopasAndCheckAnswer(std::string request, std::vector<unsigned char> *reply, int cmdId);
00163                 int sendSopasAndCheckAnswer(std::vector<unsigned char> request, std::vector<unsigned char> *reply, int cmdId);
00164 
00165                 int setAligmentMode(int _AligmentMode);
00166                 int setMeanFilter(bool _active, int _numberOfScans);
00167                 int setApplicationMode(bool _active, int _mode); //0=RANG (Ranging) 1=FEVL (Field Application).
00168                 int ActivateStandBy(void);
00169                 bool testSettingIpAddress();
00170                 bool testsetParticleFilter();
00171                 bool testsetMeanFilter();
00172                 bool testsetAligmentMode();
00173                 bool testsetActivateStandBy();
00174                 bool testsetApplicationMode();
00175                 int getReadTimeOutInMs();
00176                 void setReadTimeOutInMs(int timeOutInMs);
00177                 int getProtocolType(void);
00178                 void setProtocolType(SopasProtocol cola_dialect_id);
00179                 virtual int init();
00180                 int loopOnce();
00181                 void check_angle_range(SickScanConfig &conf);
00182                 void update_config(sick_scan::SickScanConfig &new_config, uint32_t level = 0);
00183 
00184                 double get_expected_frequency() const { return expectedFrequency_; }
00185                 int convertAscii2BinaryCmd(const char *requestAscii, std::vector<unsigned char>* requestBinary);
00186                 int init_cmdTables();
00187 
00189 
00192                 virtual bool rebootScanner();
00193 
00195 
00199                 bool changeIPandreboot(boost::asio::ip::address_v4 IpAdress);
00200 
00201                 SickScanCommonNw m_nw;
00202 
00203                 SickScanConfig* getConfigPtr()
00204                 {
00205                         return(&config_);
00206                 }
00207 
00208                 // move back to private
00209                                 /* FÜR MRS10000 brauchen wir einen Publish und eine NAchricht */
00210                                 // Should we publish laser or point cloud?
00211                                 // ros::Publisher cloud_pub_;
00212                                 ros::Publisher cloud_pub_;
00213                                 ros::Publisher cloud_radar_rawtarget_pub_;
00214                                 ros::Publisher cloud_radar_track_pub_;
00215                                 ros::Publisher radarScan_pub_;
00216                                 ros::Publisher  imuScan_pub_;
00217                                 // sensor_msgs::PointCloud cloud_;
00218                                 sensor_msgs::PointCloud2 cloud_;
00220                 // Dynamic Reconfigure
00221                 SickScanConfig config_;
00222                 protected:
00223                 virtual int init_device() = 0;
00224                 virtual int init_scanner();
00225                 virtual int stop_scanner();
00226                 virtual int close_device() = 0;
00227 
00229 
00234                 virtual int sendSOPASCommand(const char* request, std::vector<unsigned char> * reply, int cmdLen = -1) = 0;
00236 
00243                 virtual int get_datagram(ros::Time &recvTimeStamp, unsigned char *receiveBuffer, int bufferSize, int *actual_length,
00244                              bool isBinaryProtocol, int *numberOfRemainingFifoEntries) = 0;
00245 
00247 
00251                 std::string replyToString(const std::vector<unsigned char> &reply);
00257                 unsigned long convertBigEndianCharArrayToUnsignedLong(const unsigned char *vecArr);
00258 
00264                 int checkForBinaryAnswer(const std::vector<unsigned char>* reply);
00265 
00271                 bool isCompatibleDevice(const std::string identStr) const;
00272 
00273                 bool dumpDatagramForDebugging(unsigned char *buffer, int bufLen);
00274 
00275                 diagnostic_updater::Updater diagnostics_;
00276 
00277 
00278 
00279 
00280         private:
00281                 SopasProtocol m_protocolId;
00282                 // ROS
00283                 ros::NodeHandle nh_;
00284                 ros::Publisher pub_;
00285                 ros::Publisher datagram_pub_;
00286                 bool publish_datagram_;
00287 
00288 
00289                 // Diagnostics
00290                 diagnostic_updater::DiagnosedPublisher<sensor_msgs::LaserScan>* diagnosticPub_;
00291                 double expectedFrequency_;
00292 
00293 
00294 #ifndef _MSC_VER
00295                 dynamic_reconfigure::Server<sick_scan::SickScanConfig> dynamic_reconfigure_server_;
00296 #endif
00297                 // Parser
00298                 SickGenericParser* parser_;
00299                 std::vector<std::string> sopasCmdVec;
00300                 std::vector<std::string> sopasCmdMaskVec;
00301                 std::vector<std::string> sopasReplyVec;
00302                 std::vector<std::vector<unsigned char> > sopasReplyBinVec;
00303                 std::vector<std::string> sopasReplyStrVec;
00304                 std::vector<std::string> sopasCmdErrMsg;
00305                 std::vector<int> sopasCmdChain;
00306 
00307                 int  outputChannelFlagId;
00308                 bool checkForProtocolChangeAndMaybeReconnect(bool& useBinaryCmdNow);
00309                 void setSensorIsRadar(bool _isRadar);
00310                 bool getSensorIsRadar(void);
00311                 bool setNewIpAddress(boost::asio::ip::address_v4 ipNewIPAddr, bool useBinaryCmd);
00312                 bool setNTPServerAndStart(boost::asio::ip::address_v4 ipNewIPAddr, bool useBinaryCmd);
00313 
00314         int readTimeOutInMs;
00315 private:
00316         bool sensorIsRadar;
00317         };
00318 
00319 } /* namespace sick_scan */
00320 #endif /* SICK_TIM3XX_COMMON_H_ */


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Tue Jul 9 2019 05:05:35