Page 1 of 1

Load plugin fails

Posted: Sun May 25, 2014 8:45 am
by mariakrgrg
I created a new plugin editing the CoupledBushingForce plugin from the tutorial examples.
Building is successful but when I load it in the OpenSim GUI I get this error:
Error trying to load library osimMyACLPlugin. Library not loaded.
Here is the code

HEADER FILE

Code: Select all

#ifndef __MyACL_h__
#define __MyACL_h__
/* -------------------------------------------------------------------------- *
 *                      OpenSim:  MyACL.h                       *
 * -------------------------------------------------------------------------- *

// INCLUDE
#include <string>
#include <OpenSim/Simulation/Model/GeometryPath.h>
#include <OpenSim/Common/SimmSpline.h>
#include <OpenSim/Common/PropertyStr.h>
#include <OpenSim/Common/PropertyDblVec.h>
#include <OpenSim/Simulation/Model/Ligament.h>
#include "osimPluginDLL.h"

namespace OpenSim {
class OSIMPLUGIN_API MyACL: public Ligament {
OpenSim_DECLARE_CONCRETE_OBJECT(MyACL, Ligament);

//=============================================================================
// METHODS
//=============================================================================
public:
	// CONSTRUCTION
	MyACL();
	/*virtual ~MyACL();*/


	//SET 
	//void setBody1ByName(std::string aBodyName);
	//void setBody1BushingLocation(SimTK::Vec3 location, SimTK::Vec3 orientation=SimTK::Vec3(0));
	//void setBody2ByName(std::string aBodyName);
	//void setBody2BushingLocation(SimTK::Vec3 location, SimTK::Vec3 orientation=SimTK::Vec3(0));


	//--------------------------------------------------------------------------
	// COMPUTATION
	//--------------------------------------------------------------------------
	virtual void computeForce(const SimTK::State& s, 
							  SimTK::Vector_<SimTK::SpatialVec>& bodyForces, 
							  SimTK::Vector& generalizedForces) const;

	//--------------------------------------------------------------------------
	// Display
	//--------------------------------------------------------------------------
	//virtual const VisibleObject* getDisplayer() const;
	//virtual void updateDisplayer(const SimTK::State& s) const;

protected:
    /** Override this method if you would like to calculate a color for use
    when the %Ligament's path is displayed in the visualizer. You do not have 
    to invoke the base class ("Super") method, just replace it completely. This
    method will be invoked during realizeDynamics() so the supplied \a state has 
    already been realized through Stage::Velocity and you can access time, 
    position, and velocity dependent quantities. You must \e not attempt to 
    realize the passed-in \a state any further since we are already in the 
    middle of realizing here. Return SimTK::Vec3(SimTK::NaN) if you want to 
    leave the color unchanged (that's what the base class implementation does).

    @param[in] state    
        A SimTK::State already realized through Stage::Velocity. Do not 
        attempt to realize it any further.
    @returns 
        The desired color for the path as an RGB vector with each
        component ranging from 0 to 1, or NaN to indicate that the color
        should not be changed. **/
    virtual SimTK::Vec3 computePathColor(const SimTK::State& state) const;

    // Implement ModelComponent interface.
    /** Extension of parent class method; derived classes may extend further. **/
	void connectToModel(Model& aModel) OVERRIDE_11;
	/**
	 * Create a SimTK::Force which implements this MyACL as part of the SimTK::MultibodySystem.
	 */
	void addToSystem(SimTK::MultibodySystem& system) const OVERRIDE_11;
    /** Extension of parent class method; derived classes may extend further. **/
    void realizeDynamics(const SimTK::State& state) const OVERRIDE_11;

	//Force reporting
	/** 
	 * Methods to query a Force for the value actually applied during simulation
	 * The names of the quantities (column labels) is returned by this first function
	 * getRecordLabels()
	 */
	OpenSim::Array<std::string> getRecordLabels() const {
		OpenSim::Array<std::string> labels("");
		labels.append(getName());
		return labels;
	}
	/**
	 * Given SimTK::State object extract all the values necessary to report forces, application location
	 * frame, etc. used in conjunction with getRecordLabels and should return same size Array
	 */
	OpenSim::Array<double> getRecordValues(const SimTK::State& state) const {
		OpenSim::Array<double> values(1);
		values.append(getTension(state));
		return values;
	}

private:
	//void setupProperties();
	void constructProperties();

//=============================================================================
};	// END of class MyACL
//=============================================================================
//=============================================================================

} // end of namespace OpenSim

#endif // __MyACL_h__


SOURCE FILE

Code: Select all

/* -------------------------------------------------------------------------- *
 *                     OpenSim:  MyACL.cpp                      *
 * -------------------------------------------------------------------------- *
//=============================================================================
// INCLUDES
//=============================================================================
#include <OpenSim/Simulation/Model/BodySet.h>
#include <OpenSim/Simulation/Model/Model.h>

#include "MyACL.h"

//=============================================================================
// STATICS
//=============================================================================
using namespace std;
using namespace SimTK;
using namespace OpenSim;

static const Vec3 DefaultLigamentColor(.9,.9,.9); // mostly white 

//=============================================================================
// CONSTRUCTOR(S) AND DESTRUCTOR
//=============================================================================
//_____________________________________________________________________________
/**
 * Destructor.
 */
//MyACL::~MyACL()
//{
//}
//_____________________________________________________________________________
/**
 * Default constructor.
 */
MyACL::MyACL() : Ligament()
{

	constructProperties();
}

void MyACL::computeForce(const SimTK::State& s, 
							  SimTK::Vector_<SimTK::SpatialVec>& bodyForces, 
							  SimTK::Vector& generalizedForces) const
{
	Super::computeForce( s, bodyForces, generalizedForces);
}


void MyACL::constructProperties()
{
	setAuthors("Peter Loan");
	constructProperty_GeometryPath(GeometryPath());
	constructProperty_resting_length(0.0);
	constructProperty_pcsa_force(0.0);

	int forceLengthCurvePoints = 13;
	double forceLengthCurveX[] = {-5.00000000,  3.20000000,  3.30000000,  3.40000000,  3.45000000,  3.50000000,  3.60000000,  3.70000000,  3.75000000,  3.80000000,  3.85000000,  3.92000000,  5.00000000};
	double forceLengthCurveY[] = {0.00000000,  0.00000000,  0.04069010,  0.16276042,  0.25431315,  0.36621094,  0.65104167,  1.01725260,  1.23087565,  1.46484375,  1.71915690,  2.10937500,  2.66250000};
	SimmSpline forceLengthCurve
       (forceLengthCurvePoints, forceLengthCurveX, forceLengthCurveY);

	constructProperty_force_length_curve(forceLengthCurve);
}

//_____________________________________________________________________________
/**
 * Update the visible object used to represent the Ligament.
 */
//void MyACL::updateDisplayer(const SimTK::State& s) const
//{
//	getGeometryPath().updateDisplayer(s);
//}

//------------------------------------------------------------------------------
//                            REALIZE DYNAMICS
//------------------------------------------------------------------------------
// See if anyone has an opinion about the path color and change it if so.
void MyACL::realizeDynamics(const SimTK::State& state) const {
    Super::realizeDynamics(state); // Mandatory first line

	if(!isDisabled(state)){
		const SimTK::Vec3 color = computePathColor(state);
		if (!color.isNaN())
			getGeometryPath().setColor(state, color);
	}
}

//------------------------------------------------------------------------------
//                          COMPUTE PATH COLOR
//------------------------------------------------------------------------------
// This is the Ligament base class implementation for choosing the path
// color. Derived classes can override this with something meaningful.
// TODO: should the default attempt to use the ligament tension to control
// colors? Not sure how to scale.
SimTK::Vec3 MyACL::computePathColor(const SimTK::State& state) const {
    return SimTK::Vec3(SimTK::NaN);
}

//------------------------------------------------------------------------------
//                            CONNECT TO MODEL
//------------------------------------------------------------------------------
/**
 * Perform some setup functions that happen after the
 * ligament has been deserialized or copied.
 *
 * @param aModel model containing this ligament.
 */
void MyACL::connectToModel(Model& aModel)
{
	GeometryPath& path = upd_GeometryPath();
	const double& restingLength = get_resting_length();

    path.setDefaultColor(DefaultLigamentColor);

	// Specify underlying ModelComponents prior to calling 
    // Super::connectToModel() to automatically propagate connectToModel()
    // to subcomponents. Subsequent addToSystem() will also be automatically
	// propagated to subcomponents.
    // TODO: this is awkward; subcomponent API needs to be revisited (sherm)
	includeAsSubComponent(&path);

    //TODO: can't call this at start of override; this is an API bug.
	Super::connectToModel(aModel);

	// _model will be NULL when objects are being registered.
	if (_model == NULL)
		return;

	// Resting length must be greater than 0.0.
	assert(restingLength > 0.0);

	path.setOwner(this);
}

//------------------------------------------------------------------------------
//                             ADD TO SYSTEM
//------------------------------------------------------------------------------
/**
 * allocate and initialize the SimTK state for this ligament.
 */
 void MyACL::addToSystem(SimTK::MultibodySystem& system) const
{
	Super::addToSystem(system);
	// Cache the computed tension and strain of the ligament
	addCacheVariable<double>("tension", 0.0, SimTK::Stage::Velocity);
	addCacheVariable<double>("strain", 0.0, SimTK::Stage::Velocity);
}
EDIT: before editing the code of the example plugin, it was being loaded successfully from OpenSim GUI. So, I guess there is a problem in my new code.

Re: Load plugin fails

Posted: Sun Jun 01, 2014 8:47 am
by mariakrgrg
Any help???? :?

Re: Load plugin fails

Posted: Mon Jun 02, 2014 9:40 am
by aymanh
Hi Maria,

Since the plugin was loading in the GUI before your edits I assume the compiler/environment are all good and that it's your code change. I'd look into the costructor specifically as loading the dll invokes the constructor code through the call to registerTypes. I see you have a call to constructProperties inside the constructor, this should only construct properties that are new to your class (for example GeometryPath is already provided by the Ligament class you're deriving from). Please check this code and let us know if you continue to have problems or have specific questions.

Best regards,
-Ayman

Re: Load plugin fails

Posted: Wed Jun 04, 2014 8:37 am
by mariakrgrg
SOLVED.

You were right, all i had to do was to erase

Code: Select all

constructProperties();
from the constructor.

But I thought it was just something unnecessary, why should it create such a big trouble? :roll: