Unable to use PiecewiseConstantFunction through the API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Jakob Welner
Posts: 23
Joined: Mon Dec 15, 2014 3:24 pm

Unable to use PiecewiseConstantFunction through the API

Post by Jakob Welner » Thu Nov 12, 2015 2:57 pm

Hi,

For some reason I cannot seem to use the PiecewiseConstantFunction through the c++ API while I can easily use the PiecewiseLinearFunction.
Both header files are there, in the same directory (../simbody/sdk/include/OpenSim/Common), I've checked that my compiler actually looks for the Linear function in that directory, but still I cannot use the Constant function. The two header files also looks almost the same so I really don't get it.

It is probably a silly little thing I have done wrong but I have to ask if I am the only one experiencing this?

If I change the xml tags manually from the Linear to the Constant function and run my simulation it all works so I guess OpenSim internally recognizes it.

I'm using OpenSim 3.3 on Windows with VS2015 pro

Cheers

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: Unable to use PiecewiseConstantFunction through the API

Post by Ayman Habib » Fri Nov 13, 2015 12:23 pm

Hi Jakob,

The files (PiecewiseConstantFunction.h and PiecewiseLinearFunction.h) both live under the directory sdk\include\OpenSim\Common\ of the installation. I think your compiler is looking for the files in the wrong directory if it can find one and not the other. This maybe a CMake file issue or an issue with how CMake is configured or something specific to your environment. Maybe you can screencapture your CMake configuration screen and post it here.

Best of luck,
-Ayman

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

Re: Unable to use PiecewiseConstantFunction through the API

Post by Christopher Dembia » Fri Nov 13, 2015 10:13 pm

Are you attempting to include the file using `#include <OpenSim/Common/PiecewiseConstantFunction.h>` in your C++ file?

User avatar
Jakob Welner
Posts: 23
Joined: Mon Dec 15, 2014 3:24 pm

Re: Unable to use PiecewiseConstantFunction through the API

Post by Jakob Welner » Sat Nov 14, 2015 11:24 am

Hi and thank you for your reply.

If I write:

Code: Select all

#include <OpenSim/Common/PiecewiseConstantFunction.h>
then it works!

Thanks!

However, it appears to be a hack that shouldn't be necessary, right? At least when I can access all the other functions without it and I'm curious why this is happening - unless I misunderstand and it is supposed to be like this?
I checked again and the compiler is looking in the path mentioned by Ayman: "c:\\opensim33x32\sdk\include\OpenSim\Common\" but it only finds the Linear function, not the constant, despite both header files being in that directory.

I have attached a CMake screengrab and my includes look like this: (I'm using the PredictiveSim code from Dorn, Wang, Hicks and Delp.

Code: Select all

#include <iomanip>
#include <iostream>
#include <time.h>

#include <OpenSim/OpenSim.h>
#include <OpenSim/Common/IO.h>

// Messaging Passing Interface
#ifdef USE_MPI
#include <mpi.h>
#endif

#include "CMAOptimizer.h"
#include "GeyerHerrController.h"
#include "EventHandlers.h"
#include "SimpleMuscle.h"
#include "SoftCoordinateLimitForce.h"
#include "PredictiveOptimizationSystem.h"
#include "Utils.h"

using namespace std;
using namespace OpenSim;
using namespace SimTK;
Attachments
cmakeScreengrab.jpg
Screengrab og CMake setup for PredictiveSim

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

Re: Unable to use PiecewiseConstantFunction through the API

Post by Christopher Dembia » Mon Nov 16, 2015 11:20 am

Using that longer include line is not a hack, and it is fine for you to include files that way. However, you shouldn't *need* to do it that way.

The bug in OpenSim 3.3 is that PiecewiseConstantFunction.h does not appear in OpenSim/Common/osimCommon.h, which is supposed to grab all OpenSim Common headers (and is included by OpenSim/OpenSim.h).

However, there are reasons to include only the headers you need; mainly, to speed up compiling.

This bug is already fixed for the next major release of OpenSim.

POST REPLY