Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
quadruped-reactive-walking
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gepetto
quadruped-reactive-walking
Commits
581a6cff
Commit
581a6cff
authored
2 years ago
by
Pierre-Alexandre Leziart
Browse files
Options
Downloads
Patches
Plain Diff
Format and update unittests for Gait
parent
97c6178f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/python/testGait.py
+76
-29
76 additions, 29 deletions
tests/python/testGait.py
with
76 additions
and
29 deletions
tests/python/testGait.py
+
76
−
29
View file @
581a6cff
...
@@ -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
.
set
P
ast
G
ait
(
o_pgait
)
self
.
gait
.
set
_p
ast
_g
ait
(
o_pgait
)
self
.
gait
.
set
C
urrent
G
ait
(
o_cgait
)
self
.
gait
.
set
_c
urrent
_g
ait
(
o_cgait
)
self
.
gait
.
set
D
esired
G
ait
(
o_dgait
)
self
.
gait
.
set
_d
esired
_g
ait
(
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
.
update
Gait
(
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
.
update
Gait
(
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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