1 #ifndef OPENSIM_IMU_DATA_READER_H_ 2 #define OPENSIM_IMU_DATA_READER_H_ 3 4 /* -------------------------------------------------------------------------- * 5 * OpenSim: IMUDataReader.h * 6 * -------------------------------------------------------------------------- * 7 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. * 8 * OpenSim is developed at Stanford University and supported by the US * 9 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA * 10 * through the Warrior Web program. * 11 * * 12 * Copyright (c) 2005-2019 Stanford University and the Authors * 13 * * 14 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 15 * not use this file except in compliance with the License. You may obtain a * 16 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 17 * * 18 * Unless required by applicable law or agreed to in writing, software * 19 * distributed under the License is distributed on an "AS IS" BASIS, * 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 * See the License for the specific language governing permissions and * 22 * limitations under the License. * 23 * -------------------------------------------------------------------------- */ 24 #include "osimCommonDLL.h" 25 #include "TimeSeriesTable.h" 26 #include "DataAdapter.h" 27 28 /** @file 29 * This file defines common base class for various IMU DataReader 30 * classes that support different IMU providers 31 */ 32 33 namespace OpenSim { 34 35 36 class OSIMCOMMON_API IMUDataReader : public DataAdapter { 37 38 public: 39 40 IMUDataReader() = default; 41 IMUDataReader(const IMUDataReader&) = default; 42 IMUDataReader(IMUDataReader&&) = default; 43 IMUDataReader& operator=(const IMUDataReader&) = default; 44 IMUDataReader& operator=(IMUDataReader&&) = default; 45 virtual ~IMUDataReader() = default; 46 47 static const std::string Orientations; // name of table for orientation data 48 static const std::string LinearAccelerations; // name of table for acceleration data 49 static const std::string MagneticHeading; // name of table for data from Magnetometer (Magnetic Heading) 50 static const std::string AngularVelocity; // name of table for gyro data (AngularVelocity) 51 /** 52 * Custom accessors to retrieve tables of proper types without requiring users/scripters to cast. 53 * Scripting friendly */ 54 /** get table of Orientations as TimeSeriesTableQuaternion */ getOrientationsTable(const DataAdapter::OutputTables & tables)55 static const TimeSeriesTable_<SimTK::Quaternion_<double>>& getOrientationsTable(const DataAdapter::OutputTables& tables) { 56 return dynamic_cast<const TimeSeriesTableQuaternion&>(*tables.at(Orientations)); 57 } 58 /** get table of LinearAccelerations as TimeSeriesTableVec3 */ getLinearAccelerationsTable(const DataAdapter::OutputTables & tables)59 static const TimeSeriesTableVec3& getLinearAccelerationsTable(const DataAdapter::OutputTables& tables) { 60 return dynamic_cast<const TimeSeriesTableVec3&>(*tables.at(LinearAccelerations)); 61 } 62 /** get table of MagneticHeading as TimeSeriesTableVec3 */ getMagneticHeadingTable(const DataAdapter::OutputTables & tables)63 static const TimeSeriesTableVec3& getMagneticHeadingTable(const DataAdapter::OutputTables& tables) { 64 return dynamic_cast<const TimeSeriesTableVec3&>(*tables.at(MagneticHeading)); 65 } 66 /** get table of AngularVelocity as TimeSeriesTableVec3 */ getAngularVelocityTable(const DataAdapter::OutputTables & tables)67 static const TimeSeriesTableVec3& getAngularVelocityTable(const DataAdapter::OutputTables& tables) { 68 return dynamic_cast<const TimeSeriesTableVec3&>(*tables.at(AngularVelocity)); 69 } 70 protected: 71 /** create a map of names to TimeSeriesTables. MetaData contains dataRate. 72 * The result can be passed to accessors above to get individual TimeSeriesTable(s) 73 * If a matrix has nrows = 0 then an empty table is created. 74 */ 75 DataAdapter::OutputTables createTablesFromMatrices(double dataRate, 76 const std::vector<std::string>& labels, const std::vector<double>& times, 77 const SimTK::Matrix_<SimTK::Quaternion>& rotationsData, 78 const SimTK::Matrix_<SimTK::Vec3>& linearAccelerationData, 79 const SimTK::Matrix_<SimTK::Vec3>& magneticHeadingData, 80 const SimTK::Matrix_<SimTK::Vec3>& angularVelocityData) const; 81 }; 82 83 } // OpenSim namespace 84 85 #endif // OPENSIM_IMU_DATA_READER_H_ 86