Simple example/template

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Rahid Zaman
Posts: 31
Joined: Fri Apr 21, 2017 3:43 am

Simple example/template

Post by Rahid Zaman » Tue Oct 13, 2020 7:40 pm

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

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Simple example/template

Post by Dimitar Stanev » Thu Oct 15, 2020 2:37 am

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.

User avatar
Rahid Zaman
Posts: 31
Joined: Fri Apr 21, 2017 3:43 am

Re: Simple example/template

Post by Rahid Zaman » Thu Oct 15, 2020 2:13 pm

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.

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Simple example/template

Post by Dimitar Stanev » Thu Oct 15, 2020 2:27 pm

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

User avatar
Rahid Zaman
Posts: 31
Joined: Fri Apr 21, 2017 3:43 am

Re: Simple example/template

Post by Rahid Zaman » Thu Oct 15, 2020 2:41 pm

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.

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Simple example/template

Post by Dimitar Stanev » Fri Oct 16, 2020 12:13 am

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.

User avatar
Rahid Zaman
Posts: 31
Joined: Fri Apr 21, 2017 3:43 am

Re: Simple example/template

Post by Rahid Zaman » Fri Oct 16, 2020 9:47 pm

Thank you, Dimitar.

POST REPLY