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
236cc4a4
Commit
236cc4a4
authored
Mar 04, 2020
by
Guilhem Saurel
Browse files
[Tests] Add trivial python unit test
parent
ae7339ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/dynamic_graph/tutorial/simu.py
View file @
236cc4a4
...
...
@@ -3,41 +3,45 @@ import dynamic_graph.tutorial as dgt
import
matplotlib.pyplot
as
pl
import
numpy
as
np
# define inverted pendulum
a
=
dgt
.
InvertedPendulum
(
"IP"
)
a
.
setCartMass
(
1.0
)
a
.
setPendulumMass
(
1.0
)
a
.
setPendulumLength
(
1.0
)
b
=
dgt
.
FeedbackController
(
"K"
)
def
build_graph
():
# define inverted pendulum
a
=
dgt
.
InvertedPendulum
(
"IP"
)
a
.
setCartMass
(
1.0
)
a
.
setPendulumMass
(
1.0
)
a
.
setPendulumLength
(
1.0
)
# plug signals
stateOut
=
a
.
signal
(
'state'
)
forceIn
=
a
.
signal
(
'force'
)
stateIn
=
b
.
signal
(
'state'
)
forceOut
=
b
.
signal
(
'force'
)
b
=
dgt
.
FeedbackController
(
"K"
)
dg
.
plug
(
stateOut
,
stateIn
)
dg
.
plug
(
forceOut
,
forceIn
)
# plug signals
stateOut
=
a
.
signal
(
'state'
)
forceIn
=
a
.
signal
(
'force'
)
stateIn
=
b
.
signal
(
'state'
)
forceOut
=
b
.
signal
(
'force'
)
timeStep
=
0.001
dg
.
plug
(
stateOut
,
stateIn
)
dg
.
plug
(
forceOut
,
forceIn
)
# Set value of state signal
s
=
stateOut
f
=
forceIn
# Set value of state signal
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
,
)
return
s
,
f
,
a
def
play
(
nbSteps
):
s
,
f
,
a
=
build_graph
()
timeStep
=
0.001
timeSteps
=
[]
values
=
[]
forces
=
[]
...
...
tests/CMakeLists.txt
View file @
236cc4a4
...
...
@@ -7,3 +7,7 @@ TARGET_INCLUDE_DIRECTORIES(pendulum PUBLIC dynamic-graph::dynamic-graph)
ADD_UNIT_TEST
(
controller controller.cpp
)
TARGET_LINK_LIBRARIES
(
controller
${
PROJECT_NAME
}
${
Boost_UNIT_TEST_FRAMEWORK_LIBRARY
}
dynamic-graph::dynamic-graph
)
TARGET_INCLUDE_DIRECTORIES
(
controller PUBLIC dynamic-graph::dynamic-graph
)
IF
(
BUILD_PYTHON_INTERFACE
)
ADD_PYTHON_UNIT_TEST
(
simu
"tests/simu.py"
src
)
ENDIF
(
BUILD_PYTHON_INTERFACE
)
tests/simu.py
0 → 100644
View file @
236cc4a4
import
unittest
from
dynamic_graph.tutorial.simu
import
build_graph
class
DynamicGraphTutorialTest
(
unittest
.
TestCase
):
def
test_simu
(
self
):
s
,
f
,
a
=
build_graph
()
self
.
assertEqual
(
a
.
getCartMass
(),
1
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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