Commit 236cc4a4 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

[Tests] Add trivial python unit test

parent ae7339ab
......@@ -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 = ((
gain = ((
0.0,
27.0,
0.001,
0.001,
), )
b.setGain(gain, )
), )
b.setGain(gain, )
return s, f, a
def play(nbSteps):
s, f, a = build_graph()
timeStep = 0.001
timeSteps = []
values = []
forces = []
......
......@@ -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)
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()
Supports Markdown
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