Can't run the example C++ code simple arm whose elbow is actuated by a muscle, provided in opensim-core github readme

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
veerendra v
Posts: 6
Joined: Wed May 16, 2018 5:03 am

Can't run the example C++ code simple arm whose elbow is actuated by a muscle, provided in opensim-core github readme

Post by veerendra v » Wed May 16, 2018 5:12 am

I have built the opensim in ubuntu 16.04 successfully. But while running the example (simple arm whose elbow is articulated by a muscle) using the C++ interface provided in the readme i got the below error. Even after including the path to the directory containing Xml.h, it is still showing the same error.
where did i go wrong? can someone help me.

Here's the source code

Code: Select all

#include <OpenSim/OpenSim.h>
using namespace SimTK;
using namespace OpenSim;

int main() {
    Model model;
    model.setName("bicep_curl");
    model.setUseVisualizer(true);

    // Create two links, each with a mass of 1 kg, center of mass at the body's
    // origin, and moments and products of inertia of zero.
    OpenSim::Body* humerus = new OpenSim::Body("humerus", 1, Vec3(0), Inertia(0));
    OpenSim::Body* radius  = new OpenSim::Body("radius",  1, Vec3(0), Inertia(0));

    // Connect the bodies with pin joints. Assume each body is 1 m long.
    PinJoint* shoulder = new PinJoint("shoulder",
            // Parent body, location in parent, orientation in parent.
            model.getGround(), Vec3(0), Vec3(0),
            // Child body, location in child, orientation in child.
            *humerus, Vec3(0, 1, 0), Vec3(0));
    PinJoint* elbow = new PinJoint("elbow",
            *humerus, Vec3(0), Vec3(0), *radius, Vec3(0, 1, 0), Vec3(0));

    // Add a muscle that flexes the elbow.
    Millard2012EquilibriumMuscle* biceps = new
        Millard2012EquilibriumMuscle("biceps", 200, 0.6, 0.55, 0);
    biceps->addNewPathPoint("origin",    *humerus, Vec3(0, 0.8, 0));
    biceps->addNewPathPoint("insertion", *radius,  Vec3(0, 0.7, 0));

    // Add a controller that specifies the excitation of the muscle.
    PrescribedController* brain = new PrescribedController();
    brain->addActuator(*biceps);
    // Muscle excitation is 0.3 for the first 0.5 seconds, then increases to 1.
    brain->prescribeControlForActuator("biceps",
            new StepFunction(0.5, 3, 0.3, 1));

    // Add components to the model.
    model.addBody(humerus);    model.addBody(radius);
    model.addJoint(shoulder);  model.addJoint(elbow);
    model.addForce(biceps);
    model.addController(brain);

    // Add a console reporter to print the muscle fiber force and elbow angle.
    ConsoleReporter* reporter = new ConsoleReporter();
    reporter->set_report_time_interval(1.0);
    reporter->addToReport(biceps->getOutput("fiber_force"));
    reporter->addToReport(
        elbow->getCoordinate(PinJoint::Coord::RotationZ).getOutput("value"),
        "elbow_angle");
    model.addComponent(reporter);

    // Add display geometry.
    Ellipsoid bodyGeometry(0.1, 0.5, 0.1);
    bodyGeometry.setColor(Gray);
    // Attach an ellipsoid to a frame located at the center of each body.
    PhysicalOffsetFrame* humerusCenter = new PhysicalOffsetFrame(
        "humerusCenter", "humerus", Transform(Vec3(0, 0.5, 0)));
    humerus->addComponent(humerusCenter);
    humerusCenter->attachGeometry(bodyGeometry.clone());
    PhysicalOffsetFrame* radiusCenter = new PhysicalOffsetFrame(
        "radiusCenter", "radius", Transform(Vec3(0, 0.5, 0)));
    radius->addComponent(radiusCenter);
    radiusCenter->attachGeometry(bodyGeometry.clone());

    // Configure the model.
    State& state = model.initSystem();
    // Fix the shoulder at its default angle and begin with the elbow flexed.
    shoulder->getCoordinate().setLocked(state, true);
    elbow->getCoordinate().setValue(state, 0.5 * Pi);
    model.equilibrateMuscles(state);

    // Configure the visualizer.
    model.updMatterSubsystem().setShowDefaultGeometry(true);
    Visualizer& viz = model.updVisualizer().updSimbodyVisualizer();
    viz.setBackgroundType(viz.SolidColor);
    viz.setBackgroundColor(White);

    // Simulate.
    simulate(model, state, 10.0);

    return 0;
};

github url: https://github.com/opensim-org/opensim-core
Attachments
Screenshot from 2018-05-16 17-38-40.png
Screenshot from 2018-05-16 17-38-40.png (83.54 KiB) Viewed 380 times

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Can't run the example C++ code simple arm whose elbow is actuated by a muscle, provided in opensim-core github readm

Post by Christopher Dembia » Wed May 16, 2018 8:36 am

Did you base your CMakeLists.txt off of the SampleCMakeLists.txt in the opensim-core install folder?

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Can't run the example C++ code simple arm whose elbow is actuated by a muscle, provided in opensim-core github readm

Post by Christopher Dembia » Wed May 16, 2018 8:37 am

What is the value OPENSIM_COPY_DEPENDENCIES that you used when building opensim-core? Did you delete the simbody install directory?

User avatar
veerendra v
Posts: 1
Joined: Sun Mar 25, 2018 12:40 am

Re: Can't run the example C++ code simple arm whose elbow is actuated by a muscle, provided in opensim-core github readm

Post by veerendra v » Thu May 24, 2018 8:17 am

Hi Christopher..! Thanks for pointing out SampleCMakeLists.txt. While searching for it, I've found some examples in opensim-core/OpenSim/Examples of the cloned git source. The problem has been resolved after modifying the CMakeLists.txt of BuildDynamicWalker example. I think the below section of CMakeLists.txt caused the problem.

Code: Select all

find_package(OpenSim 4.0 REQUIRED PATHS "${OPENSIM_INSTALL_DIR}")
Thanks a lot.

POST REPLY