shadow_PSTs.cpp
Go to the documentation of this file.
00001 
00028 #include "sr_robot_lib/shadow_PSTs.hpp"
00029 #include <sr_utilities/sr_math_utils.hpp>
00030 #include <string>
00031 #include <vector>
00032 
00033 #define TACTILE_DATA_LENGTH_BYTES TACTILE_DATA_LENGTH_BYTES_v1
00034 
00035 namespace tactiles
00036 {
00037   template<class StatusType, class CommandType>
00038   ShadowPSTs<StatusType, CommandType>::ShadowPSTs(ros::NodeHandle nh, std::string device_id,
00039                                                   std::vector<generic_updater::UpdateConfig> update_configs_vector,
00040                                                   operation_mode::device_update_state::DeviceUpdateState update_state)
00041           : GenericTactiles<StatusType, CommandType>(nh, device_id, update_configs_vector, update_state)
00042   {
00043     init(update_configs_vector, update_state);
00044   }
00045 
00046   template<class StatusType, class CommandType>
00047   ShadowPSTs<StatusType,
00048           CommandType>::ShadowPSTs(ros::NodeHandle nh, std::string device_id,
00049                                    std::vector<generic_updater::UpdateConfig> update_configs_vector,
00050                                    operation_mode::device_update_state::DeviceUpdateState update_state,
00051                                    boost::shared_ptr<std::vector<GenericTactileData> > init_tactiles_vector)
00052           : GenericTactiles<StatusType, CommandType>(nh, device_id, update_configs_vector, update_state)
00053   {
00054     init(update_configs_vector, update_state);
00055     tactiles_vector->clear();
00056     for (unsigned int i = 0; i < this->nb_tactiles; i++)
00057     {
00058       PST3Data tmp_pst(init_tactiles_vector->at(i));
00059       tactiles_vector->push_back(tmp_pst);
00060     }
00061   }
00062 
00063   template<class StatusType, class CommandType>
00064   void ShadowPSTs<StatusType, CommandType>::init(std::vector<generic_updater::UpdateConfig> update_configs_vector,
00065                                                  operation_mode::device_update_state::DeviceUpdateState update_state)
00066   {
00067     // initialize the vector of tactiles
00068     tactiles_vector = boost::shared_ptr<std::vector<PST3Data> >(new std::vector<PST3Data>(this->nb_tactiles));
00069     this->all_tactile_data = boost::shared_ptr<std::vector<AllTactileData> >(
00070             new std::vector<AllTactileData>(this->nb_tactiles));
00071 
00072     for (size_t i = 0; i < this->all_tactile_data->size(); ++i)
00073     {
00074       this->all_tactile_data->at(i).type = "pst";
00075     }
00076   }
00077 
00078   template<class StatusType, class CommandType>
00079   void ShadowPSTs<StatusType, CommandType>::update(StatusType *status_data)
00080   {
00081     int tactile_mask = static_cast<int16u>(status_data->tactile_data_valid);
00082     // @todo use memcopy instead?
00083     for (unsigned int id_sensor = 0; id_sensor < this->nb_tactiles; ++id_sensor)
00084     {
00085       switch (static_cast<int32u>(status_data->tactile_data_type))
00086       {
00087         // TACTILE DATA
00088         case TACTILE_SENSOR_TYPE_PST3_PRESSURE_TEMPERATURE:
00089           if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00090           {
00091             tactiles_vector->at(id_sensor).pressure =
00092                     static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
00093             tactiles_vector->at(id_sensor).temperature =
00094                     static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[1]));
00095             tactiles_vector->at(id_sensor).debug_1 =
00096                     static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[2]));
00097             tactiles_vector->at(id_sensor).debug_2 =
00098                     static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[3]));
00099           }
00100           break;
00101 
00102         case TACTILE_SENSOR_TYPE_PST3_PRESSURE_RAW_ZERO_TRACKING:
00103           if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00104           {
00105             tactiles_vector->at(id_sensor).pressure_raw =
00106                     static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
00107             tactiles_vector->at(id_sensor).zero_tracking =
00108                     static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[1]));
00109           }
00110           break;
00111 
00112         case TACTILE_SENSOR_TYPE_PST3_DAC_VALUE:
00113           if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00114           {
00115             tactiles_vector->at(id_sensor).dac_value =
00116                     static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
00117           }
00118           break;
00119 
00120           // COMMON DATA
00121         case TACTILE_SENSOR_TYPE_SAMPLE_FREQUENCY_HZ:
00122           if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00123           {
00124             tactiles_vector->at(id_sensor).sample_frequency =
00125                     static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
00126           }
00127           break;
00128 
00129         case TACTILE_SENSOR_TYPE_MANUFACTURER:
00130         {
00131           if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00132           {
00133             tactiles_vector->at(id_sensor).manufacturer = this->sanitise_string(status_data->tactile[id_sensor].string,
00134                                                                                 TACTILE_DATA_LENGTH_BYTES);
00135           }
00136         }
00137           break;
00138 
00139         case TACTILE_SENSOR_TYPE_SERIAL_NUMBER:
00140         {
00141           if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00142           {
00143             tactiles_vector->at(id_sensor).serial_number = this->sanitise_string(status_data->tactile[id_sensor].string,
00144                                                                                  TACTILE_DATA_LENGTH_BYTES);
00145           }
00146         }
00147           break;
00148 
00149         case TACTILE_SENSOR_TYPE_SOFTWARE_VERSION:
00150           if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00151           {
00152             tactiles_vector->at(id_sensor).set_software_version(status_data->tactile[id_sensor].string);
00153           }
00154           break;
00155 
00156         case TACTILE_SENSOR_TYPE_PCB_VERSION:
00157           if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00158           {
00159             tactiles_vector->at(id_sensor).pcb_version = this->sanitise_string(status_data->tactile[id_sensor].string,
00160                                                                                TACTILE_DATA_LENGTH_BYTES);
00161           }
00162           break;
00163 
00164         default:
00165           break;
00166       }  // end switch
00167     }  // end for tactile
00168 
00169     if (this->sensor_updater->update_state == operation_mode::device_update_state::INITIALIZATION)
00170     {
00171       this->process_received_data_type(static_cast<int32u>(status_data->tactile_data_type));
00172       if (this->sensor_updater->initialization_configs_vector.size() == 0)
00173       {
00174         this->sensor_updater->update_state = operation_mode::device_update_state::OPERATION;
00175       }
00176     }
00177   }
00178 
00179   template<class StatusType, class CommandType>
00180   void ShadowPSTs<StatusType, CommandType>::publish()
00181   {
00182     // left empty, this is published from the controller publisher
00183   }  // end publish
00184 
00185   template <class StatusType, class CommandType>
00186   void ShadowPSTs<StatusType, CommandType>::add_diagnostics(std::vector<diagnostic_msgs::DiagnosticStatus> &vec,
00187                                                             diagnostic_updater::DiagnosticStatusWrapper &d)
00188   {
00189     for (unsigned int id_tact = 0; id_tact < this->nb_tactiles; ++id_tact)
00190     {
00191       std::stringstream ss;
00192       std::string prefix = this->device_id_.empty() ? this->device_id_ : (this->device_id_ + " ");
00193       ss << prefix << "Tactile " << id_tact + 1;
00194 
00195       d.name = ss.str().c_str();
00196       d.summary(d.OK, "OK");
00197       d.clear();
00198 
00199       d.addf("Sample Frequency", "%d", tactiles_vector->at(id_tact).sample_frequency);
00200       d.addf("Manufacturer", "%s", tactiles_vector->at(id_tact).manufacturer.c_str());
00201       d.addf("Serial Number", "%s", tactiles_vector->at(id_tact).serial_number.c_str());
00202 
00203       d.addf("Software Version", "%s", tactiles_vector->at(id_tact).get_software_version().c_str());
00204       d.addf("PCB Version", "%s", tactiles_vector->at(id_tact).pcb_version.c_str());
00205 
00206       d.addf("Pressure Raw", "%d", tactiles_vector->at(id_tact).pressure_raw);
00207       d.addf("Zero Tracking", "%d", tactiles_vector->at(id_tact).zero_tracking);
00208       d.addf("DAC Value", "%d", tactiles_vector->at(id_tact).dac_value);
00209 
00210       vec.push_back(d);
00211     }
00212   }
00213 
00214   template<class StatusType, class CommandType>
00215   std::vector<AllTactileData> *ShadowPSTs<StatusType, CommandType>::get_tactile_data()
00216   {
00217     for (unsigned int i = 0; i < tactiles_vector->size(); ++i)
00218     {
00219       this->all_tactile_data->at(i).pst = tactiles_vector->at(i);
00220     }
00221 
00222     return this->all_tactile_data.get();
00223   }
00224 
00225   // Only to ensure that the template class is compiled for the types we are interested in
00226   template
00227   class ShadowPSTs<ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_STATUS, ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_COMMAND>;
00228 
00229   template
00230   class ShadowPSTs<ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_STATUS, ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND>;
00231 
00232   template
00233   class ShadowPSTs<ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_STATUS, ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND>;
00234 }  // namespace tactiles
00235 
00236 /* For the emacs weenies in the crowd.
00237    Local Variables:
00238    c-basic-offset: 2
00239    End:
00240 */


sr_robot_lib
Author(s): Ugo Cupcic, Toni Oliver
autogenerated on Mon Jul 1 2019 20:06:26