~ubuntu-branches/ubuntu/trusty/yade/trusty

« back to all changes in this revision

Viewing changes to examples/PIDController.py

  • Committer: Package Import Robot
  • Author(s): Anton Gladky, cf3f8d9
  • Date: 2013-10-30 20:56:33 UTC
  • mfrom: (20.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20131030205633-1f01r7hjce17d723
Tags: 1.05.0-2
[cf3f8d9] Pass -ftrack-macro-expansion=0 only if gcc>=4.8. (Closes: #726009)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# encoding: utf-8
 
3
from yade import utils, plot
 
4
 
 
5
  
 
6
o = Omega()
 
7
fr = 0.0;rho=2000
 
8
tc = 0.001; en = 0.3; et = 0.3; o.dt = 0.02*tc
 
9
 
 
10
param = getViscoelasticFromSpheresInteraction(tc,en,et)
 
11
mat1 = O.materials.append(ViscElMat(frictionAngle=fr, density=rho,**param))
 
12
 
 
13
spheresID = O.bodies.append(pack.regularHexa(pack.inCylinder((0,0,-2.0),(0,0,2.0),2.0),radius=0.2,gap=0.1,color=(0,1,0),material=mat1))
 
14
 
 
15
idWalls = O.bodies.append(geom.facetCylinder(center=(0.0,0.0,0.0),radius = 2.05, height = 4.0, wallMask=6, material=mat1, segmentsNumber = 20, color=(0,0,1)))
 
16
idTop = O.bodies.append(geom.facetCylinder(center=(0.0,0.0,0.0),radius = 2.05, height = 4.0, wallMask=1, material=mat1, segmentsNumber = 5, color=(1,0,0), wire=False))
 
17
 
 
18
 
 
19
o.engines = [
 
20
  ForceResetter(),
 
21
  InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()],verletDist=1.0,label='collider'),
 
22
  InteractionLoop(
 
23
    [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
 
24
    [Ip2_ViscElMat_ViscElMat_ViscElPhys()],
 
25
    [Law2_ScGeom_ViscElPhys_Basic()],
 
26
  ),
 
27
  NewtonIntegrator(damping=0,gravity=[0,0,-9.81],label='newtonInt'),
 
28
  TranslationEngine(translationAxis=[0,0,1],velocity=-2.0,ids=idTop,dead=False,label='translat'),
 
29
  
 
30
  CombinedKinematicEngine(ids=idTop,label='combEngine',dead=True) + 
 
31
    ServoPIDController(axis=[0,0,1],maxVelocity=2.0,iterPeriod=1000,ids=idTop,target=1.0e7,kP=1.0,kI=1.0,kD=1.0) + 
 
32
    RotationEngine(rotationAxis=(0,0,1), angularVelocity=10.0, rotateAroundZero=True, zeroPoint=(0,0,0)),
 
33
  PyRunner(command='addPlotData()',iterPeriod=1000, label='graph'),
 
34
  PyRunner(command='switchTranslationEngine()',iterPeriod=45000, nDo = 2, label='switchEng'),
 
35
]
 
36
 
 
37
from yade import qt
 
38
qt.View()
 
39
r=qt.Renderer()
 
40
r.bgColor=1,1,1  
 
41
 
 
42
def addPlotData():
 
43
  fMove = Vector3(0,0,0)
 
44
  
 
45
  for i in idTop:
 
46
    fMove += O.forces.f(i)
 
47
  
 
48
  plot.addData(z=O.iter, pMove=fMove[2], pFest=fMove[2])
 
49
 
 
50
def switchTranslationEngine():
 
51
  print "Switch from TranslationEngine engine to ServoPIDController"
 
52
  translat.dead = True
 
53
  combEngine.dead = False
 
54
  
 
55
 
 
56
 
 
57
plot.plots={'z':('pMove','pFest')}; plot.plot()