1 // ============================================================================= 2 // PROJECT CHRONO - http://projectchrono.org 3 // 4 // Copyright (c) 2014 projectchrono.org 5 // All rights reserved. 6 // 7 // Use of this source code is governed by a BSD-style license that can be found 8 // in the LICENSE file at the top level of the distribution and at 9 // http://projectchrono.org/license-chrono.txt. 10 // 11 // ============================================================================= 12 // Authors: Alessandro Tasora, Radu Serban 13 // ============================================================================= 14 15 #ifndef CHFUNCT_MOCAP_H 16 #define CHFUNCT_MOCAP_H 17 18 #include "chrono/motion_functions/ChFunction_Base.h" 19 20 namespace chrono { 21 22 /// @addtogroup chrono_functions 23 /// @{ 24 25 /// Motion capture (sample) function: 26 /// `y = (linear interpolated array of samples)` 27 class ChApi ChFunction_Mocap : public ChFunction { 28 private: 29 ChArray<> array_y; 30 ChArray<> array_y_dt; 31 ChArray<> array_y_dtdt; 32 33 double samp_freq; 34 int samples; 35 double timetot; 36 37 public: 38 ChFunction_Mocap(); 39 ChFunction_Mocap(int m_samples, double freq); 40 ChFunction_Mocap(const ChFunction_Mocap& other); ~ChFunction_Mocap()41 ~ChFunction_Mocap() {} 42 43 /// "Virtual" copy constructor (covariant return type). Clone()44 virtual ChFunction_Mocap* Clone() const override { return new ChFunction_Mocap(*this); } 45 Get_Type()46 virtual FunctionType Get_Type() const override { return FUNCT_MOCAP; } 47 virtual double Get_y(double x) const override; 48 virtual double Get_y_dx(double x) const override; 49 virtual double Get_y_dxdx(double x) const override; 50 51 void Set_samp_freq(double m_fr); 52 void Set_samples(int m_samples); 53 Get_samp_freq()54 double Get_samp_freq() const { return samp_freq; } Get_samples()55 int Get_samples() const { return samples; } Get_timetot()56 double Get_timetot() const { return ((double)samples / samp_freq); } Get_timeslice()57 double Get_timeslice() const { return (1 / samp_freq); } 58 Get_array_y()59 const ChArray<>& Get_array_y() const { return array_y; } Get_array_y_dt()60 const ChArray<>& Get_array_y_dt() const { return array_y_dt; } Get_array_y_dtdt()61 const ChArray<>& Get_array_y_dtdt() const { return array_y_dtdt; } 62 63 void Set_array_y(const ChArray<>& m_array_y); 64 void Set_array_y_dt(const ChArray<>& m_array_y_dt); // *** TO DO 65 void Set_array_y_dtdt(const ChArray<>& m_array_y_dtdt); // *** TO DO 66 67 bool Parse_array_AOA(); // *** TO DO 68 bool Parse_array_Elite(); // *** TO DO 69 70 virtual void Estimate_x_range(double& xmin, double& xmax) const override; 71 72 /// Method to allow serialization of transient data to archives. 73 virtual void ArchiveOUT(ChArchiveOut& marchive) override; 74 75 /// Method to allow de-serialization of transient data from archives. 76 virtual void ArchiveIN(ChArchiveIn& marchive) override; 77 78 private: 79 void Compute_array_dt(const ChArray<>& array_A, ChArray<>& array_A_dt) const; 80 double LinInterp(const ChArray<>& array, double x, double x_max) const; 81 }; 82 83 /// @} chrono_functions 84 85 CH_CLASS_VERSION(ChFunction_Mocap, 0) 86 87 } // end namespace chrono 88 89 #endif 90