SF2 C++ FRC Class Library
Sensor Fusion Framework (SF2) for FRC
SensorDataSourceInfo.h
1 /* ============================================
2  SF2 source code is placed under the MIT license
3  Copyright (c) 2017 Kauai Labs
4 
5  Permission is hereby granted, free of charge, to any person obtaining a copy
6  of this software and associated documentation files (the "Software"), to deal
7  in the Software without restriction, including without limitation the rights
8  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  copies of the Software, and to permit persons to whom the Software is
10  furnished to do so, subject to the following conditions:
11 
12  The above copyright notice and this permission notice shall be included in
13  all copies or substantial portions of the Software.
14 
15  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  THE SOFTWARE.
22  ===============================================
23  */
24 
25 #ifndef SRC_SENSOR_SENSORDATASOURCEINFO_H_
26 #define SRC_SENSOR_SENSORDATASOURCEINFO_H_
27 
28 #include <string>
29 #include <vector>
30 using namespace std;
31 
32 #include "quantity/IQuantity.h"
33 #include "unit/Unit.h"
34 #include "orientation/Quaternion.h"
35 #include "quantity/Scalar.h"
36 
38  string name;
39  vector<IUnit*> units;
40  IQuantity& value;
41 public:
42  SensorDataSourceInfo(string name, IQuantity& value,
43  vector<IUnit *>& units) :
44  value(value)
45  {
46  this->name = name;
47  this->units = units;
48  }
49 
50  SensorDataSourceInfo(string name, IQuantity& value, IUnit&units) :
51  value(value)
52  {
53  this->name = name;
54  this->units.push_back(&units);
55  }
56 
61  string getName() {
62  return name;
63  }
69  return value;
70  }
79  const vector<IUnit *>& getQuantityUnits() {
80  return units;
81  }
82 
83  static void getQuantityArray(
84  vector<SensorDataSourceInfo*>& data_source,
85  vector<IQuantity*>& quantity_list) {
86  for (SensorDataSourceInfo *p_data_source_info : data_source) {
87  const std::type_info& qti = typeid(p_data_source_info->getQuantity());
88  string quantity_name = qti.name();
89  IQuantity *p_new_quantity = NULL;
90  if (quantity_name.compare("Quaternion")) {
91  p_new_quantity = new Quaternion((Quaternion &)p_data_source_info->value);
92  } else if (quantity_name.compare("Scalar")) {
93  p_new_quantity = new Scalar((Scalar &)p_data_source_info->value);
94  } else if (quantity_name.compare("Timestamp")) {
95  p_new_quantity = new Timestamp((Timestamp&)p_data_source_info->value);
96  }
97  quantity_list.push_back(p_new_quantity);
98  }
99  }
100 };
101 
102 #endif /* SRC_SENSOR_SENSORDATASOURCEINFO_H_ */
Definition: SensorDataSourceInfo.h:37
The Quaternion class provides methods to operate on a quaternion.
Definition: Quaternion.h:76
IQuantity & getQuantity()
Returns the class object corresponding to the sensor quantity data type.
Definition: SensorDataSourceInfo.h:68
Definition: Unit.h:43
Definition: IQuantity.h:33
Definition: Scalar.h:35
const vector< IUnit * > & getQuantityUnits()
Returns an array of IUnit objects describing the units of the sensor quantity data type...
Definition: SensorDataSourceInfo.h:79
string getName()
Returns the name of this sensor data.
Definition: SensorDataSourceInfo.h:61
Definition: Timestamp.h:30