os32c.h
Go to the documentation of this file.
00001 
00026 #ifndef OMRON_OS32C_DRIVER_OS32C_H
00027 #define OMRON_OS32C_DRIVER_OS32C_H
00028 
00029 #include <gtest/gtest_prod.h>
00030 #include <string>
00031 #include <vector>
00032 #include <boost/shared_ptr.hpp>
00033 #include <sensor_msgs/LaserScan.h>
00034 
00035 #include "odva_ethernetip/session.h"
00036 #include "odva_ethernetip/socket/socket.h"
00037 #include "omron_os32c_driver/measurement_report.h"
00038 #include "omron_os32c_driver/measurement_report_config.h"
00039 #include "omron_os32c_driver/range_and_reflectance_measurement.h"
00040 
00041 using std::vector;
00042 using boost::shared_ptr;
00043 using sensor_msgs::LaserScan;
00044 using eip::Session;
00045 using eip::socket::Socket;
00046 
00047 #define DEG2RAD(a) (a * M_PI / 180)
00048 #define RAD2DEG(a) (a * 180 / M_PI)
00049 
00050 namespace omron_os32c_driver {
00051 
00052 
00053 typedef enum
00054 {
00055   NO_TOF_MEASUREMENTS       = 0,
00056   RANGE_MEASURE_50M         = 1,
00057   RANGE_MEASURE_32M_PZ      = 2,
00058   RANGE_MEASURE_16M_WZ1PZ   = 3,
00059   RANGE_MEASURE_8M_WZ2WZ1PZ = 4,
00060   RANGE_MEASURE_TOF_4PS     = 5,
00061 } OS32C_RANGE_FORMAT;
00062 
00063 typedef enum
00064 {
00065   NO_TOT_MEASUREMENTS               = 0,
00066   REFLECTIVITY_MEASURE_TOT_ENCODED  = 1,
00067   REFLECTIVITY_MEASURE_TOT_4PS      = 2,
00068 } OS32C_REFLECTIVITY_FORMAT;
00069 
00075 class OS32C : public Session
00076 {
00077 public:
00082   OS32C(shared_ptr<Socket> socket, shared_ptr<Socket> io_socket)
00083     : Session(socket, io_socket), start_angle_(ANGLE_MAX), end_angle_(ANGLE_MIN),
00084       connection_num_(-1), mrc_sequence_num_(1)
00085   {
00086   }
00087 
00088   static const double ANGLE_MIN;
00089   static const double ANGLE_MAX;
00090   static const double ANGLE_INC;
00091   static const double DISTANCE_MIN;
00092   static const double DISTANCE_MAX;
00093 
00100   EIP_UINT getRangeFormat();
00101 
00108   void setRangeFormat(EIP_UINT format);
00109 
00116   EIP_UINT getReflectivityFormat();
00117 
00124   void setReflectivityFormat(EIP_UINT format);
00125 
00126 
00134   void selectBeams(double start_angle, double end_angle);
00135 
00141   RangeAndReflectanceMeasurement getSingleRRScan();
00142 
00154   static inline int calcBeamNumber(double angle)
00155   {
00156     return (ANGLE_MAX - angle + ANGLE_INC / 2) / ANGLE_INC;
00157   }
00158 
00165   static inline double calcBeamCentre(int beam_num)
00166   {
00167     return ANGLE_MAX - beam_num * ANGLE_INC;
00168   }
00169 
00175   void fillLaserScanStaticConfig(sensor_msgs::LaserScan* ls);
00176 
00184   static void convertToLaserScan(const RangeAndReflectanceMeasurement& rr, sensor_msgs::LaserScan* ls);
00185 
00191   static void convertToLaserScan(const MeasurementReport& mr, sensor_msgs::LaserScan* ls);
00192 
00193   void sendMeasurmentReportConfigUDP();
00194 
00195   MeasurementReport receiveMeasurementReportUDP();
00196 
00197   void startUDPIO();
00198 
00199 private:
00200   // allow unit tests to access the helpers below for direct testing
00201   FRIEND_TEST(OS32CTest, test_calc_beam_mask_all);
00202   FRIEND_TEST(OS32CTest, test_calc_beam_at_90);
00203   FRIEND_TEST(OS32CTest, test_calc_beam_boundaries);
00204   FRIEND_TEST(OS32CTest, test_calc_beam_invalid_args);
00205   FRIEND_TEST(OS32CTest, test_convert_to_laserscan);
00206 
00207   double start_angle_;
00208   double end_angle_;
00209 
00210   // data for sending to lidar to keep UDP session alive
00211   int connection_num_;
00212   MeasurementReportConfig mrc_;
00213   EIP_UDINT mrc_sequence_num_;
00214 
00221   void calcBeamMask(double start_angle, double end_angle, EIP_BYTE mask[]);
00222 };
00223 
00224 } // namespace omron_os32c_driver
00225 
00226 #endif  // OMRON_OS32C_DRIVER_OS32C_H


omron_os32c_driver
Author(s): Kareem Shehata
autogenerated on Thu Jun 6 2019 19:00:54