Moving model in Python

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Csongor Barabasi
Posts: 6
Joined: Thu Oct 18, 2018 12:17 am

Moving model in Python

Post by Csongor Barabasi » Mon Nov 19, 2018 2:44 am

Hey OpenSimmers :D

Thanks to this awesome community I managed to load and visualize an OpenSim model like this:

import opensim
m = opensim.Model('<filename>')
m.setUseVisualizer(True)
state = m.initSystem()
m.getVisualizer().show(state)

Then I managed to get out body parts like this:

self.muscleSet = self.model.getMuscles()
self.forceSet = self.model.getForceSet()
self.bodySet = self.model.getBodySet()
self.jointSet = self.model.getJointSet()
self.markerSet = self.model.getMarkerSet()

Now my question would be, how can I start moving the body? For example raise right hand.

Thanks for your help!

Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Moving model in Python

Post by jimmy d » Mon Nov 19, 2018 7:47 am

Please go through the Examples and Tutorials to learn about using OpenSim and how it works. The User Guide and Scripting sections are also important to go through. Finally, this Simple Arm example simulation seems relevant

User avatar
Csongor Barabasi
Posts: 6
Joined: Thu Oct 18, 2018 12:17 am

Re: Moving model in Python

Post by Csongor Barabasi » Tue Nov 20, 2018 7:00 am

Well that's what I did, but it is a tiny bit unclear.

So I understand that I have to create a PrescribedController() and here I add the muscles with their activation.

But then I don't know how to control them.

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Moving model in Python

Post by jimmy d » Tue Nov 20, 2018 7:26 am

The below code instantiates a Prescribed a controller and sets the Controls for the controller.

Code: Select all

brain = osim.PrescribedController()
brain.addActuator(biceps)
brain.prescribeControlForActuator("biceps",
                                  osim.StepFunction(0.5, 3.0, 0.3, 1.0))
There are a few controller types, than can be studied in the API documentation (expand the inheritance diagram at the top), but you will probably be using the Prescribed Controller mostly if you are just trying to get actuators to move the model.

User avatar
Csongor Barabasi
Posts: 6
Joined: Thu Oct 18, 2018 12:17 am

Re: Moving model in Python

Post by Csongor Barabasi » Tue Nov 20, 2018 7:40 am

Yes, so that is exactly what I did so far. But as a function I used Constant. So the muscle activation has a constant value. And now I would like to change this value to another constant ... I don't want to exhibit a full movement, just a change in the body pose. So for example change the biceps muscle activation to 1 (fully activated), so the elbow joint will bend and so on. This is where I am stuck. Doing one change, or multiple changes for each muscle. But if I know how to do it for one, then its just about looping through them all.

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Moving model in Python

Post by jimmy d » Tue Nov 20, 2018 9:02 am

You will have to define a function to pass to the PrescribedController(). There are numerous Function sub-classes, you will just have to design your control signal using these.

POST REPLY