Page 1 of 2
reading real time rotations
Posted: Fri Nov 01, 2019 1:11 pm
by bfcosta
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?
Re: reading real time rotations
Posted: Sun Nov 03, 2019 3:52 pm
by aafox
Hi Bernardo,
Perhaps check out this project -
https://simtk.org/projects/rtosim
Aaron
Re: reading real time rotations
Posted: Tue Nov 05, 2019 12:29 pm
by bfcosta
I tried to install rtosim but it failed. For some reason, it can't find simbody headers while compiling.
Re: reading real time rotations
Posted: Tue Nov 05, 2019 1:46 pm
by tkuchida
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.
Re: reading real time rotations
Posted: Fri Jan 03, 2020 11:14 am
by bfcosta
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?
Re: reading real time rotations
Posted: Sat Jan 04, 2020 9:29 am
by tkuchida
There are example scripts in your Resources\Code\Python directory (see, for example,
https://github.com/opensim-org/opensim- ... el.py#L154).
Re: reading real time rotations
Posted: Thu Jan 09, 2020 12:03 pm
by bfcosta
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.
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))
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()):
cd_set.get(i).setValue(state_ref,0,False)
model.assemble(state_ref)
Re: reading real time rotations
Posted: Fri Jan 10, 2020 11:42 am
by aymanh
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
Re: reading real time rotations
Posted: Fri Jan 10, 2020 5:48 pm
by bfcosta
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?
Re: reading real time rotations
Posted: Sat Jan 11, 2020 9:24 am
by tkuchida
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").