/* -------------------------------------------------------------------------- * * OpenSim: testSmoothSegmentedFunctionFactory.cpp * * -------------------------------------------------------------------------- * * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. * * See http://opensim.stanford.edu and the NOTICE file for more information. * * OpenSim is developed at Stanford University and supported by the US * * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA * * through the Warrior Web program. * * * * Copyright (c) 2005-2012 Stanford University and the Authors * * Author(s): Matthew Millard * * * * Licensed under the Apache License, Version 2.0 (the "License"); you may * * not use this file except in compliance with the License. You may obtain a * * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * * -------------------------------------------------------------------------- */ /* Update: This is a port of the original code so that it will work with the multibody code RBDL written by Martin Felis. This also includes additional curves (the Anderson2007 curves) which are not presently in OpenSim. Author: Matthew Millard Date: Nov 2015 */ /* Below is a basic bench mark simulation for the SmoothSegmentedFunctionFactory class, a class that enables the easy generation of C2 continuous curves that define the various characteristic curves required in a muscle model */ // Author: Matthew Millard //============================================================================== // INCLUDES //============================================================================== #include "geometry.h" #include "numericalTestFunctions.h" #include #include #include #include #include #include #include #include using namespace RigidBodyDynamics::Addons::Geometry; using namespace std; /** This function will create a quintic Bezier curve y(x) and sample it, its first derivative w.r.t. U (dx(u)/du and dy(u)/du), and its first derivative w.r.t. to X and print it to the screen. */ void testSegmentedQuinticBezierDerivatives( int maximumNumberOfToleranceViolations) { //cout <<"**************************************************"<tol) //printf("Error > Tol: (%i,%i): %f > %f\n",j,i,errorDer(j,i),tol); } } //errorDer.cwiseAbs(); //cout << errorDer << endl; //printf("...absolute tolerance of %f met\n", tol); //cout << " TEST: Bezier Curve Derivative DYDX to d6y/dx6" << endl; RigidBodyDynamics::Math::MatrixNd numericDerXY(analyticDerXU.rows(), 6); RigidBodyDynamics::Math::MatrixNd analyticDerXY(analyticDerXU.rows(),6); for(int i=0; i< analyticDerXU.rows(); i++) { analyticDerXY(i,0) = SegmentedQuinticBezierToolkit:: calcQuinticBezierCurveDerivDYDX(uV[i],xPts,yPts,1); analyticDerXY(i,1) = SegmentedQuinticBezierToolkit:: calcQuinticBezierCurveDerivDYDX(uV[i],xPts,yPts,2); analyticDerXY(i,2) = SegmentedQuinticBezierToolkit:: calcQuinticBezierCurveDerivDYDX(uV[i],xPts,yPts,3); analyticDerXY(i,3) = SegmentedQuinticBezierToolkit:: calcQuinticBezierCurveDerivDYDX(uV[i],xPts,yPts,4); analyticDerXY(i,4) = SegmentedQuinticBezierToolkit:: calcQuinticBezierCurveDerivDYDX(uV[i],xPts,yPts,5); analyticDerXY(i,5) = SegmentedQuinticBezierToolkit:: calcQuinticBezierCurveDerivDYDX(uV[i],xPts,yPts,6); } for(int j=0; jrelTol){ //printf("Error > Tol: (%i,%i): %f > %f\n",i,j, // errorDerXY(i,j),relTol); relTolExceeded++; } } } //cout << relTolExceeded << endl; //The relative tolerance gets exceeded occasionally in locations of //rapid change in the curve. Provided there are only a few locations //where the relative tolerance of 5% is broken, the curves should be //regarded as being good. Ten errors out of a possible 100*6 data points //seems relatively small. CHECK(relTolExceeded < maximumNumberOfToleranceViolations); //std::string fname = "analyticDerXY.csv"; //printMatrixToFile(analyticDerXY,fname); //fname = "numericDerXY.csv"; //printMatrixToFile(numericDerXY,fname); //fname = "errorDerXY.csv"; //printMatrixToFile(errorDerXY,fname); //printf(" ...relative tolerance of %f not exceeded more than %i times\n" // " across all 6 derivatives, with 100 samples each\n", // relTol, 10); //cout <<"**************************************************"<