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
Simple example/template
- Rahid Zaman
- Posts: 31
- Joined: Fri Apr 21, 2017 3:43 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Simple example/template
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.
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.
- Rahid Zaman
- Posts: 31
- Joined: Fri Apr 21, 2017 3:43 am
Re: Simple example/template
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.
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.
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Simple example/template
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
https://github.com/opensim-org/opensim-core/issues/2076
- Rahid Zaman
- Posts: 31
- Joined: Fri Apr 21, 2017 3:43 am
Re: Simple example/template
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.
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.
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Simple example/template
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.
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.
- Rahid Zaman
- Posts: 31
- Joined: Fri Apr 21, 2017 3:43 am
Re: Simple example/template
Thank you, Dimitar.