Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
traffic-scratch
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mehtank
traffic-scratch
Commits
835d4a3f
Commit
835d4a3f
authored
8 years ago
by
Cathy
Browse files
Options
Downloads
Patches
Plain Diff
Formatting
parent
0a9b8bb5
Branches
master
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bestrobot.py
+21
-10
21 additions, 10 deletions
bestrobot.py
with
21 additions
and
10 deletions
bestrobot.py
+
21
−
10
View file @
835d4a3f
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment