This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Scene file for cloth on table. | |
To check deformations of the cloth under Attach Constraint and Fixed Constraint | |
Current script uses only Attach constraint at the 2 red balls to grasp the cloth | |
To add Fixed constraint uncomment line 62 | |
Note: The red balls are supposed to move together in simulation and thus the cloth must follow them with minimum deformations | |
at the grasped vertices | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class workspace (Sofa.PythonScriptController): | |
def __init__(self, node, commandLineArguments) : | |
self.commandLineArguments = commandLineArguments | |
print "Command line arguments for python : "+str(commandLineArguments) | |
self.node = node | |
self.createGraph(node) | |
return None; | |
def createGraph(self,rootNode): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?> | |
<!-- Testing ball collision problem from hugo --> | |
<Node name="root" dt="0.05" gravity="0 -9.810 0"> | |
<VisualStyle displayFlags="hideBehaviorModels hideCollisionModels hideMappings hideForceFields showVisualModels hideInteractionForceFields" /> | |
<RequiredPlugin name='SofaMiscCollision'/> | |
<RequiredPlugin name="SofaPython" pluginName="SofaPython" /> | |
<FreeMotionAnimationLoop solveVelocityConstraintFirst="0" /> | |
<LCPConstraintSolver maxIt="1000" tolerance="1e-6" initial_guess="false" build_lcp="true" multi_grid="false" printLog="0" mu="0.000000000001"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Node name="root" dt="0.05" gravity="0 -9.810 0"> | |
<VisualStyle displayFlags="hideBehaviorModels hideCollisionModels hideMappings hideForceFields showVisualModels hideInteractionForceFields" /> | |
<RequiredPlugin name='SofaMiscCollision'/> | |
<RequiredPlugin name="SofaPython" pluginName="SofaPython" /> | |
<FreeMotionAnimationLoop solveVelocityConstraintFirst="0" /> | |
<LCPConstraintSolver maxIt="1000" tolerance="1e-6" initial_guess="false" build_lcp="true" multi_grid="false" printLog="0" mu="1.9"/> | |
<CollisionPipeline depth="6" verbose="0" draw="0" /> | |
<BruteForceDetection name="N2" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Node name="root" dt="0.05" gravity="0 -9.810 0"> | |
<VisualStyle displayFlags="hideBehaviorModels hideCollisionModels hideMappings hideForceFields showVisualModels" /> | |
<RequiredPlugin name='SofaMiscCollision'/> | |
<LCPConstraintSolver maxIt="1000" tolerance="1e-6" initial_guess="false" build_lcp="true" multi_grid="false" printLog="0" mu="0.9"/> | |
<FreeMotionAnimationLoop solveVelocityConstraintFirst="1" /> | |
<CollisionPipeline depth="15" verbose="0" draw="0" /> | |
<BruteForceDetection name="N2" /> | |
<LocalMinDistance name="Proximity" alarmDistance="0.3" contactDistance="0.1" useLMDFilters="0" /> | |
<CollisionResponse name="Response" response="FrictionContact" /> | |
<DiscreteIntersection/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Sofa | |
class KeyboardControl(Sofa.PythonScriptController): | |
# called once graph is created, to init some stuff... | |
def initGraph(self,node): | |
print 'initGraph called (python side)' | |
self.MechanicalState = node.getObject('DOFs') | |
gravity = node.findData('gravity').value | |
print gravity | |
self.rootNode = node.getRoot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def optimalWeightFinder(self): | |
i = 1 | |
while True: | |
W = self.optimization() # optimize to find new weights in the list of policies | |
print ("weights ::", W ) | |
print ("the distances ::", self.policiesFE.keys()) | |
self.currentT = self.policyListUpdater(W, i) | |
print ("Current distance (t) is:: ", self.currentT ) | |
if self.currentT <= self.epsilon: # terminate if the point reached close enough | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class irlAgent: | |
def __init__(self, randomFE, expertFE, epsilon, num_states, num_frames, behavior): | |
self.randomPolicy = randomFE | |
self.expertPolicy = expertFE | |
self.num_states = num_states | |
self.num_frames = num_frames | |
self.behavior = behavior | |
self.epsilon = epsilon # termination when t < 0.1 | |
self.randomT = np.linalg.norm(np.asarray(self.expertPolicy)-np.asarray(self.randomPolicy)) #norm of the diff in expert and random | |
self.policiesFE = {self.randomT:self.randomPolicy} # storing the policies and their respective t values in a dictionary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getRLAgentFE(self, W, i): #get the feature expectations of a new poliicy using RL agent | |
IRL_helper(W, self.behavior, self.num_frames, i) # train the agent and save the model in a file used below | |
saved_model = 'saved-models_'+self.behavior+str(i)+'/164-150-100-50000-'+str(self.num_frames)+'.h5' # use the saved model to get the FE | |
model = neural_net(self.num_states, [164, 150], saved_model) | |
return play(model, W)#return feature expectations by executing the learned policy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def policyListUpdater(self, W, i): #add the policyFE list and differences | |
tempFE = self.getRLAgentFE(W, i) # get feature expectations of a new policy respective to the input weights | |
hyperDistance = np.abs(np.dot(W, np.asarray(self.expertPolicy)-np.asarray(tempFE))) #hyperdistance = t | |
self.policiesFE[hyperDistance] = tempFE | |
return hyperDistance # t = (weights.tanspose)*(expert-newPolicy) |
NewerOlder