evarobot_sonar.h
Go to the documentation of this file.
00001 #ifndef INCLUDE_EVAROBOT_SONAR_H_
00002 #define INCLUDE_EVAROBOT_SONAR_H_
00003 
00004 #include "ros/ros.h"
00005 #include "sensor_msgs/Range.h"
00006 
00007 #include <diagnostic_updater/diagnostic_updater.h>
00008 #include <diagnostic_updater/publisher.h>
00009 
00010 #include <dynamic_reconfigure/server.h>
00011 #include <evarobot_sonar/SonarParamsConfig.h>
00012 
00013 #include <time.h>
00014 #include <vector>
00015 #include <sstream>
00016 
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 #include <fcntl.h>
00020 #include <math.h>
00021 
00022 #include <unistd.h>             /* exit */
00023 #include <sys/ioctl.h>          /* ioctl */
00024 #include <exception>
00025 
00026 #include <boost/shared_ptr.hpp>
00027 
00028 #include <ros/console.h>
00029 #include "ErrorCodes.h"
00030 
00031 // In order to change max number of sonar, MAX_SONAR macros 
00032 // in evarobot_sonar.cpp(ROS) and driver_sonar.h(MODULE)
00033 // should be modified.
00034 
00035 #define MAX_TRIGGER_TIME 1.2
00036 #define MAX_SONAR 7
00037 
00038 struct sonar_ioc_transfer 
00039 {
00040         int i_gpio_pin;
00041         int i_sonar_id;
00042 };
00043 
00044 struct sonar_data
00045 {
00046         int i_sonar_id;
00047         int i_distance;
00048 };
00049 
00050 #define SNRDRIVER_IOCTL_BASE 0xAE
00051 
00052 /* Set param macro*/
00053 #define IOCTL_SET_PARAM _IOW(SNRDRIVER_IOCTL_BASE, 0, struct sonar_ioc_transfer) 
00054 /* Read range macro*/
00055 #define IOCTL_READ_RANGE _IOWR(SNRDRIVER_IOCTL_BASE, 1, struct sonar_data) 
00056 
00057 
00058 int SONAR[] = {23, 24, 25, 26, 16, 20, 21};
00059 bool b_is_received_params = false;
00060 
00061 double g_d_field_of_view;
00062 double g_d_min_range;
00063 double g_d_max_range;
00064 bool g_b_always_on;
00065 
00066 int g_i_is_alive[MAX_SONAR];
00067 
00068 using namespace std;
00069 
00070 class IMDynamicReconfig
00071 {
00072         public:
00073         IMDynamicReconfig();
00074         
00075         void CallbackReconfigure(evarobot_sonar::SonarParamsConfig &config, uint32_t level);
00076         
00077         ros::NodeHandle n_private;
00078         
00079         double d_min_range, d_max_range, d_fov;
00080         double d_max_freq, d_min_freq;
00081         bool b_always_on;
00082                 
00083         dynamic_reconfigure::Server<evarobot_sonar::SonarParamsConfig> srv;
00084         dynamic_reconfigure::Server<evarobot_sonar::SonarParamsConfig>::CallbackType f;
00085 };
00086 
00087 class IMSONAR
00088 {
00089         public:
00090         
00091         IMSONAR(int fd, 
00092                                  int id, 
00093                                  int pin,
00094                                  boost::shared_ptr<IMDynamicReconfig> _dynamic_params);
00095         ~IMSONAR();
00096         void Trigger();
00097         void Wait();
00098         int Echo();
00099 
00100         bool Check();
00101         void Publish();
00102         void ProduceDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat);
00103         
00104         ros::NodeHandle n;
00105         ros::Publisher pub_sonar;
00106         diagnostic_updater::Updater updater;
00107         
00108         private:
00109         int i_fd;
00110         int i_pin_no, i_id;
00111         bool b_is_alive;
00112         
00113         sensor_msgs::Range sonar_msg;
00114         
00115         boost::shared_ptr<IMDynamicReconfig> dynamic_params;
00116         
00117         double min_freq;
00118         double max_freq;
00119         diagnostic_updater::HeaderlessTopicDiagnostic * pub_sonar_freq;
00120 
00121         
00122         struct sonar_data data;
00123 };
00124 
00125 
00126 #endif


evarobot_sonar
Author(s): Mehmet Akcakoca
autogenerated on Fri Feb 12 2016 01:15:30