Home › Forum › SofaPython3 › Using SofaPython3 › SofaPython3 controllers documentation
Tagged: SOFA_2012, Windows_10
- This topic has 6 replies, 3 voices, and was last updated 3 years, 2 months ago by
Hugo.
-
AuthorPosts
-
26 May 2021 at 09:30 #19576
SergioPM23
BlockedHello everyone!
I would like to know where can I find documentation or explained examples about SofaPython3 controllers and SofaPython3 force fields. I am developing a scene in which I want to apply forces on several objects, not at the same time, but to apply these forces progressively to the objects at different moments of time. In this way, the simulation would start with no force on any object and would end with a force on all or several of them (on the ones I want to).
I have been using Sofa for a little period of time (we could say that I am a new user) and I do not know nothing about SofaPython3 controllers or SofaPython3 force fields, so I do not know if I should use a SofaPython3 controller, a SofaPython3 force field or both of them.
I would appreciate any help/documentation/suggestion.
Thanks in advance.Cheers,
Sergio.1 June 2021 at 08:14 #19619SergioPM23
BlockedIsn’t there any documentation about SofaPython3 controllers? I need to learn about them in order to do my final degree project succesfully.
1 June 2021 at 20:53 #19623Hugo
KeymasterHi @sergiopm23
Sorry for the latency.
Yes there is, you should find in the SofaPython3 plugin an example folder containing two examples:
– emptyController.py
– example-scriptcontroller.pyHope this helps.
Best wishesHugo
2 June 2021 at 12:02 #19625SergioPM23
Blocked@Hugo Okay, thanks for your response. I have already seen this two examples, but I would like to know more about how to controll time events (basically how to do actions on objects in a specific instant of the animation and during a specific period of time).
I have also seen another example (advanced_timer.py) which seems to controll time events, but I do not understand it clearly. Is not there any further documentation which explains more about time Python controllers?
I would appreciate any help. Thanks in advance.Cheers,
Sergio.8 June 2021 at 10:57 #19665SerkanErgunAAU
BlockedHi @sergiopm23 and @ Hugo,
I am also interested in this topic. The examples provided are unfortunately very basic.
I am looking into handling objects (such as setting the pose of a mechanical object -> to have an object rotate alongside a fixed axis) at each animation stepConsider the following as a minimal example, it misses plugins and definition of angle, n,…
class Controller(Sofa.Core.Controller) def __init__(self, *args, **kwargs): Sofa.Core.Controller.__init__(self, *args, *kwargs) def onAnimateBeginEvent(self, event): # called at each begin of animation step rotation=[0,angle[n],0] pass def createScene(rootNode): rootNode.gravity=[0,-9810,0] rootNode.dt=0.05 robot=rootNode.addOject("robot") baseJoint=robot.addObject("baseJoint") baseJoint=addObject("MechanicalObject",name="mstate",<strong>rotation</strong>) pythonController=robot.addObject(Controller(name="Controller", target=baseJoint))
I want the parameter rotation to be set via the controller for each animation step.
Edit, i think I now how to pass on data, but I am stuck on the right naming convention:
class Controller(Sofa.Core.Controller) def __init__(self, *args, **kwargs): Sofa.Core.Controller.__init__(self, *args, *kwargs) def onAnimateBeginEvent(self, event): # called at each begin of animation step rotation=[0,angle[n],0] ### self.engine.findData('rotation').value = rotation ### This is the way how it is done in SofaPython2 pass def createScene(rootNode): rootNode.gravity=[0,-9810,0] rootNode.dt=0.05 robot=rootNode.addOject("robot") baseJoint=robot.addObject("baseJoint") baseJoint=addObject("MechanicalObject",name="mstate",<strong>rotation</strong>) pythonController=robot.addObject(Controller(name="Controller", target=baseJoint)).
Furthermore I executed – emptyController.py
I do not get any feedback of key Events or mouse interactions during active simulation.
Do you experience the same issues?All the best,
Serkan11 June 2021 at 12:27 #19679Hugo
KeymasterYou are right more examples would be nice! Never hesitate to make such pull-requests it would be most appreciated by the dev community.
I will try to find some time to create new ones.
Best,
Hugo
11 June 2021 at 12:29 #19680Hugo
KeymasterBy the way have you taken a look at the example liver-scriptcontroller.py in the PR #146 ? It could help.
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.