Configuration.cpp
Go to the documentation of this file.
2 
3 namespace rokubimini
4 {
5 namespace configuration
6 {
7 void Configuration::load(const std::string& rokubiminiName, NodeHandlePtr nh)
8 {
9  // blabla load the shit from file
10  // Clear the configuration first.
11  *this = Configuration();
12 
13  {
14  // lock the mutex_ for accessing all the internal variables.
15  std::lock_guard<std::recursive_mutex> lock(mutex_);
16  std::string key_string;
17  key_string = rokubiminiName + "/set_reading_to_nan_on_disconnect";
18  if (nh->hasParam(key_string))
19  {
20  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
21  bool set_reading_to_nan_on_disconnect;
22  nh->getParam(key_string, set_reading_to_nan_on_disconnect);
23  setSetReadingToNanOnDisconnect(set_reading_to_nan_on_disconnect);
25  }
26  else
27  {
29  }
30  key_string = rokubiminiName + "/imu_acceleration_range";
31  if (nh->hasParam(key_string))
32  {
33  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
34  int imu_acceleration_range;
35  nh->getParam(key_string, imu_acceleration_range);
36  setImuAccelerationRange(static_cast<unsigned int>(imu_acceleration_range));
38  }
39  else
40  {
42  }
43  key_string = rokubiminiName + "/imu_angular_rate_range";
44  if (nh->hasParam(key_string))
45  {
46  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
47  int imu_angular_rate_range;
48  nh->getParam(key_string, imu_angular_rate_range);
49  setImuAccelerationRange(static_cast<unsigned int>(imu_angular_rate_range));
51  }
52  else
53  {
55  }
56  key_string = rokubiminiName + "/force_torque_filter";
57  ForceTorqueFilter filter;
58  if (filter.load(key_string, nh))
59  {
60  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
61  setForceTorqueFilter(filter);
62  hasForceTorqueFilter_ = true;
63  }
64  else
65  {
66  hasForceTorqueFilter_ = false;
67  }
68  key_string = rokubiminiName + "/imu_acceleration_filter";
69  if (nh->hasParam(key_string))
70  {
71  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
72  int imu_acceleration_filter;
73  nh->getParam(key_string, imu_acceleration_filter);
74  setImuAccelerationFilter(static_cast<unsigned int>(imu_acceleration_filter));
76  }
77  else
78  {
80  }
81 
82  key_string = rokubiminiName + "/imu_angular_rate_filter";
83  if (nh->hasParam(key_string))
84  {
85  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
86  int imu_angular_rate_filter;
87  nh->getParam(key_string, imu_angular_rate_filter);
88  setImuAngularRateFilter(static_cast<unsigned int>(imu_angular_rate_filter));
90  }
91  else
92  {
94  }
95 
96  key_string = rokubiminiName + "/force_torque_offset";
97  Eigen::Matrix<double, 6, 1> offset;
98  bool success = false;
99  std::string force_torque_key;
100 
101  force_torque_key = key_string + "/Fx";
102  if (nh->hasParam(force_torque_key))
103  {
104  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
105  nh->getParam(force_torque_key, offset(0, 0));
106  success = true;
107  }
108  force_torque_key = key_string + "/Fy";
109  if (nh->hasParam(force_torque_key))
110  {
111  nh->getParam(force_torque_key, offset(1, 0));
112  success = true;
113  }
114  force_torque_key = key_string + "/Fz";
115  if (nh->hasParam(force_torque_key))
116  {
117  nh->getParam(force_torque_key, offset(2, 0));
118  success = true;
119  }
120  force_torque_key = key_string + "/Tx";
121  if (nh->hasParam(force_torque_key))
122  {
123  nh->getParam(force_torque_key, offset(3, 0));
124  success = true;
125  }
126  force_torque_key = key_string + "/Ty";
127  if (nh->hasParam(force_torque_key))
128  {
129  nh->getParam(force_torque_key, offset(4, 0));
130  success = true;
131  }
132  force_torque_key = key_string + "/Tz";
133  if (nh->hasParam(force_torque_key))
134  {
135  nh->getParam(force_torque_key, offset(5, 0));
136  success = true;
137  }
138  if (success)
139  {
140  setForceTorqueOffset(offset);
141  hasForceTorqueOffset_ = true;
142  }
143  else
144  {
145  hasForceTorqueOffset_ = false;
146  }
147 
148  key_string = rokubiminiName + "/sensor_configuration";
149  SensorConfiguration configuration;
150  if (configuration.load(key_string, nh))
151  {
152  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
153  setSensorConfiguration(configuration);
155  }
156  else
157  {
158  hasSensorConfiguration_ = false;
159  }
160 
161  key_string = rokubiminiName + "/use_custom_calibration";
162  if (nh->hasParam(key_string))
163  {
164  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
165  bool use_custom_calibration;
166  nh->getParam(key_string, use_custom_calibration);
167  setUseCustomCalibration(use_custom_calibration);
169  }
170  else
171  {
172  hasUseCustomCalibration_ = false;
173  }
174  key_string = rokubiminiName + "/sensor_calibration";
175  calibration::SensorCalibration calibration;
176  if (calibration.load(key_string, nh))
177  {
178  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
179  setSensorCalibration(calibration);
180  hasSensorCalibration_ = true;
181  }
182  else
183  {
184  hasSensorCalibration_ = false;
185  }
186  key_string = rokubiminiName + "/save_configuration";
187  if (nh->hasParam(key_string))
188  {
189  ROS_DEBUG_STREAM(key_string << " found in Parameter Server");
190  bool save_configuration;
191  nh->getParam(key_string, save_configuration);
192  setSaveConfiguration(save_configuration);
193  hasSaveConfiguration_ = true;
194  }
195  else
196  {
197  hasSaveConfiguration_ = false;
198  }
199  }
200 }
201 
203 {
204  ROS_INFO_STREAM("setReadingToNanOnDisconnect_: " << setReadingToNanOnDisconnect_);
205  ROS_INFO_STREAM("useCustomCalibration_: " << useCustomCalibration_);
206  ROS_INFO_STREAM("saveConfiguration_: " << saveConfiguration_);
207  ROS_INFO_STREAM("imuAccelerationRange_: " << imuAccelerationRange_);
208  ROS_INFO_STREAM("imuAngularRateRange_: " << imuAngularRateRange_);
209  ROS_INFO_STREAM("imuAccelerationFilter_: " << imuAccelerationFilter_);
210  ROS_INFO_STREAM("imuAngularRateFilter_: " << imuAngularRateFilter_);
211  ROS_INFO_STREAM("forceTorqueOffset_:\n" << forceTorqueOffset_);
214 }
215 
217 {
240  return *this;
241 }
242 
244 {
245  std::lock_guard<std::recursive_mutex> lock(mutex_);
246  forceTorqueFilter_ = forceTorqueFilter;
247 }
248 
250 {
251  std::lock_guard<std::recursive_mutex> lock(mutex_);
252  return forceTorqueFilter_;
253 }
254 
255 void Configuration::setForceTorqueOffset(const Eigen::Matrix<double, 6, 1>& forceTorqueOffset)
256 {
257  std::lock_guard<std::recursive_mutex> lock(mutex_);
258  forceTorqueOffset_ = forceTorqueOffset;
259 }
260 
261 const Eigen::Matrix<double, 6, 1>& Configuration::getForceTorqueOffset() const
262 {
263  std::lock_guard<std::recursive_mutex> lock(mutex_);
264  return forceTorqueOffset_;
265 }
266 
267 void Configuration::setUseCustomCalibration(const bool useCustomCalibration)
268 {
269  std::lock_guard<std::recursive_mutex> lock(mutex_);
270  useCustomCalibration_ = useCustomCalibration;
271 }
272 
274 {
275  std::lock_guard<std::recursive_mutex> lock(mutex_);
276  return useCustomCalibration_;
277 }
278 
279 void Configuration::setSaveConfiguration(const bool saveConfiguration)
280 {
281  std::lock_guard<std::recursive_mutex> lock(mutex_);
282  saveConfiguration_ = saveConfiguration;
283 }
284 
286 {
287  std::lock_guard<std::recursive_mutex> lock(mutex_);
288  return saveConfiguration_;
289 }
290 
291 void Configuration::setSetReadingToNanOnDisconnect(const bool setReadingToNanOnDisconnect)
292 {
293  std::lock_guard<std::recursive_mutex> lock(mutex_);
294  setReadingToNanOnDisconnect_ = setReadingToNanOnDisconnect;
295 }
296 
298 {
299  std::lock_guard<std::recursive_mutex> lock(mutex_);
301 }
302 
304 {
305  std::lock_guard<std::recursive_mutex> lock(mutex_);
306  sensorConfiguration_ = sensorConfiguration;
307 }
308 
310 {
311  std::lock_guard<std::recursive_mutex> lock(mutex_);
312  return sensorConfiguration_;
313 }
314 
316 {
317  std::lock_guard<std::recursive_mutex> lock(mutex_);
318  sensorCalibration_ = sensorCalibration;
319 }
320 
322 {
323  std::lock_guard<std::recursive_mutex> lock(mutex_);
324  return sensorCalibration_;
325 }
326 
327 void Configuration::setImuAccelerationFilter(const unsigned int imuAccelerationFilter)
328 {
329  std::lock_guard<std::recursive_mutex> lock(mutex_);
330  imuAccelerationFilter_ = imuAccelerationFilter;
331 }
332 
334 {
335  std::lock_guard<std::recursive_mutex> lock(mutex_);
336  return imuAccelerationFilter_;
337 }
338 
339 void Configuration::setImuAngularRateFilter(const unsigned int imuAngularRateFilter)
340 {
341  std::lock_guard<std::recursive_mutex> lock(mutex_);
342  imuAngularRateFilter_ = imuAngularRateFilter;
343 }
344 
346 {
347  std::lock_guard<std::recursive_mutex> lock(mutex_);
348  return imuAngularRateFilter_;
349 }
350 
351 void Configuration::setImuAccelerationRange(const uint8_t imuAccelerationRange)
352 {
353  std::lock_guard<std::recursive_mutex> lock(mutex_);
354  imuAccelerationRange_ = imuAccelerationRange;
355 }
356 
358 {
359  std::lock_guard<std::recursive_mutex> lock(mutex_);
360  return imuAccelerationRange_;
361 }
362 
363 void Configuration::setImuAngularRateRange(const uint8_t imuAngularRateRange)
364 {
365  std::lock_guard<std::recursive_mutex> lock(mutex_);
366  imuAngularRateRange_ = imuAngularRateRange;
367 }
368 
370 {
371  std::lock_guard<std::recursive_mutex> lock(mutex_);
372  return imuAngularRateRange_;
373 }
374 
376 {
377  std::lock_guard<std::recursive_mutex> lock(mutex_);
379 }
380 
382 {
383  std::lock_guard<std::recursive_mutex> lock(mutex_);
385 }
386 
388 {
389  std::lock_guard<std::recursive_mutex> lock(mutex_);
391 }
392 
394 {
395  std::lock_guard<std::recursive_mutex> lock(mutex_);
396  return hasForceTorqueFilter_;
397 }
398 
400 {
401  std::lock_guard<std::recursive_mutex> lock(mutex_);
402  return hasForceTorqueOffset_;
403 }
404 
406 {
407  std::lock_guard<std::recursive_mutex> lock(mutex_);
409 }
410 
412 {
413  std::lock_guard<std::recursive_mutex> lock(mutex_);
414  return hasSaveConfiguration_;
415 }
416 
418 {
419  std::lock_guard<std::recursive_mutex> lock(mutex_);
420  return hasSensorCalibration_;
421 }
422 
424 {
425  std::lock_guard<std::recursive_mutex> lock(mutex_);
427 }
428 
430 {
431  std::lock_guard<std::recursive_mutex> lock(mutex_);
433 }
434 
436 {
437  std::lock_guard<std::recursive_mutex> lock(mutex_);
439 }
440 } // namespace configuration
441 } // namespace rokubimini
bool hasForceTorqueOffset() const
Checks if the value of the forceTorqueOffset_ variable has been set by the user in the configuration ...
bool hasImuAccelerationRange() const
Checks if the value of the imuAccelerationRange_ variable has been set by the user in the configurati...
void setUseCustomCalibration(const bool useCustomCalibration)
Sets the useCustomCalibration variable.
Class holding the force-torque filter settings.
bool hasSetReadingToNanOnDisconnect() const
Checks if the value of the setReadingToNanOnDisconnect_ variable has been set by the user in the conf...
bool getSetReadingToNanOnDisconnect() const
Gets the setReadingToNanOnDisconnect variable.
Eigen::Matrix< double, 6, 1 > forceTorqueOffset_
The forceTorqueOffset variable.
std::recursive_mutex mutex_
Mutex for synchronized access on the object&#39;s private variables.
bool hasForceTorqueFilter() const
Checks if the value of the forceTorqueFilter_ variable has been set by the user in the configuration ...
bool hasSensorCalibration() const
Checks if the value of the sensorCalibration_ variable has been set by the user in the configuration ...
Class holding the configuration of the sensor.
Configuration()=default
Default constructor.
bool hasForceTorqueOffset_
Flag indicating if forceTorqueOffset_ is set.
bool hasImuAngularRateFilter_
Flag indicating if imuAngularRateFilter_ is set.
SensorConfiguration sensorConfiguration_
The sensorConfiguration variable.
const ForceTorqueFilter & getForceTorqueFilter() const
Gets the forceTorqueFilter variable.
bool hasSensorConfiguration_
Flag indicating if sensorConfiguration_ is set.
bool hasUseCustomCalibration_
Flag indicating if useCustomCalibration_ is set.
void setImuAccelerationRange(const uint8_t imuAccelerationRange)
Sets the imuAccelerationRange variable.
void print() const
Prints the existing sensor configuration settings.
void setImuAngularRateRange(const uint8_t imuAngularRateRange)
Sets the imuAngularRateRange variable.
bool hasImuAngularRateFilter() const
Checks if the value of the imuAngularRateFilter_ variable has been set by the user in the configurati...
bool hasImuAccelerationRange_
Flag indicating if imuAccelerationRange_ is set.
void setSensorConfiguration(const SensorConfiguration &sensorConfiguration)
Sets the sensorConfiguration variable.
bool hasSensorConfiguration() const
Checks if the value of the sensorConfiguration_ variable has been set by the user in the configuratio...
const Eigen::Matrix< double, 6, 1 > & getForceTorqueOffset() const
Gets the forceTorqueOffset variable.
bool hasImuAngularRateRange() const
Checks if the value of the imuAngularRateRange_ variable has been set by the user in the configuratio...
unsigned int imuAngularRateFilter_
The imuAngularRateFilter variable.
bool getUseCustomCalibration() const
Gets the useCustomCalibration variable.
bool hasSetReadingToNanOnDisconnect_
Flag indicating if setReadingToNanOnDisconnect_ is set.
bool getSaveConfiguration() const
Gets the saveConfiguration variable.
calibration::SensorCalibration sensorCalibration_
The sensorCalibration variable.
unsigned int getImuAngularRateFilter() const
Gets the imuAccelerationFilter variable.
Class holding the sensor configuration settings.
bool hasSaveConfiguration() const
Checks if the value of the saveConfiguration_ variable has been set by the user in the configuration ...
void print() const
Prints the existing Filter settings.
bool saveConfiguration_
The saveConfiguration_ variable.
bool hasImuAccelerationFilter_
Flag indicating if imuAccelerationFilter_ is set.
The SensorCalibration class is used for holding the calibration information of each rokubi mini senso...
bool hasImuAngularRateRange_
Flag indicating if imuAngularRateRange_ is set.
bool hasUseCustomCalibration() const
Checks if the value of the useCustomCalibration_ variable has been set by the user in the configurati...
uint8_t getImuAccelerationRange() const
Gets the imuAccelerationRange variable.
void setForceTorqueFilter(const ForceTorqueFilter &forceTorqueFilter)
Sets the forceTorqueFilter variable.
bool hasSaveConfiguration_
Flag indicating if saveConfiguration_ is set.
void load(const std::string &key, NodeHandlePtr nh)
Loads the configuration from the parameter server.
void setImuAccelerationFilter(const unsigned int imuAccelerationFilter)
Sets the imuAccelerationFilter variable.
bool load(const std::string &key, NodeHandlePtr nh)
Loads the calibrations from the parameter server.
void setSetReadingToNanOnDisconnect(const bool setReadingToNanOnDisconnect)
Sets the setReadingToNanOnDisconnect variable.
const calibration::SensorCalibration & getSensorCalibration() const
Gets the sensorCalibration variable.
unsigned int getImuAccelerationFilter() const
uint8_t getImuAngularRateRange() const
Gets the imuAngularRateRange variable.
unsigned int imuAccelerationRange_
The imuAccelerationRange variable.
bool setReadingToNanOnDisconnect_
The setReadingToNanOnDisconnect variable.
bool hasForceTorqueFilter_
Flag indicating if forceTorqueFilter_ is set.
ForceTorqueFilter forceTorqueFilter_
The forceTorqueFilter variable.
void printConfiguration() const
Prints the existing Configuration.
void setSensorCalibration(const calibration::SensorCalibration &sensorCalibration)
Sets the sensorCalibration variable.
#define ROS_DEBUG_STREAM(args)
unsigned int imuAccelerationFilter_
The imuAccelerationFilter variable.
#define ROS_INFO_STREAM(args)
unsigned int imuAngularRateRange_
The imuAngularRateRange variable.
bool useCustomCalibration_
The useCustomCalibration variable.
bool hasImuAccelerationFilter() const
Checks if the value of the imuAccelerationFilter_ variable has been set by the user in the configurat...
void setForceTorqueOffset(const Eigen::Matrix< double, 6, 1 > &forceTorqueOffset)
Sets the forceTorqueOffset variable.
void setSaveConfiguration(const bool saveConfiguration)
Sets the saveConfiguration variable.
bool hasSensorCalibration_
Flag indicating if sensorCalibration_ is set.
Configuration & operator=(const Configuration &other)
Assignment operator for Configuration.
bool load(const std::string &key, NodeHandlePtr nh)
Loads the force torque filter from the parameter server.
bool load(const std::string &key, NodeHandlePtr nh)
Loads the sensor configuration from the parameter server.
void setImuAngularRateFilter(const unsigned int imuAngularRateFilter)
Sets the imuAngularRateFilter variable.
const SensorConfiguration & getSensorConfiguration() const
Gets the sensorConfiguration variable.
std::shared_ptr< ros::NodeHandle > NodeHandlePtr
Tests Configuration.


rokubimini
Author(s):
autogenerated on Wed Mar 3 2021 03:09:12