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
00031 namespace tactiles
00032 {
00033 ShadowPSTs::ShadowPSTs(std::vector<generic_updater::UpdateConfig> update_configs_vector, operation_mode::device_update_state::DeviceUpdateState update_state)
00034 : GenericTactiles(update_configs_vector, update_state)
00035 {
00036 init(update_configs_vector, update_state);
00037 }
00038
00039 ShadowPSTs::ShadowPSTs(std::vector<generic_updater::UpdateConfig> update_configs_vector, operation_mode::device_update_state::DeviceUpdateState update_state, boost::shared_ptr< std::vector<GenericTactileData> > init_tactiles_vector)
00040 : GenericTactiles(update_configs_vector, update_state)
00041 {
00042 init(update_configs_vector, update_state);
00043 tactiles_vector->clear();
00044 for(unsigned int i=0;i<nb_tactiles;i++)
00045 {
00046 PST3Data tmp_pst(init_tactiles_vector->at(i));
00047 tactiles_vector->push_back( tmp_pst );
00048 }
00049 }
00050
00051 void ShadowPSTs::init(std::vector<generic_updater::UpdateConfig> update_configs_vector, operation_mode::device_update_state::DeviceUpdateState update_state)
00052 {
00053
00054 tactile_publisher = boost::shared_ptr<realtime_tools::RealtimePublisher<sr_robot_msgs::ShadowPST> >( new realtime_tools::RealtimePublisher<sr_robot_msgs::ShadowPST>(nodehandle_ , "tactile", 4));
00055
00056
00057 tactiles_vector = boost::shared_ptr< std::vector<PST3Data> >( new std::vector<PST3Data>(nb_tactiles) );
00058 all_tactile_data = boost::shared_ptr<std::vector<AllTactileData> >( new std::vector<AllTactileData>(nb_tactiles) );
00059 }
00060
00061 void ShadowPSTs::update(ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_STATUS* status_data)
00062 {
00063 int tactile_mask = static_cast<int16u>(status_data->tactile_data_valid);
00064
00065 for( unsigned int id_sensor = 0; id_sensor < nb_tactiles; ++id_sensor)
00066 {
00067 switch( static_cast<int32u>(status_data->tactile_data_type) )
00068 {
00069
00070 case TACTILE_SENSOR_TYPE_PST3_PRESSURE_TEMPERATURE:
00071 if( sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor) )
00072 {
00073 tactiles_vector->at(id_sensor).pressure = static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]) );
00074 tactiles_vector->at(id_sensor).temperature = static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[1]) );
00075 tactiles_vector->at(id_sensor).debug_1 = static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[2]) );
00076 tactiles_vector->at(id_sensor).debug_2 = static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[3]) );
00077 }
00078 break;
00079
00080 case TACTILE_SENSOR_TYPE_PST3_PRESSURE_RAW_ZERO_TRACKING:
00081 if( sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor) )
00082 {
00083 tactiles_vector->at(id_sensor).pressure_raw = static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]) );
00084 tactiles_vector->at(id_sensor).zero_tracking = static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[1]) );
00085 }
00086 break;
00087
00088 case TACTILE_SENSOR_TYPE_PST3_DAC_VALUE:
00089 if( sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor) )
00090 {
00091 tactiles_vector->at(id_sensor).dac_value = static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]) );
00092 }
00093 break;
00094
00095
00096 case TACTILE_SENSOR_TYPE_SAMPLE_FREQUENCY_HZ:
00097 if( sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor) )
00098 {
00099 tactiles_vector->at(id_sensor).sample_frequency = static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]) );
00100 }
00101 break;
00102
00103 case TACTILE_SENSOR_TYPE_MANUFACTURER:
00104 {
00105 if( sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor) )
00106 {
00107 tactiles_vector->at(id_sensor).manufacturer = sanitise_string( status_data->tactile[id_sensor].string, TACTILE_DATA_LENGTH_BYTES );
00108 }
00109 }
00110 break;
00111
00112 case TACTILE_SENSOR_TYPE_SERIAL_NUMBER:
00113 {
00114 if( sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor) )
00115 {
00116 tactiles_vector->at(id_sensor).serial_number = sanitise_string( status_data->tactile[id_sensor].string, TACTILE_DATA_LENGTH_BYTES );
00117 }
00118 }
00119 break;
00120
00121 case TACTILE_SENSOR_TYPE_SOFTWARE_VERSION:
00122 if( sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor) )
00123 {
00124 tactiles_vector->at(id_sensor).set_software_version( status_data->tactile[id_sensor].string );
00125 }
00126 break;
00127
00128 case TACTILE_SENSOR_TYPE_PCB_VERSION:
00129 if( sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor) )
00130 {
00131 tactiles_vector->at(id_sensor).pcb_version = sanitise_string( status_data->tactile[id_sensor].string, TACTILE_DATA_LENGTH_BYTES );
00132 }
00133 break;
00134
00135 default:
00136 break;
00137
00138 }
00139 }
00140
00141 if(sensor_updater->update_state == operation_mode::device_update_state::INITIALIZATION)
00142 {
00143 process_received_data_type(static_cast<int32u>(status_data->tactile_data_type));
00144 if(sensor_updater->initialization_configs_vector.size() == 0)
00145 sensor_updater->update_state = operation_mode::device_update_state::OPERATION;
00146 }
00147 }
00148
00149 void ShadowPSTs::publish()
00150 {
00151 if(tactile_publisher->trylock())
00152 {
00153
00154 sr_robot_msgs::ShadowPST tactiles;
00155 tactiles.header.stamp = ros::Time::now();
00156
00157
00158
00159 for(unsigned int id_tact = 0; id_tact < nb_tactiles; ++id_tact)
00160 {
00161
00162
00163 tactiles.pressure.push_back( tactiles_vector->at(id_tact).pressure );
00164 tactiles.temperature.push_back( tactiles_vector->at(id_tact).temperature );
00165 }
00166
00167
00168 tactile_publisher->msg_ = tactiles;
00169 tactile_publisher->unlockAndPublish();
00170 }
00171
00172 }
00173
00174 void ShadowPSTs::add_diagnostics(std::vector<diagnostic_msgs::DiagnosticStatus> &vec,
00175 diagnostic_updater::DiagnosticStatusWrapper &d)
00176 {
00177 for(unsigned int id_tact = 0; id_tact < nb_tactiles; ++id_tact)
00178 {
00179 std::stringstream ss;
00180
00181 ss << "Tactile " << id_tact + 1;
00182
00183 d.name = ss.str().c_str();
00184 d.summary(d.OK, "OK");
00185 d.clear();
00186
00187 d.addf("Sample Frequency", "%d", tactiles_vector->at(id_tact).sample_frequency);
00188 d.addf("Manufacturer", "%s", tactiles_vector->at(id_tact).manufacturer.c_str());
00189 d.addf("Serial Number", "%s", tactiles_vector->at(id_tact).serial_number.c_str());
00190
00191 d.addf("Software Version", "%d", tactiles_vector->at(id_tact).get_software_version().c_str());
00192 d.addf("PCB Version", "%s", tactiles_vector->at(id_tact).pcb_version.c_str());
00193
00194 d.addf("Pressure Raw", "%d", tactiles_vector->at(id_tact).pressure_raw);
00195 d.addf("Zero Tracking", "%d", tactiles_vector->at(id_tact).zero_tracking);
00196 d.addf("DAC Value", "%d", tactiles_vector->at(id_tact).dac_value);
00197
00198 vec.push_back(d);
00199 }
00200 }
00201
00202 std::vector<AllTactileData>* ShadowPSTs::get_tactile_data()
00203 {
00204 for( unsigned int i=0; i < tactiles_vector->size(); ++i)
00205 all_tactile_data->at(i).pst = tactiles_vector->at(i);
00206
00207 return all_tactile_data.get();
00208 }
00209
00210 }
00211
00212
00213
00214
00215
00216
00217
00218