Hey OpenSimmers
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!
Moving model in Python
- Csongor Barabasi
- Posts: 6
- Joined: Thu Oct 18, 2018 12:17 am
Re: Moving model in Python
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
- Csongor Barabasi
- Posts: 6
- Joined: Thu Oct 18, 2018 12:17 am
Re: Moving model in Python
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.
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.
Re: Moving model in Python
The below code instantiates a Prescribed a controller and sets the Controls for the controller.
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.
Code: Select all
brain = osim.PrescribedController()
brain.addActuator(biceps)
brain.prescribeControlForActuator("biceps",
osim.StepFunction(0.5, 3.0, 0.3, 1.0))
- Csongor Barabasi
- Posts: 6
- Joined: Thu Oct 18, 2018 12:17 am
Re: Moving model in Python
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.
Re: Moving model in Python
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.