reading real time rotations

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Bernardo Costa
Posts: 12
Joined: Tue Jul 16, 2019 11:56 am

reading real time rotations

Post by Bernardo Costa » Fri Nov 01, 2019 1:11 pm

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:

User avatar
Aaron Fox
Posts: 291
Joined: Sun Aug 06, 2017 10:54 pm

Re: reading real time rotations

Post by Aaron Fox » Sun Nov 03, 2019 3:52 pm

Hi Bernardo,

Perhaps check out this project - https://simtk.org/projects/rtosim

Aaron

User avatar
Bernardo Costa
Posts: 12
Joined: Tue Jul 16, 2019 11:56 am

Re: reading real time rotations

Post by Bernardo Costa » Tue Nov 05, 2019 12:29 pm

I tried to install rtosim but it failed. For some reason, it can't find simbody headers while compiling.

User avatar
Thomas Uchida
Posts: 1794
Joined: Wed May 16, 2012 11:40 am

Re: reading real time rotations

Post by Thomas Uchida » Tue Nov 05, 2019 1:46 pm

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.

User avatar
Bernardo Costa
Posts: 12
Joined: Tue Jul 16, 2019 11:56 am

Re: reading real time rotations

Post by Bernardo Costa » Fri Jan 03, 2020 11:14 am

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?

User avatar
Thomas Uchida
Posts: 1794
Joined: Wed May 16, 2012 11:40 am

Re: reading real time rotations

Post by Thomas Uchida » Sat Jan 04, 2020 9:29 am

There are example scripts in your Resources\Code\Python directory (see, for example, https://github.com/opensim-org/opensim- ... el.py#L154).

User avatar
Bernardo Costa
Posts: 12
Joined: Tue Jul 16, 2019 11:56 am

Re: reading real time rotations

Post by Bernardo Costa » Thu Jan 09, 2020 12:03 pm

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)

User avatar
Ayman Habib
Posts: 2252
Joined: Fri Apr 01, 2005 12:24 pm

Re: reading real time rotations

Post by Ayman Habib » Fri Jan 10, 2020 11:42 am

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

User avatar
Bernardo Costa
Posts: 12
Joined: Tue Jul 16, 2019 11:56 am

Re: reading real time rotations

Post by Bernardo Costa » Fri Jan 10, 2020 5:48 pm

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?

User avatar
Thomas Uchida
Posts: 1794
Joined: Wed May 16, 2012 11:40 am

Re: reading real time rotations

Post by Thomas Uchida » Sat Jan 11, 2020 9:24 am

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").

POST REPLY