tactile_sensors.hpp
Go to the documentation of this file.
00001 
00027 #ifndef _TACTILE_SENSORS_HPP_
00028 #define _TACTILE_SENSORS_HPP_
00029 
00030 #include <string>
00031 #include <vector>
00032 
00033 #include <boost/array.hpp>
00034 #include <boost/algorithm/string.hpp>
00035 #include <boost/algorithm/string/find_iterator.hpp>
00036 #include <sstream>
00037 
00038 #include <ros/ros.h>
00039 
00040 namespace tactiles
00041 {
00042   class GenericTactileData
00043   {
00044   public:
00045     GenericTactileData() {};
00046 
00047     GenericTactileData(bool tactile_data_valid, int sample_frequency,
00048                        std::string manufacturer, std::string serial_number,
00049                        int software_version_current, int software_version_server,
00050                        bool software_version_modified, std::string pcb_version)
00051       : tactile_data_valid(tactile_data_valid), sample_frequency(sample_frequency),
00052         manufacturer(manufacturer), serial_number(serial_number),
00053         software_version_current(software_version_current),
00054         software_version_server(software_version_server),
00055         software_version_modified(software_version_modified),
00056         pcb_version(pcb_version)
00057     {};
00058 
00059     ~GenericTactileData() {};
00060 
00061     bool tactile_data_valid;
00062 
00063     int which_sensor;
00064     int sample_frequency;
00065     std::string manufacturer;
00066     std::string serial_number;
00067 
00068     int software_version_current;
00069     int software_version_server;
00070     bool software_version_modified;
00071 
00079     void set_software_version( std::string version )
00080     {
00081       //split the string to fill the different versions
00082       std::vector<std::string> splitted_string;
00083       boost::split(splitted_string, version, boost::is_any_of("\n"));
00084 
00085       ROS_DEBUG("Tactile version: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", static_cast<unsigned char>(version[0]), static_cast<unsigned char>(version[1]), static_cast<unsigned char>(version[2]), static_cast<unsigned char>(version[3]), static_cast<unsigned char>(version[4]), static_cast<unsigned char>(version[5]), static_cast<unsigned char>(version[6]), static_cast<unsigned char>(version[7]), static_cast<unsigned char>(version[8]), static_cast<unsigned char>(version[9]), static_cast<unsigned char>(version[10]), static_cast<unsigned char>(version[11]), static_cast<unsigned char>(version[12]), static_cast<unsigned char>(version[13]), static_cast<unsigned char>(version[14]), static_cast<unsigned char>(version[15]));
00086       if (splitted_string.size() >= 3)
00087       {
00088           software_version_current = convertToInt(splitted_string[0]);
00089           software_version_server = convertToInt(splitted_string[1]);
00090 
00091           if( splitted_string[2] == "No")
00092             software_version_modified = false;
00093           else
00094             software_version_modified = true;
00095       }
00096       else
00097       {
00098           ROS_ERROR("Incorrect tactile sensor version format");
00099           software_version_current = 0;
00100           software_version_server = 0;
00101           software_version_modified = false;
00102       }
00103     };
00104 
00111     virtual std::string get_software_version()
00112     {
00113       //concatenate versions in a string.
00114       std::string full_version;
00115 
00116       std::stringstream ss;
00117       if( software_version_modified )
00118         ss << "current: " << software_version_current << " / server: " << software_version_server << " / MODIFIED";
00119       else
00120         ss << "current: " << software_version_current << " / server: " << software_version_server << " / not modified";
00121 
00122       full_version = ss.str();
00123 
00124       return full_version;
00125     };
00126 
00127     std::string pcb_version;
00128 
00129     inline double convertToInt(std::string const& s)
00130     {
00131       std::istringstream i(s);
00132       int x;
00133       if (!(i >> x))
00134         x = -1;
00135       return x;
00136     }
00137   };
00138 
00139   class PST3Data
00140     : public GenericTactileData
00141   {
00142   public:
00143     PST3Data()
00144       : GenericTactileData()
00145     {};
00146 
00147     PST3Data(const PST3Data& pst3)
00148       : GenericTactileData(pst3.tactile_data_valid, pst3.sample_frequency,
00149                            pst3.manufacturer, pst3.serial_number,
00150                            pst3.software_version_current,
00151                            pst3.software_version_server,
00152                            pst3.software_version_modified,
00153                            pst3.pcb_version),
00154         pressure(pst3.pressure), temperature(pst3.temperature),
00155         debug_1(pst3.debug_1), debug_2(pst3.debug_2),
00156         pressure_raw(pst3.pressure_raw), zero_tracking(pst3.zero_tracking), dac_value(pst3.dac_value)
00157     {};
00158 
00159 
00160     PST3Data(const GenericTactileData& gtd)
00161       : GenericTactileData(gtd.tactile_data_valid, gtd.sample_frequency,
00162                            gtd.manufacturer, gtd.serial_number,
00163                            gtd.software_version_current,
00164                            gtd.software_version_server,
00165                            gtd.software_version_modified,
00166                            gtd.pcb_version)
00167     {};
00168 
00169     ~PST3Data() {};
00170     int pressure;
00171     int temperature;
00172 
00173     int debug_1;
00174     int debug_2;
00175 
00176     int pressure_raw;
00177     int zero_tracking;
00178 
00179     int dac_value;
00180 
00187     virtual std::string get_software_version()
00188     {
00189       //concatenate versions in a string.
00190       std::string full_version;
00191 
00192       std::stringstream ss;
00193       ss << "current: " << software_version_current;
00194 
00195       full_version = ss.str();
00196 
00197       return full_version;
00198     };
00199   };
00200 
00201   class BiotacData
00202     : public GenericTactileData
00203   {
00204   public:
00205     BiotacData()
00206       : GenericTactileData()
00207     {};
00208 
00209     BiotacData(const BiotacData& btac)
00210       : GenericTactileData(btac.tactile_data_valid, btac.sample_frequency,
00211                            btac.manufacturer, btac.serial_number,
00212                            btac.software_version_current,
00213                            btac.software_version_server,
00214                            btac.software_version_modified,
00215                            btac.pcb_version),
00216         pac0(btac.pac0), pac1(btac.pac1),
00217         pdc(btac.pdc), tac(btac.tac),
00218         tdc(btac.tdc)
00219     {
00220       for(unsigned int i =0; i<btac.electrodes.size() ;i++)
00221       {
00222         electrodes[i] = btac.electrodes[i];
00223       }
00224     };
00225 
00226     BiotacData(const GenericTactileData& gtd)
00227       : GenericTactileData(gtd.tactile_data_valid, gtd.sample_frequency,
00228                            gtd.manufacturer, gtd.serial_number,
00229                            gtd.software_version_current,
00230                            gtd.software_version_server,
00231                            gtd.software_version_modified,
00232                            gtd.pcb_version)
00233     {};
00234 
00235     ~BiotacData() {};
00236 
00237     int pac0; //always there, in word[0] and 1; int16u (2kHz)
00238     int pac1; //int16u
00239 
00240     int pdc; //int16u in word[2]
00241 
00242     int tac; //int16u in word[2]
00243     int tdc; //int16u in word[2]
00244     boost::array<short int, 19ul> electrodes; //int16u in word[2]
00245   };
00246 
00247   class UBI0Data
00248     : public GenericTactileData
00249   {
00250   public:
00251     UBI0Data()
00252       : GenericTactileData()
00253     {};
00254 
00255     UBI0Data(const UBI0Data& ubi0)
00256       : GenericTactileData(ubi0.tactile_data_valid, ubi0.sample_frequency,
00257                            ubi0.manufacturer, ubi0.serial_number,
00258                            ubi0.software_version_current,
00259                            ubi0.software_version_server,
00260                            ubi0.software_version_modified,
00261                            ubi0.pcb_version)
00262     {
00263       for(unsigned int i =0; i<ubi0.distal.size() ;i++)
00264       {
00265         distal[i] = ubi0.distal[i];
00266       }
00267       for(unsigned int i =0; i<ubi0.middle.size() ;i++)
00268       {
00269         middle[i] = ubi0.middle[i];
00270       }
00271       for(unsigned int i =0; i<ubi0.proximal.size() ;i++)
00272       {
00273         proximal[i] = ubi0.proximal[i];
00274       }
00275     };
00276 
00277     UBI0Data(const GenericTactileData& gtd)
00278       : GenericTactileData(gtd.tactile_data_valid, gtd.sample_frequency,
00279                            gtd.manufacturer, gtd.serial_number,
00280                            gtd.software_version_current,
00281                            gtd.software_version_server,
00282                            gtd.software_version_modified,
00283                            gtd.pcb_version)
00284     {};
00285 
00286     ~UBI0Data() {};
00287 
00288 
00289     boost::array<unsigned short int, 12ul> distal;
00290     boost::array<unsigned short int, 4ul> middle;
00291     boost::array<unsigned short int, 4ul> proximal;
00292   };
00293 
00294   class UBI0PalmData
00295   {
00296   public:
00297     UBI0PalmData()
00298     {};
00299 
00300     UBI0PalmData(const UBI0PalmData& ubi0)
00301     {
00302       for(unsigned int i =0; i<ubi0.palm.size() ;i++)
00303       {
00304         palm[i] = ubi0.palm[i];
00305       }
00306     };
00307 
00308     ~UBI0PalmData() {};
00309 
00310     boost::array<unsigned short int, 16ul> palm;
00311   };
00312 
00313   struct AllTactileData
00314   {
00315     BiotacData biotac;
00316     PST3Data pst;
00317     UBI0Data ubi0;
00318   };
00319 }
00320 
00321 /* For the emacs weenies in the crowd.
00322    Local Variables:
00323    c-basic-offset: 2
00324    End:
00325 */
00326 
00327 #endif


sr_hardware_interface
Author(s): Ugo Cupcic / ugo@shadowrobot.com
autogenerated on Mon Oct 6 2014 07:46:07