00001
00028 #include "sr_robot_lib/biotac.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
00038 template <class StatusType, class CommandType>
00039 const size_t Biotac<StatusType, CommandType>::nb_electrodes_v1_ = 19;
00040
00041 template <class StatusType, class CommandType>
00042 const size_t Biotac<StatusType, CommandType>::nb_electrodes_v2_ = 24;
00043
00044 template<class StatusType, class CommandType>
00045 Biotac<StatusType, CommandType>::Biotac(ros::NodeHandle nh, std::string device_id,
00046 std::vector<generic_updater::UpdateConfig> update_configs_vector,
00047 operation_mode::device_update_state::DeviceUpdateState update_state)
00048 : GenericTactiles<StatusType, CommandType>(nh, device_id, update_configs_vector, update_state)
00049 {
00050 init(update_configs_vector, update_state);
00051 }
00052
00053 template<class StatusType, class CommandType>
00054 Biotac<StatusType, CommandType>::Biotac(ros::NodeHandle nh, std::string device_id,
00055 std::vector<generic_updater::UpdateConfig> update_configs_vector,
00056 operation_mode::device_update_state::DeviceUpdateState update_state,
00057 boost::shared_ptr<std::vector<GenericTactileData> > init_tactiles_vector)
00058 : GenericTactiles<StatusType, CommandType>(nh, device_id, update_configs_vector, update_state)
00059 {
00060 init(update_configs_vector, update_state);
00061 tactiles_vector->clear();
00062 for (unsigned int i = 0; i < this->nb_tactiles; i++)
00063 {
00064 BiotacData tmp_pst(init_tactiles_vector->at(i));
00065 tactiles_vector->push_back(tmp_pst);
00066 }
00067
00068 set_version_specific_details();
00069 }
00070
00071 template<class StatusType, class CommandType>
00072 void Biotac<StatusType, CommandType>::init(std::vector<generic_updater::UpdateConfig> update_configs_vector,
00073 operation_mode::device_update_state::DeviceUpdateState update_state)
00074 {
00075
00076 tactiles_vector = boost::shared_ptr<std::vector<BiotacData> >(new std::vector<BiotacData>(this->nb_tactiles));
00077 this->all_tactile_data = boost::shared_ptr<std::vector<AllTactileData> >(
00078 new std::vector<AllTactileData>(this->nb_tactiles));
00079
00080 for (size_t i = 0; i < this->all_tactile_data->size(); ++i)
00081 {
00082 this->all_tactile_data->at(i).type = "biotac";
00083 }
00084 }
00085
00086 template<class StatusType, class CommandType>
00087 void Biotac<StatusType, CommandType>::update(StatusType *status_data)
00088 {
00089 int tactile_mask = static_cast<int16u>(status_data->tactile_data_valid);
00090
00091 for (unsigned int id_sensor = 0; id_sensor < this->nb_tactiles; ++id_sensor)
00092 {
00093 TACTILE_SENSOR_BIOTAC_DATA_CONTENTS *tactile_data =
00094 reinterpret_cast<TACTILE_SENSOR_BIOTAC_DATA_CONTENTS*> (&(status_data->tactile[id_sensor]));
00095
00096 tactiles_vector->at(id_sensor).pac0 = static_cast<int>(tactile_data->Pac[0]);
00097 tactiles_vector->at(id_sensor).pac1 = static_cast<int>(tactile_data->Pac[1]);
00098
00099
00100 switch (static_cast<int32u>(status_data->tactile_data_type))
00101 {
00102
00103 case TACTILE_SENSOR_TYPE_BIOTAC_INVALID:
00104 ROS_WARN("received invalid tactile type");
00105 break;
00106
00107 case TACTILE_SENSOR_TYPE_BIOTAC_PDC:
00108 if (tactile_data->data_valid.other_sensor_0)
00109 {
00110 tactiles_vector->at(id_sensor).pdc = static_cast<int>(tactile_data->other_sensor_0);
00111 }
00112 else
00113 {
00114
00115 }
00116 if (tactile_data->data_valid.other_sensor_1)
00117 {
00118 tactiles_vector->at(id_sensor).tac = static_cast<int>(tactile_data->other_sensor_1);
00119 }
00120 break;
00121
00122
00123
00124
00125
00126
00127 case TACTILE_SENSOR_TYPE_BIOTAC_TDC:
00128 if (tactile_data->data_valid.other_sensor_0)
00129 {
00130 tactiles_vector->at(id_sensor).tdc = static_cast<int>(tactile_data->other_sensor_0);
00131 }
00132 if (tactile_data->data_valid.other_sensor_1)
00133 {
00134 tactiles_vector->at(id_sensor).electrodes[0] = static_cast<int>(tactile_data->other_sensor_1);
00135 }
00136 break;
00137
00138
00139
00140
00141
00142
00143 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_2:
00144 if (tactile_data->data_valid.other_sensor_0)
00145 {
00146 tactiles_vector->at(id_sensor).electrodes[1] = static_cast<int>(tactile_data->other_sensor_0);
00147 }
00148 if (tactile_data->data_valid.other_sensor_1)
00149 {
00150 tactiles_vector->at(id_sensor).electrodes[2] = static_cast<int>(tactile_data->other_sensor_1);
00151 }
00152 break;
00153
00154
00155
00156
00157
00158
00159 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_4:
00160 if (tactile_data->data_valid.other_sensor_0)
00161 {
00162 tactiles_vector->at(id_sensor).electrodes[3] = static_cast<int>(tactile_data->other_sensor_0);
00163 }
00164 if (tactile_data->data_valid.other_sensor_1)
00165 {
00166 tactiles_vector->at(id_sensor).electrodes[4] = static_cast<int>(tactile_data->other_sensor_1);
00167 }
00168 break;
00169
00170
00171
00172
00173
00174
00175 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_6:
00176 if (tactile_data->data_valid.other_sensor_0)
00177 {
00178 tactiles_vector->at(id_sensor).electrodes[5] = static_cast<int>(tactile_data->other_sensor_0);
00179 }
00180 if (tactile_data->data_valid.other_sensor_1)
00181 {
00182 tactiles_vector->at(id_sensor).electrodes[6] = static_cast<int>(tactile_data->other_sensor_1);
00183 }
00184 break;
00185
00186
00187
00188
00189
00190
00191 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_8:
00192 if (tactile_data->data_valid.other_sensor_0)
00193 {
00194 tactiles_vector->at(id_sensor).electrodes[7] = static_cast<int>(tactile_data->other_sensor_0);
00195 }
00196 if (tactile_data->data_valid.other_sensor_1)
00197 {
00198 tactiles_vector->at(id_sensor).electrodes[8] = static_cast<int>(tactile_data->other_sensor_1);
00199 }
00200 break;
00201
00202
00203
00204
00205
00206
00207 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_10:
00208 if (tactile_data->data_valid.other_sensor_0)
00209 {
00210 tactiles_vector->at(id_sensor).electrodes[9] = static_cast<int>(tactile_data->other_sensor_0);
00211 }
00212 if (tactile_data->data_valid.other_sensor_1)
00213 {
00214 tactiles_vector->at(id_sensor).electrodes[10] = static_cast<int>(tactile_data->other_sensor_1);
00215 }
00216 break;
00217
00218
00219
00220
00221
00222
00223 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_12:
00224 if (tactile_data->data_valid.other_sensor_0)
00225 {
00226 tactiles_vector->at(id_sensor).electrodes[11] = static_cast<int>(tactile_data->other_sensor_0);
00227 }
00228 if (tactile_data->data_valid.other_sensor_1)
00229 {
00230 tactiles_vector->at(id_sensor).electrodes[12] = static_cast<int>(tactile_data->other_sensor_1);
00231 }
00232 break;
00233
00234
00235
00236
00237
00238
00239 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_14:
00240 if (tactile_data->data_valid.other_sensor_0)
00241 {
00242 tactiles_vector->at(id_sensor).electrodes[13] = static_cast<int>(tactile_data->other_sensor_0);
00243 }
00244 if (tactile_data->data_valid.other_sensor_1)
00245 {
00246 tactiles_vector->at(id_sensor).electrodes[14] = static_cast<int>(tactile_data->other_sensor_1);
00247 }
00248 break;
00249
00250
00251
00252
00253
00254
00255 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_16:
00256 if (tactile_data->data_valid.other_sensor_0)
00257 {
00258 tactiles_vector->at(id_sensor).electrodes[15] = static_cast<int>(tactile_data->other_sensor_0);
00259 }
00260 if (tactile_data->data_valid.other_sensor_1)
00261 {
00262 tactiles_vector->at(id_sensor).electrodes[16] = static_cast<int>(tactile_data->other_sensor_1);
00263 }
00264 break;
00265
00266
00267
00268
00269
00270
00271 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_18:
00272 if (tactile_data->data_valid.other_sensor_0)
00273 {
00274 tactiles_vector->at(id_sensor).electrodes[17] = static_cast<int>(tactile_data->other_sensor_0);
00275 }
00276 if (tactile_data->data_valid.other_sensor_1)
00277 {
00278 tactiles_vector->at(id_sensor).electrodes[18] = static_cast<int>(tactile_data->other_sensor_1);
00279 }
00280 break;
00281
00282
00283
00284
00285
00286
00287 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_20:
00288 if (tactile_data->data_valid.other_sensor_0)
00289 {
00290 tactiles_vector->at(id_sensor).electrodes[19] = static_cast<int>(tactile_data->other_sensor_0);
00291 }
00292 if (tactile_data->data_valid.other_sensor_1)
00293 {
00294 tactiles_vector->at(id_sensor).electrodes[20] = static_cast<int>(tactile_data->other_sensor_1);
00295 }
00296 break;
00297
00298 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_22:
00299 if (tactile_data->data_valid.other_sensor_0)
00300 {
00301 tactiles_vector->at(id_sensor).electrodes[21] = static_cast<int>(tactile_data->other_sensor_0);
00302 }
00303 if (tactile_data->data_valid.other_sensor_1)
00304 {
00305 tactiles_vector->at(id_sensor).electrodes[22] = static_cast<int>(tactile_data->other_sensor_1);
00306 }
00307 break;
00308
00309 case TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_24:
00310 if (tactile_data->data_valid.other_sensor_0)
00311 {
00312 tactiles_vector->at(id_sensor).electrodes[23] = static_cast<int>(tactile_data->other_sensor_0);
00313 }
00314
00315
00316
00317
00318 break;
00319
00320
00321 case TACTILE_SENSOR_TYPE_SAMPLE_FREQUENCY_HZ:
00322 if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00323 {
00324 tactiles_vector->at(id_sensor).sample_frequency =
00325 static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
00326 }
00327 break;
00328
00329 case TACTILE_SENSOR_TYPE_MANUFACTURER:
00330 if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00331 {
00332 tactiles_vector->at(id_sensor).manufacturer = this->sanitise_string(status_data->tactile[id_sensor].string,
00333 TACTILE_DATA_LENGTH_BYTES);
00334 }
00335 break;
00336
00337 case TACTILE_SENSOR_TYPE_SERIAL_NUMBER:
00338 if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00339 {
00340 tactiles_vector->at(id_sensor).serial_number = this->sanitise_string(status_data->tactile[id_sensor].string,
00341 TACTILE_DATA_LENGTH_BYTES);
00342 }
00343 break;
00344
00345 case TACTILE_SENSOR_TYPE_SOFTWARE_VERSION:
00346 if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00347 {
00348 tactiles_vector->at(id_sensor).set_software_version(status_data->tactile[id_sensor].string);
00349 }
00350 break;
00351
00352 case TACTILE_SENSOR_TYPE_PCB_VERSION:
00353 if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
00354 {
00355 tactiles_vector->at(id_sensor).pcb_version = this->sanitise_string(status_data->tactile[id_sensor].string,
00356 TACTILE_DATA_LENGTH_BYTES);
00357 }
00358 break;
00359
00360 default:
00361 break;
00362 }
00363 }
00364
00365 if (this->sensor_updater->update_state == operation_mode::device_update_state::INITIALIZATION)
00366 {
00367 this->process_received_data_type(static_cast<int32u>(status_data->tactile_data_type));
00368 if (this->sensor_updater->initialization_configs_vector.size() == 0)
00369 {
00370 this->sensor_updater->update_state = operation_mode::device_update_state::OPERATION;
00371 }
00372 }
00373 }
00374
00375 template<class StatusType, class CommandType>
00376 void Biotac<StatusType, CommandType>::publish()
00377 {
00378
00379 }
00380
00381 template <class StatusType, class CommandType>
00382 void Biotac<StatusType, CommandType>::add_diagnostics(std::vector<diagnostic_msgs::DiagnosticStatus> &vec,
00383 diagnostic_updater::DiagnosticStatusWrapper &d)
00384 {
00385 for (unsigned int id_tact = 0; id_tact < this->nb_tactiles; ++id_tact)
00386 {
00387 std::stringstream ss;
00388 std::string prefix = this->device_id_.empty() ? this->device_id_ : (this->device_id_ + " ");
00389
00390 ss << prefix << "Tactile " << id_tact + 1;
00391
00392 d.name = ss.str().c_str();
00393 d.summary(d.OK, "OK");
00394 d.clear();
00395
00396 d.addf("Sample Frequency", "%d", tactiles_vector->at(id_tact).sample_frequency);
00397 d.addf("Manufacturer", "%s", tactiles_vector->at(id_tact).manufacturer.c_str());
00398 d.addf("Serial Number", "%s", tactiles_vector->at(id_tact).serial_number.c_str());
00399
00400 d.addf("Software Version", "%s", tactiles_vector->at(id_tact).get_software_version().c_str());
00401 d.addf("PCB Version", "%s", tactiles_vector->at(id_tact).pcb_version.c_str());
00402
00403 vec.push_back(d);
00404 }
00405 }
00406
00407 template<class StatusType, class CommandType>
00408 std::vector<AllTactileData> *Biotac<StatusType, CommandType>::get_tactile_data()
00409 {
00410 for (unsigned int i = 0; i < tactiles_vector->size(); ++i)
00411 {
00412 this->all_tactile_data->at(i).biotac = tactiles_vector->at(i);
00413 }
00414
00415 return this->all_tactile_data.get();
00416 }
00417
00418 template <class StatusType, class CommandType>
00419 void Biotac<StatusType, CommandType>::set_version_specific_details()
00420 {
00421 nb_electrodes_ = nb_electrodes_v1_;
00422
00423 for (size_t i = 0; i < this->nb_tactiles; ++i)
00424 {
00425
00426 if (tactiles_vector->at(i).serial_number.find("BTSP") != std::string::npos)
00427 {
00428 nb_electrodes_ = nb_electrodes_v2_;
00429 break;
00430 }
00431 }
00432
00433 if (nb_electrodes_ == nb_electrodes_v1_)
00434 {
00435 for (int32u data = TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_20;
00436 data <= TACTILE_SENSOR_TYPE_BIOTAC_ELECTRODE_24; ++data)
00437 {
00438 std::vector<generic_updater::UpdateConfig>::iterator it =
00439 this->sensor_updater->important_update_configs_vector.begin();
00440 while (it != this->sensor_updater->important_update_configs_vector.end())
00441 {
00442 if (it->what_to_update == data)
00443 {
00444 it = this->sensor_updater->important_update_configs_vector.erase(it);
00445 }
00446 else
00447 {
00448 it++;
00449 }
00450 }
00451 }
00452 }
00453
00454 for (unsigned int id_tact = 0; id_tact < this->nb_tactiles; ++id_tact)
00455 {
00456 tactiles_vector->at(id_tact).electrodes.resize(nb_electrodes_);
00457 }
00458 }
00459
00460
00461 template
00462 class Biotac<ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_STATUS, ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_COMMAND>;
00463
00464 template
00465 class Biotac<ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_STATUS, ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND>;
00466
00467 template
00468 class Biotac<ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_STATUS, ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND>;
00469 }
00470
00471
00472
00473
00474
00475