reading real time rotations
- Bernardo Costa
- Posts: 12
- Joined: Tue Jul 16, 2019 11:56 am
reading real time rotations
Is it possible to pass real time data to opensim models? By data, I mean rotations of skeleton bones. If there is no out-of-the-box solution for now, would it be possible to build a solution by means of a script or perhaps a plugin?
Tags:
- Bernardo Costa
- Posts: 12
- Joined: Tue Jul 16, 2019 11:56 am
Re: reading real time rotations
I tried to install rtosim but it failed. For some reason, it can't find simbody headers while compiling.
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: reading real time rotations
The README.md file on the GitHub page (https://github.com/RealTimeBiomechanics/rtosim) includes a "Contacts" section near the bottom with instructions for where to go for help with RTOSIM.
- Bernardo Costa
- Posts: 12
- Joined: Tue Jul 16, 2019 11:56 am
Re: reading real time rotations
After studying rtosim, opensim and simtk for a while, I have found that, for now, I don't need to use rtosim and that there are other ways to do what I want to. It seems that it is possible to update joint rotation values for a previoulsy opened model in opensim using a python script. This would be the same as changing those values using the GUI. However, I couldn't get exactly where is the data of each joint rotation (or the particular one that I want to update) and how do I update this value. Is there a code example for this?
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: reading real time rotations
There are example scripts in your Resources\Code\Python directory (see, for example, https://github.com/opensim-org/opensim- ... el.py#L154).
- Bernardo Costa
- Posts: 12
- Joined: Tue Jul 16, 2019 11:56 am
Re: reading real time rotations
Ok, so here is what I did. The code below executed in the scripting shell window is able to read and dump the rotational coordinates of a loaded model. I used the Arm26 model.
Then, I changed the coordinate reading for writing in the code below. However, these changes are not shown in the visualizer window. If I print the values, the newly updated values are shown. Why it does not show these new rotations in the visualizer window? I thought that reassembling the model with the updated state would update the UI.
Code: Select all
model = getCurrentModel()
state_ref = getStateRef(model)
cd_set = model.getCoordinateSet()
for i in range(cd_set.getSize()):
print('i = ',i,' coordinate = ',cd_set.get(i).getValue(state_ref))
Code: Select all
model = getCurrentModel()
state_ref = getStateRef(model)
cd_set = model.getCoordinateSet()
for i in range(cd_set.getSize()):
cd_set.get(i).setValue(state_ref,0,False)
model.assemble(state_ref)
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: reading real time rotations
Hello,
The code snippet you wrote is reasonable with the caveat that you should not modify the state under the model while loaded in the application as there's nothing that propagates state changes to the variety of windows/tools that are currently open (there're methods for that specific to the GUI scripting shell). We should make this more prominent but you can verify for yourself if your code works by loading a model in a python script, modifying coordinates, saving, then loading it in the GUI. Keep in mind that Rotational coordinates are in radians.
Hope this helps,
-Ayman
The code snippet you wrote is reasonable with the caveat that you should not modify the state under the model while loaded in the application as there's nothing that propagates state changes to the variety of windows/tools that are currently open (there're methods for that specific to the GUI scripting shell). We should make this more prominent but you can verify for yourself if your code works by loading a model in a python script, modifying coordinates, saving, then loading it in the GUI. Keep in mind that Rotational coordinates are in radians.
Hope this helps,
-Ayman
- Bernardo Costa
- Posts: 12
- Joined: Tue Jul 16, 2019 11:56 am
Re: reading real time rotations
Well, good to know that I have successfully changed values. However, what I really want for now is visualizing these changes in the UI. But it seems that this is not the correct way of doing it. Is there a way - through scripting or maybe other options - to make changes in joint rotations appear in the UI as they are updated?
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: reading real time rotations
You could try using the API Visualizer (https://simtk-confluence.stanford.edu/d ... Visualizer). There's an example that uses it on the main GitHub page (https://github.com/opensim-org/opensim-core, scroll down to "Simple example").