def onKeyPressed(self, c): if (c == "+"): print 'heating' wire = self.node.getObject('actuator_wire') ls = Sofa.LinearSpring(0, 0, 0, 0, 0) #(0, 1, 500., 5., 100.) for i in range(0, len(wire.spring)): ls = wire.spring[i] # insert SMA heating algorithm here ls.L *= 0.95 ls.Ks += 100 wire.spring[i] = ls #wire.stiffness *=10 #stiffness is controlled for the whole wire, not segmentwise #self.node.getObject('actuator_wire').reinit() print wire.spring elif (c == "-"): print 'cooling' wire = self.node.getObject('actuator_wire') ls = Sofa.LinearSpring(0, 0, 0, 0, 0) #(0, 1, 500., 5., 100.) for i in range(0, len(wire.spring)): ls = wire.spring[i] # insert SMA cooling algorithm here ls.L /= 0.95 ls.Ks -= 100 wire.spring[i] = ls #self.node.getObject('actuator_wire').reinit() print wire.spring sys.stdout.flush() return 0
def createScene(node): node.createObject("MechanicalObject",position="0 0 0 1 0 0 2 0 0") sff = node.createObject("SpringForceField", spring="0 1 10 0.1 1 1 2 10 0.1 1") print type(sff.spring), sff.spring print type(sff.spring.value), sff.spring.value print sff.spring.value[0][0].Ks ls = Sofa.LinearSpring(0, 1, 100., 100., 100.) sff.spring.value = ls print len(sff.spring.value),sff.spring.value[0][0].Ks sff.spring.value = [ls,ls] print len(sff.spring.value),sff.spring.value[1][0].Ks print 'len',len(sff.spring) print sff.spring.__getitem__(0).Ks ls.Ks = 99999 sff.spring[1] = ls print sff.spring[0].Ks, sff.spring[1].Ks sff.spring[0] = sff.spring[1] print sff.spring[0].Ks, sff.spring[1].Ks sys.stdout.flush()