00001 /* 00002 * Copyright (C) 2013, Osnabrück University 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of Osnabrück University nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 * 00029 * Created on: 24.05.2012 00030 * 00031 * Authors: 00032 * Jochen Sprickerhof <jochen@sprickerhof.de> 00033 * Martin Günther <mguenthe@uos.de> 00034 * 00035 * Based on the TiM communication example by SICK AG. 00036 * 00037 */ 00038 00039 #ifndef SICK_TIM3XX_COMMON_H_ 00040 #define SICK_TIM3XX_COMMON_H_ 00041 00042 #include <stdio.h> 00043 #include <stdlib.h> 00044 #include <string> 00045 #include <string.h> 00046 #include <vector> 00047 00048 #include <ros/ros.h> 00049 #include <sensor_msgs/LaserScan.h> 00050 #include <std_msgs/String.h> 00051 00052 #include <diagnostic_updater/diagnostic_updater.h> 00053 #include <diagnostic_updater/publisher.h> 00054 00055 #include <dynamic_reconfigure/server.h> 00056 #include <sick_tim/SickTimConfig.h> 00057 00058 #include "abstract_parser.h" 00059 00060 namespace sick_tim 00061 { 00062 00063 class SickTimCommon 00064 { 00065 public: 00066 SickTimCommon(AbstractParser* parser); 00067 virtual ~SickTimCommon(); 00068 virtual int init(); 00069 virtual int loopOnce(); 00070 void check_angle_range(SickTimConfig &conf); 00071 void update_config(sick_tim::SickTimConfig &new_config, uint32_t level = 0); 00072 00073 double get_expected_frequency() const { return expectedFrequency_; } 00074 00076 00079 virtual bool rebootScanner(); 00080 00081 protected: 00082 virtual int init_device() = 0; 00083 virtual int init_scanner(); 00084 virtual int stop_scanner(); 00085 virtual int close_device() = 0; 00086 00088 00092 virtual int sendSOPASCommand(const char* request, std::vector<unsigned char> * reply) = 0; 00093 00095 00100 virtual int get_datagram(unsigned char* receiveBuffer, int bufferSize, int* actual_length) = 0; 00101 00103 00107 static std::string replyToString(const std::vector<unsigned char> &reply); 00108 00109 bool isCompatibleDevice(const std::string identStr) const; 00110 00111 protected: 00112 diagnostic_updater::Updater diagnostics_; 00113 00114 // Dynamic Reconfigure 00115 SickTimConfig config_; 00116 bool publish_datagram_; 00117 ros::Publisher datagram_pub_; 00118 00119 // Diagnostics 00120 diagnostic_updater::DiagnosedPublisher<sensor_msgs::LaserScan>* diagnosticPub_; 00121 double expectedFrequency_; 00122 00123 private: 00124 // ROS 00125 ros::NodeHandle nh_; 00126 ros::Publisher pub_; 00127 00128 00129 dynamic_reconfigure::Server<sick_tim::SickTimConfig> dynamic_reconfigure_server_; 00130 00131 // Parser 00132 AbstractParser* parser_; 00133 }; 00134 00135 } /* namespace sick_tim */ 00136 #endif /* SICK_TIM3XX_COMMON_H_ */