--- a +++ b/Tools/AnyMocap/InterpolateJointAngleData.any @@ -0,0 +1,77 @@ +#ifndef MOCAP_FILTER_JOINT_ANGLES + #define MOCAP_FILTER_JOINT_ANGLES OFF +#endif + +#ifndef _MOCAP_FULL_TARRAY +#define _MOCAP_FULL_TARRAY Main.Studies.MarkerTracking.tArray +#endif + +#ifndef _MOCAP_MAIN_STUDY_REF +#define _MOCAP_MAIN_STUDY_REF Main.Studies.InverseDynamicStudy +#endif + +AnyFunInterpol InterpolatedData = +{ + Type ??= iffun(gtfun(.FileReader.Length0, 1), Bspline, ConstantValue); + BsplineOrder ??= min({4,.FileReader.Length0}); + T = .FileReader.T; + + #if MOCAP_FILTER_JOINT_ANGLES == ON + Data = Main.ModelSetup.JointAngleFilter.FilterFun(.FileReader.Data); + #else + Data ??= .FileReader.Data; + #endif +}; + +AnyInputFile FileReader = { + // Check if the start time is with the range of data in the file. + + /// Number of data elements in the file + AnyInt nFile = NumElemOf(.FileReader.TFile); + + AnyFloat TFileMin = arrcat(TFile, {0.0})[0]; + AnyFloat TFileMax = arrcat(TFile, {0.0})[ max({ min({TFileNumRead,Length0})-1,0})]; + AnyInt ValidStartTime = andfun( gtfun(_MOCAP_MAIN_STUDY_REF.tArray[0],TFileMin-1e-13), + ltfun(_MOCAP_MAIN_STUDY_REF.tArray[0], TFileMax+1e-13)); + + + AnyInt ValidData = andfun(ValidStartTime, bool(TFileIsMonotoneIncreasing)); + + // If there is problems with the file data, force the use of default data. + AlwaysUseData0 ??= not(ValidData); + + // FileName: This is set externally to this include file. + FileErrorContinueOnOff = On; + ReloadOnOff = On; + SuppressWarningsOnOff = On; + + AnyInt Length0 = NumElemOf(_MOCAP_FULL_TARRAY); + T0 = _MOCAP_FULL_TARRAY; +}; + +#ifndef _ANYMOCAP_JOINT_ANGLE_WARNING_MSG_ +#define _ANYMOCAP_JOINT_ANGLE_WARNING_MSG_ +AnyMessage AnyMoCap_msg1= +{ + AnyInt LastTimeIdx = max({0,.FileReader.TFileNumRead-1}); + AnyVar LastTimeInFile = .FileReader.T[min({LastTimeIdx, NumElemOf(.FileReader.T)-1})]; + TriggerRuntime = andfun(.FileReader.ValidData, + andfun(_MOCAP_MAIN_STUDY_REF.iStep, gtfun(_MOCAP_MAIN_STUDY_REF.t, LastTimeInFile ))); + Type = MSG_ErrorFatal; + Message = DesignVar(strformat("\n"+ + "----------------------------------------------------------------------------------------------------------\n"+ + " No kinematic joint angle data available after t = "+strval(LastTimeInFile, "%.3g") + "s.\n "+ + " Please re-run the entire Marker Tracking first (or Main.RunAnalysis)\n"+ + "----------------------------------------------------------------------------------------------------------\n")); +}; +AnyMessage AnyMoCap_msg2= +{ + TriggerRuntime = andfun(eqfun(_MOCAP_MAIN_STUDY_REF.iStep,1), not(.FileReader.ValidData)); + Type = MSG_ErrorFatal; + Message = DesignVar(strformat("\n"+ + "----------------------------------------------------------------------------------------------------------\n"+ + " No valid kinematic joint angle data available.\n"+ + " Please run the Marker Tracking analysis first (or Main.RunAnalysis)\n"+ + "----------------------------------------------------------------------------------------------------------\n")); +}; +#endif