Page 1 of 1

Simple example/template

Posted: Tue Oct 13, 2020 7:40 pm
by rahid
Hello,

Can I have a simple API example in C++, where
- an .osim file is called
- a motion file (.mot) is used to move the model
- show the model and motion in the visualizer.

It would be great if, in that template, the static optimization is run and show the simulation in the visualizer.


Thanks,
Rahid

Re: Simple example/template

Posted: Thu Oct 15, 2020 2:37 am
by mitkof6
Hi Rahid,

Here is an example code for updating the model's pose in Python:

https://github.com/mitkof6/symbolic_mom ... 40.py#L301

If you have the model visualization set to true:

https://github.com/mitkof6/OpenSim_API_ ... s.cpp#L218

the visualizer will be opened. Then you can visualize the current pose using the state:

https://github.com/mitkof6/OpenSim_API_ ... s.cpp#L222

You can check some of the examples I use to demonstrate the use of OpenSim in C++:

https://github.com/mitkof6/OpenSim_API_tutorial

The use of static optimization is a bit tricky and hard to explain if you are new to the API.

Re: Simple example/template

Posted: Thu Oct 15, 2020 2:13 pm
by rahid
Hi Dimitar,

Thank you for your response. These are really helpful.
I used static optimization before using the GUI. Also, I understand the xml file settings for static optimization.

But, I do not have clear idea about how to use static optimization class in visual studio directly. I could not find any example on that. Probably, I will use the xml settings to run the static optimization.

I appreciate your help.

Re: Simple example/template

Posted: Thu Oct 15, 2020 2:27 pm
by mitkof6
Yes, the best option is to use the xml setup files, because it is very easy to mess things up. If you are interested in this post you can find the Python code to run static optimization without the setup file:

https://github.com/opensim-org/opensim-core/issues/2076

Re: Simple example/template

Posted: Thu Oct 15, 2020 2:41 pm
by rahid
Thank you for the link. I am not good at python. But, I think I've got the idea from there about how to implement it.

I don't know why, but I felt that people like to use Matlab and Python for OpenSim 4.x API than C++. Is there any specific reason or it is just a personal preference? Do I still need to use Cmake for Matlab or Python?

Again, thanks for your time.

Re: Simple example/template

Posted: Fri Oct 16, 2020 12:13 am
by mitkof6
For Python and Matlab you do not have to use CMake.

People typically use them since it is easy to test and prototype ideas. Most people are used to work with Matlab. Also, the C++ building system is cumbersome. However, some things are not possible to do in Python and Matlab and that is why it is useful to use the C++ API.

Re: Simple example/template

Posted: Fri Oct 16, 2020 9:47 pm
by rahid
Thank you, Dimitar.