pendulum

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
ARFA Essosnam
Posts: 24
Joined: Thu Oct 15, 2015 4:03 am

pendulum

Post by ARFA Essosnam » Wed Mar 02, 2016 8:18 am

I have done a simple pendulum in opensim and run a forward dynamic.
Now I want to use two muscles to generate the pendulum movement but I don't know how to do that.
can anyone give me a hand please? :(
I'am using Visual basic to perform my work.

here you are my code.




// Author:

//==============================================================================
//==============================================================================
#include <OpenSim/OpenSim.h>

using namespace OpenSim;
using namespace SimTK;
using namespace std;

//______________________________________________________________________________
/**
*
*/
int main()
{
try {

double tigeMass = 1.0, tigeSideLength = 0.1, rayon =0.0025 ;


// Create an OpenSim model and set its name
Model osimModel;
osimModel.setName("PENDULE");

// GROUND BODY
// Get a reference to the model's ground body
OpenSim::Body& ground = osimModel.getGroundBody();


// add a ground geometry
ground.addDisplayGeometry("ground_catia.stl");

GeometrySet& geometry = ground.updDisplayer()->updGeometrySet();
DisplayGeometry& block1 = geometry[0];
//scale the blocks
block1.setScaleFactors(Vec3(1, 1, 1));
// reposition the blocks
block1.setTransform(Transform(Vec3(0, 0, 0)));

// TIGE BODY
Vec3 tigeMassCenter(0);
Inertia tigeInertia = tigeMass*Inertia::cylinderAlongY(rayon, tigeSideLength);

// Create a new block body with the specified properties
OpenSim::Body *tige = new OpenSim::Body("tige", tigeMass, tigeMassCenter, tigeInertia);

// Add display geometry to the block to visualize in the GUI
tige->addDisplayGeometry("cylindre.stl");

tige->updDisplayer()->setScaleFactors(Vec3(1,1,1));

// Section: Create the Tige Joint
// Create the joint connection the tige to the ground
Vec3 locationInParent(0.0,0.0,0.0);
Vec3 orientationInParent(0.0,0.0,0);
Vec3 locationInChild(0.0,50,0.0);
Vec3 orientationInChild(0.0,0.0,0);
PinJoint *tigeToGround = new PinJoint("tigeToGround", ground, locationInParent, orientationInParent, *tige, locationInChild, orientationInChild, false);


// A pin joint consists of a single coordinate describing a change in orientation about the Z axis
CoordinateSet &tigeJoints = tigeToGround->upd_CoordinateSet();
tigeJoints[0].setName("tige_rz");
double rotRangePlatform[2] = {-50*Pi/180.0, 50*Pi/180.0};
tigeJoints[0].setDefaultValue(convertDegreesToRadians(-10.0));
tigeJoints[0].setRange(rotRangePlatform);




// Add the tige body to the model
osimModel.addBody(tige);

// Define the initial and final simulation times
double initialTime = 0.0;
double finalTime = 3.0;



// GRAVITY
// Obtaine the default acceleration due to gravity
// Define the acceleration of gravity
osimModel.setGravity(Vec3(0,-9.80665,0));


// Initialize the system
SimTK::State& si = osimModel.initSystem();

//add t


// Define non-zero (defaults are 0) states for the free joint
CoordinateSet& modelCoordinateSet = osimModel.updCoordinateSet();


// set speed value of the tige
modelCoordinateSet[0].setSpeedValue(si, 0.2);


// Create the integrator and manager for the simulation.
SimTK::RungeKuttaMersonIntegrator integrator(osimModel.getMultibodySystem());
integrator.setAccuracy(1.0e-4);
Manager manager(osimModel, integrator);

// Integrate from initial time to final time
manager.setInitialTime(initialTime);
manager.setFinalTime(finalTime);
std::cout<<"\n\nIntegrating from "<<initialTime<<" to " <<finalTime<<std::endl;
manager.integrate(si);



// Save the simulation results
Storage statesDegrees(manager.getStateStorage());
statesDegrees.print("pendule_states.sto");
osimModel.updSimbodyEngine().convertRadiansToDegrees(statesDegrees);
statesDegrees.setWriteSIMMHeader(true);
statesDegrees.print("pendule_degrees.mot");




// Save the model to a file
osimModel.print("pendule_model.osim");
}

catch (OpenSim::Exception ex)
{
std::cout << ex.getMessage() << std::endl;
return 1;
}
catch (std::exception ex)
{
std::cout << ex.what() << std::endl;
return 1;
}
catch (...)
{
std::cout << "UNRECOGNIZED EXCEPTION" << std::endl;
return 1;
}



std::cout << "OpenSim example completed successfully.\n";
std::cin.get();
return 0;
}

POST REPLY