Skip to content
Snippets Groups Projects
Commit 835d4a3f authored by Cathy's avatar Cathy
Browse files

Formatting

parent 0a9b8bb5
Branches master
No related merge requests found
......@@ -11,11 +11,13 @@ def isstable(model):
"""
return 2 * model[1] * model[2] + model[2] * model[2] - 2 * model[0]
def tf((f,g,h), w):
def tf((f, g, h), w):
"""
Return the complex value of the linearized transfer function T(jw)
"""
return (g*1j*w + f)/(-w*w + (g+h)*1j*w + f)
return (g * 1j * w + f) / (-w * w + (g + h) * 1j * w + f)
def tflogmag(model, w):
"""
......@@ -24,12 +26,14 @@ def tflogmag(model, w):
"""
return log(absolute(tf(model, w)))
def htflogmag(model, w):
"""
Return the log of the magnitude of the linearized headway transfer function
log[ |1-T(jw)| ]
"""
return log(absolute(1-tf(model,w)))
return log(absolute(1 - tf(model, w)))
def btf(human, robot, gamma, w):
"""
......@@ -42,9 +46,10 @@ def btf(human, robot, gamma, w):
"""
tr = tf(robot, w)
th = tf(human, w)
t = gamma * tr / (1 - (1-gamma)*tr*th)
t = gamma * tr / (1 - (1 - gamma) * tr * th)
return t
def btflogmag(human, robot, gamma, w):
"""
Return the log of the magnitude of the linearized transfer function
......@@ -53,13 +58,15 @@ def btflogmag(human, robot, gamma, w):
"""
return log(absolute(btf(human, robot, gamma, w)))
def bhtflogmag(human, robot, gamma, w):
"""
Return the log of the magnitude of the linearized headway transfer function
log[ |1-T(jw)| ]
of a bilateral robot controller [ followed by a human ]
"""
return log(absolute(1-btf(human, robot, gamma, w)))
return log(absolute(1 - btf(human, robot, gamma, w)))
def kstable(human, robot, w, eta=2):
"""
......@@ -87,6 +94,7 @@ def ksafe(human, robot, w, eta):
TOL = 1e-6
def maxkfn(human, robot, eta, kfn):
"""
Find the maximum number of humans cars that can be handled by a
......@@ -97,9 +105,11 @@ def maxkfn(human, robot, eta, kfn):
:param kfn: function { ksafe for safety | kstable for string stability }
:return:
"""
f,g,h = human
f, g, h = human
maxw = sqrt(-isstable(human))
return minimize(lambda w : kfn(human, robot, w, eta), 1, bounds=[(TOL,maxw-TOL)])#.fun[0]
return minimize(lambda w: kfn(human, robot, w, eta), 1,
bounds=[(TOL, maxw - TOL)]) # .fun[0]
def maxk(human, robot, eta):
"""
......@@ -109,7 +119,8 @@ def maxk(human, robot, eta):
:param eta:
:return:
"""
return min(maxkfn(human, robot, eta, kstable), maxkfn(human, robot, eta, ksafe))
return min(maxkfn(human, robot, eta, kstable),
maxkfn(human, robot, eta, ksafe))
def best_robot_at_w(human, w, optfun, eta=2, fbound=(0, 0.2), gbound=(0, 0.2),
......@@ -178,7 +189,8 @@ def plot_kmaxs_vs_FGH(human, robotopt, eta=2, res=100, fbound=(0, 0.2),
robots[:, i] = robotXs
kstablerobots = np.array(
[maxkfn(human, robot, eta, kstable).fun[0] for robot in robots])
ksaferobots = [maxkfn(human, robot, eta, ksafe).fun[0] for robot in robots]
ksaferobots = [maxkfn(human, robot, eta, ksafe).fun[0] for robot in
robots]
kstablerobots[kstablerobots < 0] = 0
plt.plot(robotXs, kstablerobots, 'k.')
plt.plot(robotXs, ksaferobots, 'r.')
......@@ -202,4 +214,3 @@ if __name__ == "__main__":
robotopt = bestrobot(human, eta)
plot_kmaxs_vs_FGH(human, robotopt.x)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment