Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sot-dyninv
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Stack Of Tasks
sot-dyninv
Commits
9cc3638a
Commit
9cc3638a
authored
13 years ago
by
Nicolas Mansard
Committed by
nmansard
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
IVIGIT.
parent
bf640fa9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
python/matrix_util.py
+75
-0
75 additions, 0 deletions
python/matrix_util.py
python/mocap/mocap_parser.py
+2
-70
2 additions, 70 deletions
python/mocap/mocap_parser.py
python/mocap/replay_mocap.py
+1
-2
1 addition, 2 deletions
python/mocap/replay_mocap.py
with
78 additions
and
72 deletions
python/matrix_util.py
0 → 100644
+
75
−
0
View file @
9cc3638a
'''
Tiny matrix functions, taken from Oscar source code.
'''
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
from
random
import
random
from
math
import
sqrt
,
atan2
,
pi
# Convert matrix to tuple
def
matrixToTuple
(
M
):
tmp
=
M
.
tolist
()
res
=
[]
for
i
in
tmp
:
res
.
append
(
tuple
(
i
))
return
tuple
(
res
)
# Convert from Roll, Pitch, Yaw to transformation Matrix
def
rpy2tr
(
r
,
p
,
y
):
mat
=
matrix
(
rotate
(
'
z
'
,
r
))
*
matrix
(
rotate
(
'
y
'
,
p
))
*
matrix
(
rotate
(
'
x
'
,
y
))
return
matrixToTuple
(
mat
)
# Get the distance btw the position components of 2 transf matrices
def
distVector
(
M2
,
M1
):
px
=
M1
[
0
][
3
]
-
M2
[
0
][
3
]
py
=
M1
[
1
][
3
]
-
M2
[
1
][
3
]
pz
=
M1
[
2
][
3
]
-
M2
[
2
][
3
]
return
[
px
,
py
,
pz
]
# Obtain an orthonormal matrix SO3 using the given vector as its first column
# (it computes Gram Schmidt to obtain an orthonormal basis using the
# first vector and 2 other 'random' vectors)
def
generateOrthonormalM
(
v1
):
v2
=
matrix
([
random
(),
random
(),
random
()])
v3
=
matrix
([
random
(),
random
(),
random
()])
v1
=
matrix
(
v1
)
e1
=
v1
/
linalg
.
norm
(
v1
)
u2
=
v2
-
inner
(
v2
,
e1
)
*
e1
e2
=
u2
/
linalg
.
norm
(
u2
)
u3
=
v3
-
inner
(
v3
,
e1
)
*
e1
-
inner
(
v3
,
e2
)
*
e2
e3
=
u3
/
linalg
.
norm
(
u3
)
e1
=
e1
.
tolist
();
e2
=
e2
.
tolist
();
e3
=
e3
.
tolist
()
M
=
(
(
e1
[
0
][
0
],
e2
[
0
][
0
],
e3
[
0
][
0
]),
(
e1
[
0
][
1
],
e2
[
0
][
1
],
e3
[
0
][
1
]),
(
e1
[
0
][
2
],
e2
[
0
][
2
],
e3
[
0
][
2
])
)
return
M
# Convert from Transformation Matrix to Roll,Pitch,Yaw
def
tr2rpy
(
M
):
m
=
sqrt
(
M
[
2
][
1
]
**
2
+
M
[
2
][
2
]
**
2
)
p
=
atan2
(
-
M
[
2
][
0
],
m
)
if
abs
(
p
-
pi
/
2
)
<
0.001
:
r
=
0
y
=
atan2
(
M
[
0
][
1
],
M
[
1
][
1
])
elif
abs
(
p
+
pi
/
2
)
<
0.001
:
r
=
0
y
=
-
atan2
(
M
[
0
][
1
],
M
[
1
][
1
])
else
:
r
=
atan2
(
M
[
1
][
0
],
M
[
0
][
0
])
y
=
atan2
(
M
[
2
][
1
],
M
[
2
][
2
])
return
[
float
(
r
),
float
(
p
),
float
(
y
)]
def
matrixToRPY
(
M
):
'''
Convert a 4x4 homogeneous matrix to a 6x1 rpy pose vector.
'''
rot
=
tr2rpy
(
M
)
return
[
M
[
0
][
3
],
M
[
1
][
3
],
M
[
2
][
3
],
rot
[
2
],
rot
[
1
],
rot
[
0
]]
This diff is collapsed.
Click to expand it.
python/mocap/mocap_parser.py
+
2
−
70
View file @
9cc3638a
...
...
@@ -16,78 +16,10 @@
import
sys
import
time
from
numpy
import
*
sys
.
path
.
append
(
'
..
'
)
from
matrix_util
import
matrixToTuple
,
rpy2tr
,
distVector
,
generateOrthonormalM
,
tr2rpy
,
matrixToRPY
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# Convert matrix to tuple
def
matrixToTuple
(
M
):
tmp
=
M
.
tolist
()
res
=
[]
for
i
in
tmp
:
res
.
append
(
tuple
(
i
))
return
tuple
(
res
)
# Convert from Roll, Pitch, Yaw to transformation Matrix
def
rpy2tr
(
r
,
p
,
y
):
mat
=
matrix
(
rotate
(
'
z
'
,
r
))
*
matrix
(
rotate
(
'
y
'
,
p
))
*
matrix
(
rotate
(
'
x
'
,
y
))
return
matrixToTuple
(
mat
)
# Get the distance btw the position components of 2 transf matrices
def
distVector
(
M2
,
M1
):
px
=
M1
[
0
][
3
]
-
M2
[
0
][
3
]
py
=
M1
[
1
][
3
]
-
M2
[
1
][
3
]
pz
=
M1
[
2
][
3
]
-
M2
[
2
][
3
]
return
[
px
,
py
,
pz
]
# Obtain an orthonormal matrix SO3 using the given vector as its first column
# (it computes Gram Schmidt to obtain an orthonormal basis using the
# first vector and 2 other 'random' vectors)
def
generateOrthonormalM
(
v1
):
v2
=
matrix
([
random
(),
random
(),
random
()])
v3
=
matrix
([
random
(),
random
(),
random
()])
v1
=
matrix
(
v1
)
e1
=
v1
/
linalg
.
norm
(
v1
)
u2
=
v2
-
inner
(
v2
,
e1
)
*
e1
e2
=
u2
/
linalg
.
norm
(
u2
)
u3
=
v3
-
inner
(
v3
,
e1
)
*
e1
-
inner
(
v3
,
e2
)
*
e2
e3
=
u3
/
linalg
.
norm
(
u3
)
e1
=
e1
.
tolist
();
e2
=
e2
.
tolist
();
e3
=
e3
.
tolist
()
M
=
(
(
e1
[
0
][
0
],
e2
[
0
][
0
],
e3
[
0
][
0
]),
(
e1
[
0
][
1
],
e2
[
0
][
1
],
e3
[
0
][
1
]),
(
e1
[
0
][
2
],
e2
[
0
][
2
],
e3
[
0
][
2
])
)
return
M
# Convert from Transformation Matrix to Roll,Pitch,Yaw
def
tr2rpy
(
M
):
m
=
sqrt
(
M
[
2
][
1
]
**
2
+
M
[
2
][
2
]
**
2
)
p
=
arctan2
(
-
M
[
2
][
0
],
m
)
if
abs
(
p
-
pi
/
2
)
<
0.001
:
r
=
0
y
=
arctan2
(
M
[
0
][
1
],
M
[
1
][
1
])
elif
abs
(
p
+
pi
/
2
)
<
0.001
:
r
=
0
y
=
-
arctan2
(
M
[
0
][
1
],
M
[
1
][
1
])
else
:
r
=
arctan2
(
M
[
1
][
0
],
M
[
0
][
0
])
y
=
arctan2
(
M
[
2
][
1
],
M
[
2
][
2
])
return
[
float
(
r
),
float
(
p
),
float
(
y
)]
def
matrixToRPY
(
M
):
'''
Convert a 4x4 homogeneous matrix to a 6x1 rpy pose vector.
'''
rot
=
tr2rpy
(
M
)
return
[
M
[
0
][
3
],
M
[
1
][
3
],
M
[
2
][
3
],
rot
[
2
],
rot
[
1
],
rot
[
0
]]
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
python/mocap/replay_mocap.py
+
1
−
2
View file @
9cc3638a
...
...
@@ -31,9 +31,8 @@
from
optparse
import
OptionParser
from
mocap_parser
import
MocapParser
sys
.
path
.
append
(
'
/home/nmansard/src/hpp2/sot-dyninv/python
'
)
sys
.
path
.
append
(
'
..
'
)
from
dynamic_graph.script_shortcuts
import
optionalparentheses
from
random
import
random
# --- PARSER INIT ------------------------------------------------------------------
...
...
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