Forum Replies Created
-
AuthorPosts
-
elieKBlocked
Hello Sara,
I am not sure if it could be a hotkey issue as I have never used Sofa on a mac. I have put the code on a drive below:
https://drive.google.com/drive/folders/1-MfPOVGQQQIxwVqzzRvpJwjnZ9iwnA7Z?usp=sharing
In this drive, there is both your modified implementation, and a second script testMesh-2.py. In this second script, I added the collision model and added the “TetrahedronSetTopologyContainer” as in the tutorial. Both scripts work for me, but you can try to see maybe adding these elements in testMesh-2.py could fix your issue. If not, could you add a print(c) command inside the onKeyPressed in the interaction class to check if it capturing the correct keys and if it is going into the conditional blocks.
Best regards,
ElieelieKBlockedHello Sarah,
If you take the complete code in the previous comment, you should be able to bend the finger with ctr M and ctr – in its initial position.
I saw that there is still an issue where the finger actuation doesn’t work when you move the finger too far from its original position, I think I found the issue: When creating the fixed box you need to specify that you don’t want it to update during the simulation. I also propose that you use a slightly bigger boxROI because a small portion of the finger is left out from below.
finger.createObject('BoxROI', name='boxROI', box='-20 20 70 20 -2 80', doUpdate=False, drawBoxes='true')
Replacing the line above in your code, I was able to move around the finger and bend it with no problems. Let me know if this works.
Best regards,
ElieelieKBlockedHello Sara,
I tried to change a bit in your test scene, I managed to move the finger.
Can you try to replace the code in interactiveFinger.py to:import Sofa import math class interaction(Sofa.PythonScriptController): def initGraph(self, node): self.node = node self.f1Node=self.node.getChild('finger') self.cableconstraint1Node=self.f1Node.getChild('PullingCable') self.cableconstraintvalue = self.cableconstraint1Node.getObject("CableConstraint").findData('value') def onKeyPressed(self,c): if (c == "M"): self.cableconstraintvalue.value = self.cableconstraintvalue.value[0][0] + 1. if (c == "-"): self.cableconstraintvalue.value = self.cableconstraintvalue.value[0][0] - 1. def getTranslated(points, vec): r=[] for v in points: r.append( [v[0]+vec[0], v[1]+vec[1], v[2]+vec[2]] ) return r class GripperController(Sofa.PythonScriptController): def initGraph(self, node): self.node = node self.fingers = [self.node.getChild('finger')] self.name = "FingerController" def onKeyPressed(self,c): dir = None # UP key : if ord(c)==19: dir = [0.0,1.0,0.0] # DOWN key : rear elif ord(c)==21: dir = [0.0,-1.0,0.0] # LEFT key : left elif ord(c)==18: dir = [1.0,0.0,0.0] elif ord(c)==20: dir = [-1.0,0.0,0.0] if dir != None: for finger in self.fingers: mechanicalObject = finger.getObject("finger_tetras") mechanicalObject.findData('rest_position').value = getTranslated(mechanicalObject.rest_position, dir) cable = finger.getChild("PullingCable").getObject("CableConstraint") p = cable.pullPoint[0] cable.findData("pullPoint").value = [p[0]+dir[0], p[1]+dir[1], p[2]+dir[2]]
and add the additional controller to your testMesh.py:
rootNode.createObject('PythonScriptController', filename="./interactiveFinger.py", classname="GripperController")
With that I was able to actuate the finger and move it in the plane. Does this solve your issue?
I wasn’t able to test your initial gripping scene because the file hemi_vol is missing.Best regards,
Elie -
AuthorPosts