Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
dynamic-graph-tutorial
Commits
3f9b9bc6
Commit
3f9b9bc6
authored
Oct 29, 2019
by
Guilhem Saurel
Browse files
[Python] Format
parent
56410b7d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/simu.py
View file @
3f9b9bc6
import
numpy
as
np
import
matplotlib.pyplot
as
pl
import
dynamic_graph
as
dg
import
dynamic_graph.tutorial
as
dgt
import
dynamic_graph.signal_base
as
dgsb
import
matplotlib.pyplot
as
pl
import
numpy
as
np
# define inverted pendulum
a
=
dgt
.
InvertedPendulum
(
"IP"
)
...
...
@@ -14,8 +13,8 @@ b = dgt.FeedbackController("K")
# plug signals
stateOut
=
a
.
signal
(
'state'
)
forceIn
=
a
.
signal
(
'force'
)
stateIn
=
b
.
signal
(
'state'
)
forceIn
=
a
.
signal
(
'force'
)
stateIn
=
b
.
signal
(
'state'
)
forceOut
=
b
.
signal
(
'force'
)
dg
.
plug
(
stateOut
,
stateIn
)
...
...
@@ -27,20 +26,25 @@ timeStep = 0.001
s
=
stateOut
f
=
forceIn
s
.
value
=
(
0.0
,
0.1
,
0.0
,
0.0
)
s
.
value
=
(
0.0
,
0.1
,
0.0
,
0.0
)
gain
=
((
0.0
,
27.0
,
0.001
,
0.001
,
),
)
b
.
setGain
(
gain
,
)
gain
=
((
0.0
,
27.0
,
0.001
,
0.001
,),)
b
.
setGain
(
gain
,)
def
play
(
nbSteps
):
def
play
(
nbSteps
):
timeSteps
=
[]
values
=
[]
forces
=
[]
# Loop over time and compute discretized state values
for
x
in
x
range
(
nbSteps
)
:
t
=
x
*
timeStep
for
x
in
range
(
nbSteps
):
t
=
x
*
timeStep
timeSteps
.
append
(
t
)
values
.
append
(
s
.
value
)
forces
.
append
(
f
.
value
)
...
...
@@ -50,24 +54,24 @@ def play (nbSteps):
x
=
np
.
array
(
timeSteps
)
y
=
np
.
array
(
values
).
transpose
()
fig
=
pl
.
figure
()
fig
=
pl
.
figure
()
ax1
=
fig
.
add_subplot
(
121
)
ax2
=
fig
.
add_subplot
(
122
)
# plot configuration variables
ax1
.
plot
(
x
,
y
[
0
])
ax1
.
plot
(
x
,
y
[
1
])
ax1
.
plot
(
x
,
y
[
0
])
ax1
.
plot
(
x
,
y
[
1
])
# plot velocity variables
ax2
.
plot
(
x
,
y
[
2
])
ax2
.
plot
(
x
,
y
[
3
])
ax2
.
plot
(
x
,
forces
)
ax2
.
plot
(
x
,
y
[
2
])
ax2
.
plot
(
x
,
y
[
3
])
ax2
.
plot
(
x
,
forces
)
leg
=
ax1
.
legend
((
"x"
,
"theta"
))
leg
=
ax2
.
legend
((
"dx"
,
"dtheta"
,
"force"
))
ax1
.
legend
((
"x"
,
"theta"
))
ax2
.
legend
((
"dx"
,
"dtheta"
,
"force"
))
pl
.
show
()
if
__name__
==
'__main__'
:
play
(
100
)
if
__name__
==
'__main__'
:
play
(
100
)
Write
Preview
Supports
Markdown
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!
Cancel
Please
register
or
sign in
to comment