Code: Select all
#include "McKibbenActuator.h"
#include <OpenSim/OpenSim.h>
using namespace OpenSim;
using namespace SimTK;
//______________________________________________________________________________
/**
* First exercise: create a model that does nothing.
*/
int main()
{
try {
// Create an OpenSim model and set its name
Model arm;
arm.setName("armSimple");
// Get a reference to the model's ground body
OpenSim::Body& ground = arm.getGroundBody();
//Add display geometry to the ground to visualize in the GUI
ground.addDisplayGeometry("ground_ribs.vtp");
ground.addDisplayGeometry("ground_spine.vtp");
ground.addDisplayGeometry("ground_skull.vtp");
ground.addDisplayGeometry("ground_jaw.vtp");
ground.addDisplayGeometry("ground_r_clavicle.vtp");
ground.addDisplayGeometry("ground_scapula.vtp");
//Save the model to a file
//Specify properties of humurus
double humurusMass = 1.99757;
Vec3 humurusMassCenter(0.01806404, -0.14014073, -0.01274600);
SimTK::Inertia humurusInertia(0.01227763,0.00255133, 0.01257888,-0.00034741, -0.00023250, 0.00122930 );
// Create a new block body with specified properties
OpenSim::Body *humurus = new OpenSim::Body("humurus", humurusMass, humurusMassCenter, humurusInertia);
// Add display geometry to the block to visualize in the GUI
humurus->addDisplayGeometry("humurus.vtp");
double ulnaMass = 1.10530000;
Vec3 ulnaMassCenter(0.00971783, -0.09595089, 0.02428600);
SimTK::Inertia ulnaInertia(0.00541309, 0.00115318, 0.00494361, 0.00031686, -0.00007615, 0.00109169);
// Create a new block body with specified properties
OpenSim::Body *ulna = new OpenSim::Body("ulna", ulnaMass, ulnaMassCenter, ulnaInertia);
// Add display geometry to the block to visualize in the GUI
ulna->addDisplayGeometry("ulna.vtp");
// Create a new custom joint with 6 DoF(coordinates) between the humurus and ulna bodies
Vec3 locationInParent(0.00610000, - 0.29040000, - 0.01230000), orientationInParent(0), locationInBody(0), orientationInBody(0);
FreeJoint *elbow = new FreeJoint("elbow", *humurus, locationInParent, orientationInParent, *ulna, locationInBody, orientationInBody,false);
// Get a reference to the coordinate set (6 degrees-of-freedom) between the block and ground bodies
CoordinateSet& jointCoordinateSet = elbow->upd_CoordinateSet();
// Set the angle and position ranges for the coordinate set (SimTK:: prefix not actually needed here)
double angleRange[2] = { -SimTK::Pi / 2, SimTK::Pi / 2 };
double positionRange[2] = { -1, 1 };
jointCoordinateSet[0].setRange(angleRange);
jointCoordinateSet[1].setRange(angleRange);
jointCoordinateSet[2].setRange(angleRange);
jointCoordinateSet[3].setRange(positionRange);
jointCoordinateSet[4].setRange(positionRange);
jointCoordinateSet[5].setRange(positionRange);
McKibbenActuator *actuator = new McKibbenActuator("humurus", "ulna");
arm.addBody(humurus);
arm.addBody(ulna);
arm.print("armSimple_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;
}
When I try to open the .osim file in OpenSim3.3 GUI, the GUI just flashed and I don't know why.
Also, I installed the OpenSim3.3 on Win7.
Hope to get some help from you.
Thanks!
Best,
Ruoshi Wen