Strange servo using ServoPIDController
Hi! I am using ServoPIDControl
The MWE is presented below:
# import essential modules
from __future__ import print_function
from yade import pack, ymport, qt, plot, geom
from yade.gridpfacet import *
import gts, os.path, locale, random, math
locale.
#######
### 1. DEFINE VARIABLES AND MATERIALS ###
#######
# 1.a). define variables
key = 'Triaxial_
young=55e6 # normal contact stiffness
compFricDegree = 1.8 # initial contact friction during the confining phase
finalFricDegree = 43 # contact friction during the deviatoric loading
poisson = 0.3 # shear-to-normal stiffness ratio
isoStress = 110000 # confining stress
conStress = 100000 # confining stress for deviatoric loading stage
width = 1.4e-1 # sample width
height = 2.8e-1 # target sample height(after consolidation)
height_0 = 3.2e-1 # initial sample height
num_spheres=500 # number of spheres
R_p = 0.0084 # mean particle radius
rCoff = 10 # thickness of top and bot sphere cap (based on rParticle)
rParticle = 0.02e-1 # membrane grid seed size
alpha = 8
rate = 0.1 # loading rate (strain rate)
damp = 0.3 # damping coefficient
targetPorosity = 0.45 # target porosity
thresholdvalue = 0.05 # threshold unbalance force
final_rate = 0.1 # strain rate for deviator loading
thresholdstrain = 0.06 # threshold axial strain for terminate
enlargefactor = 1.00
# A.b). create materials for sand spheres and plates
Sand = O.materials.
young=young,
))
# A.c). create membrane materials
GridMat = O.materials.
))
pFacetMat = O.materials.
))
# A.d). create TOP & BOT plate materials
frictMat = O.materials.
young=100e6,
))
#######
### 3. DEFINE GLOBAL ENGINES ###
#######
#******
O.engines=[
ForceResetter(),
InsertionSortC
Bo1_Sphere_
Bo1_Facet_Aabb(),
Bo1_PFacet_
Bo1_GridConne
]),
InteractionLoop(
[
Ig2_Sphere_
Ig2_GridNode_
Ig2_GridConne
Ig2_Sphere_
Ig2_Facet_
],
[
Ip2_FrictMat_
Ip2_CohFrictM
],
[
Law2_
Law2_
Law2_
Law2_
],
label="iloop"
),
GlobalStiffnes
NewtonIntegrat
]
#******
O.engines[
O.engines[
#######
### 2. IMPORT CT-BASED PACKING ###
#######
# C.a). generate random dense sphere pack
pred = pack.inCylinder
sp = pack.randomDens
sand=sp.
# C.b). define different sections of sphere pack
bot = [O.bodies[s] for s in sand if O.bodies[
top = [O.bodies[s] for s in sand if O.bodies[
tot = [O.bodies[s] for s in sand if O.bodies[
# C.c). detect the position of particles in top & bot layer
top_limit = 0
top_id = 0
for s in top:
if s.state.
top_limit = s.state.pos[2]
top_id = s.id
bot_limit = height_0
bot_id = 0
for s in bot:
if s.state.
bot_limit = s.state.pos[2]
bot_id = s.id
# C.d). create facet wall around particle packing
facets = []
nw = 45
nh = 15
rCyl2 = 0.5*width / cos(pi/float(nw))
for r in range(nw):
for h in range(nh):
v1 = Vector3( rCyl2*cos(
v2 = Vector3( rCyl2*cos(
v3 = Vector3( rCyl2*cos(
v4 = Vector3( rCyl2*cos(
f1 = facet((
f2 = facet((
facets.
wall = O.bodies.
# C.e). define different sections of facet wall
for b in wall:
O.bodies[
O.bodies[
# C.f). create top & bot facet plate
facets3 = []
nw=45
rCyl2 = (.6*width+
for r in range(nw):
if r%2==0:
v1 = Vector3( rCyl2*cos(
v2 = Vector3( rCyl2*cos(
v3 = Vector3( rCyl2*cos(
v4 = Vector3( 0, 0, height_0 )
f1 = facet((
f2 = facet((
facets3.
topcap = O.bodies.
facets3 = []
for r in range(nw):
if r%2==0:
v1 = Vector3( rCyl2*cos(
v2 = Vector3( rCyl2*cos(
v3 = Vector3( rCyl2*cos(
v4 = Vector3( 0, 0, 0 )
f1 = facet((
f2 = facet((
facets3.
botcap = O.bodies.
# C.g). define top & bot wall id
for s in topcap:
top_id = s
bot_id = 0
for s in botcap:
bot_id = s
# D.h). calculate porosity
V_sand = 0
num_sand = 0
for b in sand:
r = O.bodies[
V_sand += 1.3333333*
num_sand +=1
porosity = 1-V_sand/
print('v_sand= ',V_sand,' number of sand: ',num_sand,
O.pause()
#######
### 4. DEFINE FUNCTIONS ###
#######
#######
# D.c). a function for recording data
def checkrecord():
plot.saveDataT
def compress():
for b in wall:
O.bodies[
O.bodies[
#######
# E.a). adding corrosponding python function
O.engines=
PyRunner(
]
# E.b). compress until target porosity
vel_ini_a = rate*height_0
vel_ini_r = rate*height_0
for b in topcap:
O.bodies[
O.bodies[
for b in botcap:
O.bodies[
O.bodies[
while 1:
O.run(100,True)
h = (O.bodies[
V = h*0.25*
porosity = 1-V_sand/V
print('porosity: ',porosity, ' height: ', h)
if (porosity <= targetPorosity):
print( 'compression stage finished!')
break
h_ini = h # record height after compression
# E.c). ADD CONFINING STRESS
# E.c.1). remove facet wall
for b in wall:
O.bodies.erase(b)
# E.c.2). create membrane around particle packing by reading mesh file
def membraneCylinde
'''
width: diameter of cylinder
height: height of cylinder
nw: number of facets along perimeter
nh: number of facets along height
rNode: radius of grid node
posC: center of cylindrical bottom surface-
materialNodes: material of grid nodes
materialPfacets: material of PFacets
'''
nodesIds = [] # ID list of gridnodes
cylIds = [] # ID list of cylinders
pfIds = [] # ID list of pfacets
colornode = [255/255,
colorcylinder = [0,0,0]
colorpfacet1 = [248/255,
colorpfacet2 = [156/255,
# create gridnodes
rCyl2 = 0.5*width / cos(pi/float(nw))
for r in range(nw):
for h in range(nh+1):
v = Vector3(
V = (O.bodies.
# create grid connection
nodeIdsMin = min(nodesIds)
for r in range(nw):
for h in range(nh):
if r == nw-1:
V1 = nodeIdsMin+
V2 = nodeIdsMin+
V3 = nodeIdsMin+
V4 = nodeIdsMin+
else:
V1 = nodeIdsMin+
V2 = nodeIdsMin+
V3 = nodeIdsMin+
V4 = nodeIdsMin+
#create grid connection
cylIds.
cylIds.
cylIds.
if h == nh-1:
cylIds.
# create PFacet
for r in range(nw):
for h in range(nh):
if r == nw-1:
V1 = nodeIdsMin+
V2 = nodeIdsMin+
V3 = nodeIdsMin+
V4 = nodeIdsMin+
else:
V1 = nodeIdsMin+
V2 = nodeIdsMin+
V3 = nodeIdsMin+
V4 = nodeIdsMin+
#create Pfacets
pfIds.
pfIds.
return nodesIds,
# 4.2.2). generate flexible membrane
shiftfactor = O.bodies[
nodesIds,
posC=Vector3(
# E.c.3). define different sections of membrane
membrane_grid = [O.bodies[s] for s in nodesIds ]
membrane_pfacet = [O.bodies[s] for s in pfIds]
# E.c.4). run one interaction
for f in membrane_grid:
f.shape.color = Vector3(0,0,0)
x = f.state.pos[0]
y = f.state.pos[1]
z = f.state.pos[2]
dist = math.sqrt(x*x+y*y)
n = Vector3(
if z<=O.bodies[
f.state.vel = -vel_ini_r*n*5
O.engines[
O.engines[
while 1:
O.run(1,True)
break
# 4.2). redefine engine
#******
# some initial parameters
'''
tsrr = 110000
wszz = 0
wsrr = 0
r_avg = 0
# velocity
zvel = 0.05*rate*height
rvel = 0.05*rate*height
max_vel = 0.5*height
gz = 0
gr = 0
rParticle = width/100
'''
tszz = 110000
tsrr = 110000
max_vel = 0.5*height
axialforce = tszz*width*
O.engines=[
ForceResetter(),
InsertionSortC
[
Bo1_Sphere_
Bo1_Facet_Aabb(),
Bo1_PFacet_
Bo1_GridConne
]
),
InteractionLoop(
[
Ig2_Sphere_
Ig2_GridNode_
Ig2_GridConne
Ig2_Sphere_
Ig2_Facet_
Ig2_Sphere_
Ig2_GridConne
Ig2_PFacet_
],
[
Ip2_FrictMat_
Ip2_CohFrictM
],
[
Law2_
Law2_
Law2_
Law2_
],
label="iloop"
),
NewtonInteg
ServoPIDContro
ServoPIDContro
#GlobalStiffne
PyRunner(
]
# set final friction angle, enable cohesion
setContactFrict
O.engines[
O.engines[
O.engines[
def plotAddData():
# axial stress
f4 = 0 # total confining force act on the flexible membrane toward center of circle
r_cum = 0 # cumulative radius of flexbile membrane
count = 0 # number of gridnodes
for b in membrane_grid:
x = b.state.pos[0]
y = b.state.pos[1]
z = b.state.pos[2]
dist = math.sqrt(x*x+y*y)
n = Vector3(
if z<=O.bodies[
f_local = O.forces.f(b.id) # resultant force on the gridnode
f_normal = n[0]*f_
f4 -= f_normal
r_cum += dist
count += 1
# calculate resulant force on top and bottom loading plates
f1 = sum(O.forces.
f2 = sum(O.forces.
# calculate height of sample and area of cylindrical walls
wdz = O.bodies[
r_avg = r_cum/count-
wAz = math.pi*r_avg*r_avg # area of loading plate
wAr = math.pi*r_avg*wdz*2 # area of flexible membrane
# calculate axial and radial stress
wszz = 0.5*(f2-f1)/wAz # average axial stress in the Z direction (kPa)
wsrr = f4/wAr
unbF = unbalancedForce()
print( 'Servoing: wszz= ',wszz,' wsrr= ',wsrr,' unbalanced force: ',unbF)
plot.addData(
def node2servo(node, area):
global tsrr, max_vel
x, y, z = node.state.pos
f = tsrr * area
dist = math.sqrt(x*x+y*y)
return ServoPIDControl
#nodes, nodesmiddle, nodestop, nodesbottom = findnodes(0, height)
nAPFacet = math.pi*
servosnode = [node2servo(node, nAPFacet) for node in membrane_grid]
O.engines = O.engines + servosnode
qt.View()
r = qt.Renderer()
r.bgColor = 1, 1, 1
plot.plots = {'z': ('swa', 'swc'), 'z ': ('unbF',)}
plot.plot()
O.dt = 0.1*PWaveTimeStep()
O.run()
Question information
- Language:
- English Edit question
- Status:
- Expired
- For:
- Yade Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: