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   struct AllTactileData
00248   {
00249     BiotacData biotac;
00250     PST3Data pst;
00251   };
00252 }
00253 
00254 /* For the emacs weenies in the crowd.
00255    Local Variables:
00256    c-basic-offset: 2
00257    End:
00258 */
00259 
00260 #endif


sr_hardware_interface
Author(s): Ugo Cupcic / ugo@shadowrobot.com
autogenerated on Fri Jan 3 2014 12:04:18