Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sot-talos-balance
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
Guilhem Saurel
sot-talos-balance
Commits
c39e60f2
Commit
c39e60f2
authored
6 years ago
by
Gabriele Buondonno
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned sot_utils
parent
dde932d1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/sot_talos_balance/utils/run_test_utils.py
+5
-1
5 additions, 1 deletion
python/sot_talos_balance/utils/run_test_utils.py
python/sot_talos_balance/utils/sot_utils.py
+32
-104
32 additions, 104 deletions
python/sot_talos_balance/utils/sot_utils.py
with
37 additions
and
105 deletions
python/sot_talos_balance/utils/run_test_utils.py
+
5
−
1
View file @
c39e60f2
'''
This module contains utilities for running the tests.
'''
"""
2019, LAAS/CNRS
@author: Gabriele Buondonno
This module contains utilities for running the tests
"""
from
__future__
import
print_function
from
__future__
import
print_function
import
rospy
import
rospy
...
...
This diff is collapsed.
Click to expand it.
python/sot_talos_balance/utils/sot_utils.py
+
32
−
104
View file @
c39e60f2
# -*- coding: utf-8 -*-1
# -*- coding: utf-8 -*-1
"""
"""
2014, LAAS/CNRS
2019, LAAS/CNRS
@author: Andrea Del Prete
@author: Andrea Del Prete, Gabriele Buondonno
This module contains utilities for the SOT
"""
"""
from
__future__
import
print_function
import
numpy
as
np
import
numpy
as
np
from
time
import
sleep
from
time
import
sleep
import
os
import
os
class
Bunch
:
class
Bunch
:
def
__init__
(
self
,
**
kwds
):
def
__init__
(
self
,
**
kwds
):
self
.
__dict__
.
update
(
kwds
)
;
self
.
__dict__
.
update
(
kwds
)
def
__str__
(
self
,
prefix
=
""
):
def
__str__
(
self
,
prefix
=
""
):
res
=
""
;
res
=
""
for
(
key
,
value
)
in
self
.
__dict__
.
iteritems
():
for
(
key
,
value
)
in
self
.
__dict__
.
iteritems
():
if
(
isinstance
(
value
,
np
.
ndarray
)
and
len
(
value
.
shape
)
==
2
and
value
.
shape
[
0
]
>
value
.
shape
[
1
]):
if
(
isinstance
(
value
,
np
.
ndarray
)
and
len
(
value
.
shape
)
==
2
and
value
.
shape
[
0
]
>
value
.
shape
[
1
]):
res
+=
prefix
+
"
-
"
+
key
+
"
:
"
+
str
(
value
.
T
)
+
"
\n
"
;
res
+=
prefix
+
"
-
"
+
key
+
"
:
"
+
str
(
value
.
T
)
+
"
\n
"
elif
(
isinstance
(
value
,
Bunch
)):
elif
(
isinstance
(
value
,
Bunch
)):
res
+=
prefix
+
"
-
"
+
key
+
"
:
\n
"
+
value
.
__str__
(
prefix
+
"
"
)
+
"
\n
"
;
res
+=
prefix
+
"
-
"
+
key
+
"
:
\n
"
+
value
.
__str__
(
prefix
+
"
"
)
+
"
\n
"
else
:
else
:
res
+=
prefix
+
"
-
"
+
key
+
"
:
"
+
str
(
value
)
+
"
\n
"
;
res
+=
prefix
+
"
-
"
+
key
+
"
:
"
+
str
(
value
)
+
"
\n
"
return
res
[:
-
1
]
;
return
res
[:
-
1
]
def
start_sot
():
def
start_sot
():
os
.
system
(
'
rosservice call /start_dynamic_graph
'
)
;
os
.
system
(
'
rosservice call /start_dynamic_graph
'
)
def
stop_sot
():
def
stop_sot
():
os
.
system
(
'
rosservice call /stop_dynamic_graph
'
);
os
.
system
(
'
rosservice call /stop_dynamic_graph
'
)
def
start_tracer
(
robot
,
estimator_ft
,
estimator_kin
,
torque_ctrl
,
traj_gen
,
ctrl_manager
,
inv_dyn
,
adm_ctrl
):
from
dynamic_graph.sot.torque_control.create_entities_utils
import
create_tracer
tracer
=
create_tracer
(
robot
.
device
,
traj_gen
,
estimator_ft
,
estimator_kin
,
inv_dyn
,
torque_ctrl
);
tracer
.
start
();
return
tracer
;
def
move_to_initial_configuration
(
traj_gen
):
traj_gen
.
moveJoint
(
'
rhy
'
,
0
,
4.0
);
traj_gen
.
moveJoint
(
'
rhr
'
,
0
,
4.0
);
traj_gen
.
moveJoint
(
'
rhp
'
,
-
0.6
,
4
);
traj_gen
.
moveJoint
(
'
rk
'
,
1.1
,
4
);
traj_gen
.
moveJoint
(
'
rap
'
,
-
0.6
,
4
);
traj_gen
.
moveJoint
(
'
rar
'
,
0
,
4.0
);
traj_gen
.
moveJoint
(
'
lhy
'
,
0
,
4.0
);
traj_gen
.
moveJoint
(
'
lhp
'
,
0
,
4.0
);
traj_gen
.
moveJoint
(
'
lhr
'
,
0.5
,
4.0
);
traj_gen
.
moveJoint
(
'
lk
'
,
1.7
,
4.0
);
traj_gen
.
moveJoint
(
'
lap
'
,
0
,
4.0
);
traj_gen
.
moveJoint
(
'
lar
'
,
0
,
4.0
);
def
go_to_position
(
traj_gen
,
q
,
T
=
10.0
):
#put the robot in position q
# RLEG TO 0 **********************
traj_gen
.
moveJoint
(
'
rhy
'
,
q
[
0
],
T
)
#0
traj_gen
.
moveJoint
(
'
rhr
'
,
q
[
1
],
T
)
#1
traj_gen
.
moveJoint
(
'
rhp
'
,
q
[
2
],
T
)
#2
traj_gen
.
moveJoint
(
'
rk
'
,
q
[
3
],
T
)
#3
traj_gen
.
moveJoint
(
'
rap
'
,
q
[
4
],
T
)
#4
traj_gen
.
moveJoint
(
'
rar
'
,
q
[
5
],
T
)
#5
# LLEG TO 0 **********************
traj_gen
.
moveJoint
(
'
lhy
'
,
q
[
6
],
T
)
#6
traj_gen
.
moveJoint
(
'
lhr
'
,
q
[
7
],
T
)
#7
traj_gen
.
moveJoint
(
'
lhp
'
,
q
[
8
],
T
)
#8
traj_gen
.
moveJoint
(
'
lk
'
,
q
[
9
],
T
)
#9
traj_gen
.
moveJoint
(
'
lap
'
,
q
[
10
],
T
)
#10
traj_gen
.
moveJoint
(
'
lar
'
,
q
[
11
],
T
)
#11
# TORSO TO 0
traj_gen
.
moveJoint
(
'
ty
'
,
q
[
12
],
T
)
#12
traj_gen
.
moveJoint
(
'
tp
'
,
q
[
13
],
T
)
#13
# HEAD TO 0
traj_gen
.
moveJoint
(
'
hy
'
,
q
[
14
],
T
)
#14
traj_gen
.
moveJoint
(
'
hp
'
,
q
[
15
],
T
)
#15
# RARM TO 0 **********************
traj_gen
.
moveJoint
(
'
rsp
'
,
q
[
16
],
T
)
#16
traj_gen
.
moveJoint
(
'
rsr
'
,
q
[
17
],
T
)
#17
traj_gen
.
moveJoint
(
'
rsy
'
,
q
[
18
],
T
)
#18
traj_gen
.
moveJoint
(
'
re
'
,
q
[
19
],
T
)
#19
traj_gen
.
moveJoint
(
'
rwy
'
,
q
[
20
],
T
)
#20
traj_gen
.
moveJoint
(
'
rwp
'
,
q
[
21
],
T
)
#21
traj_gen
.
moveJoint
(
'
rh
'
,
q
[
22
],
T
)
#22
# LARM TO 0 **********************
traj_gen
.
moveJoint
(
'
lsp
'
,
q
[
23
],
T
)
#23
traj_gen
.
moveJoint
(
'
lsr
'
,
q
[
24
],
T
)
#24
traj_gen
.
moveJoint
(
'
lsy
'
,
q
[
25
],
T
)
#25
traj_gen
.
moveJoint
(
'
le
'
,
q
[
26
],
T
)
#26
traj_gen
.
moveJoint
(
'
lwy
'
,
q
[
27
],
T
)
#27
traj_gen
.
moveJoint
(
'
lwp
'
,
q
[
28
],
T
)
#28
traj_gen
.
moveJoint
(
'
lh
'
,
q
[
29
],
T
)
#29
def
smoothly_set_signal_to_zero
(
sig
):
def
smoothly_set_signal_to_zero
(
sig
):
v
=
np
.
array
(
sig
.
value
)
;
v
=
np
.
array
(
sig
.
value
)
for
i
in
range
(
40
):
for
i
in
range
(
40
):
v
=
0.95
*
v
;
v
=
0.95
*
v
sig
.
value
=
tuple
(
v
)
;
sig
.
value
=
tuple
(
v
)
sleep
(
1
)
;
sleep
(
1
)
print
'
Setting signal to zero
'
;
print
(
'
Setting signal to zero
'
)
v
[:]
=
0.0
;
v
[:]
=
0.0
sig
.
value
=
tuple
(
v
)
;
sig
.
value
=
tuple
(
v
)
def
smoothly_set_signal
(
sig
,
final_value
,
duration
=
5.0
,
steps
=
500
,
prints
=
10
):
def
smoothly_set_signal
(
sig
,
final_value
,
duration
=
5.0
,
steps
=
500
,
prints
=
10
):
v
=
np
.
array
(
sig
.
value
)
;
v
=
np
.
array
(
sig
.
value
)
vf
=
np
.
array
(
final_value
)
vf
=
np
.
array
(
final_value
)
for
i
in
range
(
steps
+
1
):
for
i
in
range
(
steps
+
1
):
alpha
=
1.0
*
i
/
steps
alpha
=
1.0
*
i
/
steps
sig
.
value
=
tuple
(
vf
*
alpha
+
(
1
-
alpha
)
*
v
)
;
sig
.
value
=
tuple
(
vf
*
alpha
+
(
1
-
alpha
)
*
v
)
sleep
(
1.0
*
duration
/
steps
)
;
sleep
(
1.0
*
duration
/
steps
)
print
'
Signal set
'
;
print
(
'
Signal set
'
)
sig
.
value
=
tuple
(
final_value
)
;
sig
.
value
=
tuple
(
final_value
)
def
monitor_tracking_error
(
sig
,
sigRef
,
dt
,
time
):
def
monitor_tracking_error
(
sig
,
sigRef
,
dt
,
time
):
N
=
int
(
time
/
dt
)
;
N
=
int
(
time
/
dt
)
err
=
np
.
zeros
((
N
,
6
))
;
err
=
np
.
zeros
((
N
,
6
))
for
i
in
range
(
N
):
for
i
in
range
(
N
):
err
[
i
,:]
=
np
.
array
(
sig
.
value
)
-
np
.
array
(
sigRef
.
value
)
;
err
[
i
,:]
=
np
.
array
(
sig
.
value
)
-
np
.
array
(
sigRef
.
value
)
sleep
(
dt
)
;
sleep
(
dt
)
for
i
in
range
(
6
):
for
i
in
range
(
6
):
print
'
Max tracking error for axis %d: %.2f
'
%
(
i
,
np
.
max
(
np
.
abs
(
err
[:,
i
])));
print
(
'
Max tracking error for axis %d: %.2f
'
%
(
i
,
np
.
max
(
np
.
abs
(
err
[:,
i
])))
)
print
'
Mean square tracking error for axis %d: %.2f
'
%
(
i
,
np
.
linalg
.
norm
(
err
[:,
i
])
/
N
);
print
(
'
Mean square tracking error for axis %d: %.2f
'
%
(
i
,
np
.
linalg
.
norm
(
err
[:,
i
])
/
N
)
)
def
dump_signal_to_file
(
sig_list
,
index
,
filename
,
T
,
dt
):
N
=
int
(
T
/
dt
);
m
=
len
(
sig_list
);
f
=
open
(
'
/tmp/
'
+
filename
,
'
a
'
,
1
);
for
t
in
range
(
N
):
for
s
in
sig_list
:
f
.
write
(
'
{0}
\t
'
.
format
(
s
.
value
[
index
]))
f
.
write
(
'
\n
'
);
sleep
(
dt
);
f
.
close
();
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