00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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,
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,
00114 CMD_STOP_IMU_DATA,
00115
00116
00117 CMD_SET_TRANSMIT_RAWTARGETS_ON,
00118 CMD_SET_TRANSMIT_RAWTARGETS_OFF,
00119
00120 CMD_SET_TRANSMIT_OBJECTS_ON,
00121 CMD_SET_TRANSMIT_OBJECTS_OFF,
00122
00123 CMD_SET_TRACKING_MODE_0,
00124 CMD_SET_TRACKING_MODE_1,
00125
00126 CMD_LOAD_APPLICATION_DEFAULT,
00127 CMD_DEVICE_TYPE,
00128 CMD_ORDER_NUMBER,
00129
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,
00139 CMD_SET_TO_COLA_B_PROTOCOL,
00140
00141
00142
00143 CMD_END
00144 };
00145
00146 #define PARAM_MIN_ANG "min_ang"
00147 #define PARAM_MAX_ANG "max_ang"
00148 #define PARAM_RES_ANG "res_ang"
00149
00150
00151
00152 SickScanCommon(SickGenericParser* parser);
00153 virtual ~SickScanCommon();
00154
00155 int setParticleFilter(bool _active, int _particleThreshold);
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);
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
00209
00210
00211
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
00218 sensor_msgs::PointCloud2 cloud_;
00220
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
00283 ros::NodeHandle nh_;
00284 ros::Publisher pub_;
00285 ros::Publisher datagram_pub_;
00286 bool publish_datagram_;
00287
00288
00289
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
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 }
00320 #endif