Skip to content
Snippets Groups Projects
Commit 581a6cff authored by Pierre-Alexandre Leziart's avatar Pierre-Alexandre Leziart
Browse files

Format and update unittests for Gait

parent 97c6178f
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,6 @@ np.set_printoptions(precision=6, linewidth=300) ...@@ -13,7 +13,6 @@ np.set_printoptions(precision=6, linewidth=300)
class TestGait(unittest.TestCase): class TestGait(unittest.TestCase):
def setUp(self): def setUp(self):
# Object that holds all controller parameters # Object that holds all controller parameters
...@@ -24,12 +23,24 @@ class TestGait(unittest.TestCase): ...@@ -24,12 +23,24 @@ class TestGait(unittest.TestCase):
self.params.dt_mpc = 0.02 self.params.dt_mpc = 0.02
self.k_mpc = int(self.params.dt_mpc / self.params.dt_wbc) self.k_mpc = int(self.params.dt_mpc / self.params.dt_wbc)
self.params.N_SIMULATION = 1000 self.params.N_SIMULATION = 1000
q_init = [0.0, 0.764, -1.407, 0.0, 0.76407, -1.4, 0.0, 0.76407, -1.407, 0.0, 0.764, -1.407] q_init = [
0.0,
0.764,
-1.407,
0.0,
0.76407,
-1.4,
0.0,
0.76407,
-1.407,
0.0,
0.764,
-1.407,
]
for i in range(len(q_init)): for i in range(len(q_init)):
self.params.q_init[i] = q_init[i] self.params.q_init[i] = q_init[i]
self.params.N_periods = 1 self.params.N_periods = 1
gait = [12, 1, 0, 0, 1, gait = [12, 1, 0, 0, 1, 12, 0, 1, 1, 0]
12, 0, 1, 1, 0]
for i in range(len(gait)): for i in range(len(gait)):
self.params.gait_vec[i] = gait[i] self.params.gait_vec[i] = gait[i]
...@@ -54,9 +65,16 @@ class TestGait(unittest.TestCase): ...@@ -54,9 +65,16 @@ class TestGait(unittest.TestCase):
pgait = self.params.gait.copy() pgait = self.params.gait.copy()
# Check initial state # Check initial state
self.assertTrue(np.allclose(np.flip(pgait, axis=0), self.gait.getPastGait()), "Initial past gait is OK") self.assertTrue(
self.assertTrue(np.allclose(pgait, self.gait.getCurrentGait()), "Initial current gait is OK") np.allclose(pgait, self.gait.get_past_gait()), "Initial past gait is OK"
self.assertTrue(np.allclose(pgait, self.gait.getDesiredGait()), "Initial desired gait is OK") )
self.assertTrue(
np.allclose(pgait, self.gait.matrix), "Initial current gait is OK"
)
self.assertTrue(
np.allclose(pgait, self.gait.get_desired_gait()),
"Initial desired gait is OK",
)
def test_roll(self): def test_roll(self):
"""Check if roll is properly applied with a transfer from desired gait to current gait and from """Check if roll is properly applied with a transfer from desired gait to current gait and from
...@@ -66,29 +84,49 @@ class TestGait(unittest.TestCase): ...@@ -66,29 +84,49 @@ class TestGait(unittest.TestCase):
o_pgait = np.round(np.random.random(self.params.gait.shape)) o_pgait = np.round(np.random.random(self.params.gait.shape))
o_cgait = np.round(np.random.random(self.params.gait.shape)) o_cgait = np.round(np.random.random(self.params.gait.shape))
o_dgait = np.round(np.random.random(self.params.gait.shape)) o_dgait = np.round(np.random.random(self.params.gait.shape))
self.gait.setPastGait(o_pgait) self.gait.set_past_gait(o_pgait)
self.gait.setCurrentGait(o_cgait) self.gait.set_current_gait(o_cgait)
self.gait.setDesiredGait(o_dgait) self.gait.set_desired_gait(o_dgait)
# Check that set functions are working # Check that set functions are working
self.assertTrue(np.allclose(o_pgait, self.gait.getPastGait()), "setPastGait is OK") self.assertTrue(
self.assertTrue(np.allclose(o_cgait, self.gait.getCurrentGait()), "setCurrentGait is OK") np.allclose(o_pgait, self.gait.get_past_gait()), "set_past_gait is OK"
self.assertTrue(np.allclose(o_dgait, self.gait.getDesiredGait()), "setDesiredGait is OK") )
self.assertTrue(
np.allclose(o_cgait, self.gait.matrix), "set_current_gait is OK"
)
self.assertTrue(
np.allclose(o_dgait, self.gait.get_desired_gait()), "set_desired_gait is OK"
)
# Oldify # Oldify
for i in range(12 * self.k_mpc + 1): for i in range(12 * self.k_mpc + 1):
self.gait.updateGait(i, self.k_mpc, 0) self.gait.update(i, 0)
# Check new values in gait matrices # Check new values in gait matrices
pgait = self.gait.getPastGait() pgait = self.gait.get_past_gait()
cgait = self.gait.getCurrentGait() cgait = self.gait.matrix
dgait = self.gait.getDesiredGait() dgait = self.gait.get_desired_gait()
self.assertTrue(np.allclose(np.flip(o_cgait[:12, :], axis=0), pgait[:12, :]), "First half past gait is OK") self.assertTrue(
self.assertTrue(np.allclose(o_pgait[:12, :], pgait[12:, :]), "Second half past gait is OK") np.allclose(o_pgait[12:, :], pgait[:12, :]), "First half past gait is OK"
self.assertTrue(np.allclose(o_cgait[12:, :], cgait[:12, :]), "First half current gait is OK") )
self.assertTrue(np.allclose(o_dgait[:12, :], cgait[12:, :]), "Second half current gait is OK") self.assertTrue(
self.assertTrue(np.allclose(o_dgait[12:, :], dgait[:12, :]), "First half desired gait is OK") np.allclose(o_cgait[:12, :], pgait[12:, :]), "Second half past gait is OK"
self.assertTrue(np.allclose(o_dgait[:12, :], dgait[12:, :]), "Second half desired gait is OK") )
self.assertTrue(
np.allclose(o_cgait[12:, :], cgait[:12, :]), "First half current gait is OK"
)
self.assertTrue(
np.allclose(o_dgait[:12, :], cgait[12:, :]),
"Second half current gait is OK",
)
self.assertTrue(
np.allclose(o_dgait[12:, :], dgait[:12, :]), "First half desired gait is OK"
)
self.assertTrue(
np.allclose(o_dgait[:12, :], dgait[12:, :]),
"Second half desired gait is OK",
)
def test_phase_duration(self): def test_phase_duration(self):
""" """
...@@ -98,18 +136,27 @@ class TestGait(unittest.TestCase): ...@@ -98,18 +136,27 @@ class TestGait(unittest.TestCase):
""" """
for i in range(16 * self.k_mpc): for i in range(16 * self.k_mpc):
self.gait.updateGait(i, self.k_mpc, 0) self.gait.update(i, 0)
cgait = self.gait.getCurrentGait() cgait = self.gait.matrix
for i in range(cgait.shape[0]): for i in range(cgait.shape[0]):
for j in range(4): for j in range(4):
self.assertTrue(0.24 == self.gait.getPhaseDuration(i, j, cgait[i, j]), "phaseDuration is OK") self.assertTrue(
self.assertTrue(12 - (i - 9) % 12 == self.gait.getRemainingTime(), "remainingTime is OK") np.allclose(
self.params.T_gait * 0.5, self.gait.get_phase_duration(i, j)
),
"phaseDuration is OK",
)
self.assertTrue(
self.params.dt_mpc * (12 - (i - 9) % 12)
== self.gait.get_remaining_time(i, j),
"remainingTime is OK",
)
def test_upper(self): def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO') self.assertEqual("foo".upper(), "FOO")
if __name__ == '__main__': if __name__ == "__main__":
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment