shadow_PSTs.cpp
Go to the documentation of this file.
1 
28 #include <sr_utilities/sr_math_utils.hpp>
29 #include <string>
30 #include <vector>
31 
32 #define TACTILE_DATA_LENGTH_BYTES TACTILE_DATA_LENGTH_BYTES_v1
33 
34 namespace tactiles
35 {
36  template<class StatusType, class CommandType>
38  std::vector<generic_updater::UpdateConfig> update_configs_vector,
40  : GenericTactiles<StatusType, CommandType>(nh, device_id, update_configs_vector, update_state)
41  {
42  init(update_configs_vector, update_state);
43  }
44 
45  template<class StatusType, class CommandType>
46  ShadowPSTs<StatusType,
47  CommandType>::ShadowPSTs(ros::NodeHandle nh, std::string device_id,
48  std::vector<generic_updater::UpdateConfig> update_configs_vector,
50  boost::shared_ptr<std::vector<GenericTactileData> > init_tactiles_vector)
51  : GenericTactiles<StatusType, CommandType>(nh, device_id, update_configs_vector, update_state)
52  {
53  init(update_configs_vector, update_state);
54  tactiles_vector->clear();
55  for (unsigned int i = 0; i < this->nb_tactiles; i++)
56  {
57  PST3Data tmp_pst(init_tactiles_vector->at(i));
58  tactiles_vector->push_back(tmp_pst);
59  }
60  }
61 
62  template<class StatusType, class CommandType>
63  void ShadowPSTs<StatusType, CommandType>::init(std::vector<generic_updater::UpdateConfig> update_configs_vector,
65  {
66  // initialize the vector of tactiles
67  tactiles_vector = boost::shared_ptr<std::vector<PST3Data> >(new std::vector<PST3Data>(this->nb_tactiles));
69  new std::vector<AllTactileData>(this->nb_tactiles));
70 
71  for (size_t i = 0; i < this->all_tactile_data->size(); ++i)
72  {
73  this->all_tactile_data->at(i).type = "pst";
74  }
75  }
76 
77  template<class StatusType, class CommandType>
78  void ShadowPSTs<StatusType, CommandType>::update(StatusType *status_data)
79  {
80  int tactile_mask = static_cast<int16u>(status_data->tactile_data_valid);
81  // @todo use memcopy instead?
82  for (unsigned int id_sensor = 0; id_sensor < this->nb_tactiles; ++id_sensor)
83  {
84  switch (static_cast<int32u>(status_data->tactile_data_type))
85  {
86  // TACTILE DATA
88  if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
89  {
90  tactiles_vector->at(id_sensor).pressure =
91  static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
92  tactiles_vector->at(id_sensor).temperature =
93  static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[1]));
94  tactiles_vector->at(id_sensor).debug_1 =
95  static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[2]));
96  tactiles_vector->at(id_sensor).debug_2 =
97  static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[3]));
98  }
99  break;
100 
102  if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
103  {
104  tactiles_vector->at(id_sensor).pressure_raw =
105  static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
106  tactiles_vector->at(id_sensor).zero_tracking =
107  static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[1]));
108  }
109  break;
110 
112  if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
113  {
114  tactiles_vector->at(id_sensor).dac_value =
115  static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
116  }
117  break;
118 
119  // COMMON DATA
121  if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
122  {
123  tactiles_vector->at(id_sensor).sample_frequency =
124  static_cast<unsigned int>(static_cast<int16u>(status_data->tactile[id_sensor].word[0]));
125  }
126  break;
127 
129  {
130  if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
131  {
132  tactiles_vector->at(id_sensor).manufacturer = this->sanitise_string(status_data->tactile[id_sensor].string,
134  }
135  }
136  break;
137 
139  {
140  if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
141  {
142  tactiles_vector->at(id_sensor).serial_number = this->sanitise_string(status_data->tactile[id_sensor].string,
144  }
145  }
146  break;
147 
149  if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
150  {
151  tactiles_vector->at(id_sensor).set_software_version(status_data->tactile[id_sensor].string);
152  }
153  break;
154 
156  if (sr_math_utils::is_bit_mask_index_true(tactile_mask, id_sensor))
157  {
158  tactiles_vector->at(id_sensor).pcb_version = this->sanitise_string(status_data->tactile[id_sensor].string,
160  }
161  break;
162 
163  default:
164  break;
165  } // end switch
166  } // end for tactile
167 
169  {
170  this->process_received_data_type(static_cast<int32u>(status_data->tactile_data_type));
171  if (this->sensor_updater->initialization_configs_vector.size() == 0)
172  {
174  }
175  }
176  }
177 
178  template<class StatusType, class CommandType>
180  {
181  // left empty, this is published from the controller publisher
182  } // end publish
183 
184  template <class StatusType, class CommandType>
185  void ShadowPSTs<StatusType, CommandType>::add_diagnostics(std::vector<diagnostic_msgs::DiagnosticStatus> &vec,
187  {
188  for (unsigned int id_tact = 0; id_tact < this->nb_tactiles; ++id_tact)
189  {
190  std::stringstream ss;
191  std::string prefix = this->device_id_.empty() ? this->device_id_ : (this->device_id_ + " ");
192  ss << prefix << "Tactile " << id_tact + 1;
193 
194  d.name = ss.str().c_str();
195  d.summary(d.OK, "OK");
196  d.clear();
197 
198  d.addf("Sample Frequency", "%d", tactiles_vector->at(id_tact).sample_frequency);
199  d.addf("Manufacturer", "%s", tactiles_vector->at(id_tact).manufacturer.c_str());
200  d.addf("Serial Number", "%s", tactiles_vector->at(id_tact).serial_number.c_str());
201 
202  d.addf("Software Version", "%s", tactiles_vector->at(id_tact).get_software_version().c_str());
203  d.addf("PCB Version", "%s", tactiles_vector->at(id_tact).pcb_version.c_str());
204 
205  d.addf("Pressure Raw", "%d", tactiles_vector->at(id_tact).pressure_raw);
206  d.addf("Zero Tracking", "%d", tactiles_vector->at(id_tact).zero_tracking);
207  d.addf("DAC Value", "%d", tactiles_vector->at(id_tact).dac_value);
208 
209  vec.push_back(d);
210  }
211  }
212 
213  template<class StatusType, class CommandType>
215  {
216  for (unsigned int i = 0; i < tactiles_vector->size(); ++i)
217  {
218  this->all_tactile_data->at(i).pst = tactiles_vector->at(i);
219  }
220 
221  return this->all_tactile_data.get();
222  }
223 
224  // Only to ensure that the template class is compiled for the types we are interested in
225  template
227 
228  template
230 
231  template
233 
234  template
236 } // namespace tactiles
237 
238 /* For the emacs weenies in the crowd.
239  Local Variables:
240  c-basic-offset: 2
241  End:
242 */
unsigned short int16u
TACTILE_SENSOR_TYPE_PST3_PRESSURE_TEMPERATURE
TACTILE_SENSOR_TYPE_SOFTWARE_VERSION
void summary(unsigned char lvl, const std::string s)
TACTILE_SENSOR_TYPE_MANUFACTURER
virtual void add_diagnostics(std::vector< diagnostic_msgs::DiagnosticStatus > &vec, diagnostic_updater::DiagnosticStatusWrapper &d)
TACTILE_SENSOR_TYPE_PST3_DAC_VALUE
static const unsigned int nb_tactiles
Number of tactile sensors (TODO: should probably be defined in the protocol)
void addf(const std::string &key, const char *format,...)
boost::shared_ptr< generic_updater::SensorUpdater< CommandType > > sensor_updater
virtual std::vector< AllTactileData > * get_tactile_data()
TACTILE_SENSOR_TYPE_SERIAL_NUMBER
void init(std::vector< generic_updater::UpdateConfig > update_configs_vector, operation_mode::device_update_state::DeviceUpdateState update_state)
Definition: shadow_PSTs.cpp:63
boost::shared_ptr< std::vector< PST3Data > > tactiles_vector
the vector containing the data for the tactiles.
Definition: shadow_PSTs.hpp:81
virtual void publish()
ShadowPSTs(ros::NodeHandle nh, std::string device_id, std::vector< generic_updater::UpdateConfig > update_configs_vector, operation_mode::device_update_state::DeviceUpdateState update_state)
Definition: shadow_PSTs.cpp:37
TACTILE_SENSOR_TYPE_PST3_PRESSURE_RAW_ZERO_TRACKING
TACTILE_SENSOR_TYPE_PCB_VERSION
void process_received_data_type(int32u data)
virtual void update(StatusType *status_data)
Definition: shadow_PSTs.cpp:78
TACTILE_SENSOR_TYPE_SAMPLE_FREQUENCY_HZ
boost::shared_ptr< std::vector< AllTactileData > > all_tactile_data
std::string sanitise_string(const char *raw_string, const unsigned int str_size)
#define TACTILE_DATA_LENGTH_BYTES
Definition: shadow_PSTs.cpp:32


sr_robot_lib
Author(s): Ugo Cupcic, Toni Oliver
autogenerated on Tue Oct 13 2020 04:01:57