Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
9621a84c
Commit
9621a84c
authored
6 years ago
by
Olivier Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Correct world2body and body2world
parent
1f74df12
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
navipy/trajectories/__init__.py
+55
-16
55 additions, 16 deletions
navipy/trajectories/__init__.py
navipy/trajectories/test_trajectory.py
+1
-1
1 addition, 1 deletion
navipy/trajectories/test_trajectory.py
with
56 additions
and
17 deletions
navipy/trajectories/__init__.py
+
55
−
16
View file @
9621a84c
...
@@ -17,6 +17,7 @@ from functools import partial
...
@@ -17,6 +17,7 @@ from functools import partial
import
time
import
time
from
scipy
import
signal
from
scipy
import
signal
from
scipy.interpolate
import
CubicSpline
from
scipy.interpolate
import
CubicSpline
import
warnings
def
_markers2position
(
x
,
kwargs
):
def
_markers2position
(
x
,
kwargs
):
...
@@ -51,6 +52,18 @@ def _markerstransform(index_i, trajectory,
...
@@ -51,6 +52,18 @@ def _markerstransform(index_i, trajectory,
return
tmarker
.
transpose
().
flatten
()
return
tmarker
.
transpose
().
flatten
()
def
_invmarkerstransform
(
index_i
,
trajectory
,
homogeneous_markers
,
rotation_mode
):
row
=
trajectory
.
loc
[
index_i
]
angles
=
row
.
loc
[
rotation_mode
].
values
translate
=
row
.
loc
[
'
location
'
].
values
trans_mat
=
htf
.
compose_matrix
(
angles
=
angles
,
translate
=
translate
,
axes
=
rotation_mode
)
tmarker
=
np
.
linalg
.
inv
(
trans_mat
).
dot
(
homogeneous_markers
)[:
3
]
return
tmarker
.
transpose
().
flatten
()
class
Trajectory
(
pd
.
DataFrame
):
class
Trajectory
(
pd
.
DataFrame
):
def
__init__
(
self
,
rotconv
=
'
rzyx
'
,
indeces
=
np
.
arange
(
1
)):
def
__init__
(
self
,
rotconv
=
'
rzyx
'
,
indeces
=
np
.
arange
(
1
)):
columns
=
self
.
__build_columns
(
rotconv
)
columns
=
self
.
__build_columns
(
rotconv
)
...
@@ -479,9 +492,8 @@ class Trajectory(pd.DataFrame):
...
@@ -479,9 +492,8 @@ class Trajectory(pd.DataFrame):
# -----------------------------------------------
# -----------------------------------------------
# ---------------- TRANSFORM --------------------
# ---------------- TRANSFORM --------------------
# -----------------------------------------------
# -----------------------------------------------
def
body2world
(
self
,
markers
,
indeces
=
None
):
def
world2body
(
self
,
markers
,
indeces
=
None
):
"""
Transform markers in body coordinate to world coordinate
"""
Transform markers in world coordinate to body coordinate
"""
"""
if
not
isinstance
(
markers
,
pd
.
Series
):
if
not
isinstance
(
markers
,
pd
.
Series
):
msg
=
'
markers should be of type pd.Series and not
'
msg
=
'
markers should be of type pd.Series and not
'
...
@@ -516,16 +528,44 @@ class Trajectory(pd.DataFrame):
...
@@ -516,16 +528,44 @@ class Trajectory(pd.DataFrame):
dtype
=
float
)
dtype
=
float
)
return
transformed_markers
return
transformed_markers
for
index_i
in
indeces
:
def
world2body
(
self
,
markers
,
indeces
=
None
):
row
=
self
.
loc
[
index_i
]
"""
Transform markers in world coordinate to body coordinate
angles
=
row
.
loc
[
self
.
rotation_mode
].
values
"""
translate
=
row
.
loc
[
'
location
'
].
values
msg
=
'
Prior to 12/09/2018:
\n
'
trans_mat
=
htf
.
compose_matrix
(
angles
=
angles
,
msg
+=
'
world2body was doing a reverse transformed
\n
'
translate
=
translate
,
msg
+=
'
Please use body2world instead
'
axes
=
self
.
rotation_mode
)
warnings
.
warn
(
msg
)
tmarker
=
trans_mat
.
dot
(
homogeneous_markers
.
transpose
())[:
3
]
if
not
isinstance
(
markers
,
pd
.
Series
):
transformed_markers
.
loc
[
index_i
,
:]
=
tmarker
.
transpose
().
flatten
()
msg
=
'
markers should be of type pd.Series and not
'
msg
+=
'
{}
'
.
format
(
type
(
markers
))
raise
TypeError
(
msg
)
if
not
isinstance
(
markers
.
index
,
pd
.
MultiIndex
):
msg
=
'
markers should have a multiIndex index
\n
'
msg
+=
'
(i,
"
x
"
), (i,
"
y
"
),(i,
"
z
"
)
\n
'
msg
+=
'
here i is the index of the marker
'
raise
TypeError
(
msg
)
if
indeces
is
None
:
# Looping through each time point along the trajectory
indeces
=
self
.
index
# More than one marker may be transformed
# The marker are assume to be a multiIndex dataframe
homogeneous_markers
=
markers
.
unstack
()
homogeneous_markers
[
'
w
'
]
=
1
homogeneous_markers
=
homogeneous_markers
.
transpose
()
# Looping throught the indeces
# to get the homogeneous transformation from the position orientation
# and then apply the transformed to the marker position
with
Pool
()
as
p
:
result
=
p
.
map
(
partial
(
_invmarkerstransform
,
trajectory
=
self
,
homogeneous_markers
=
homogeneous_markers
,
rotation_mode
=
self
.
rotation_mode
),
indeces
)
transformed_markers
=
pd
.
DataFrame
(
data
=
result
,
index
=
indeces
,
columns
=
markers
.
index
,
dtype
=
float
)
return
transformed_markers
return
transformed_markers
def
velocity
(
self
):
def
velocity
(
self
):
...
@@ -538,8 +578,7 @@ class Trajectory(pd.DataFrame):
...
@@ -538,8 +578,7 @@ class Trajectory(pd.DataFrame):
'
dalpha_2
'
],
'
dalpha_2
'
],
dtype
=
float
)
dtype
=
float
)
diffrow
=
self
.
diff
()
diffrow
=
self
.
diff
()
velocity
.
loc
[:,
[
'
dx
'
,
'
dy
'
,
'
dz
'
]]
=
\
velocity
.
loc
[:,
[
'
dx
'
,
'
dy
'
,
'
dz
'
]]
=
diffrow
.
loc
[:,
'
location
'
].
values
diffrow
.
loc
[:,
'
location
'
].
values
for
index_i
,
row
in
self
.
iterrows
():
for
index_i
,
row
in
self
.
iterrows
():
if
self
.
rotation_mode
==
'
quaternion
'
:
if
self
.
rotation_mode
==
'
quaternion
'
:
raise
NameError
(
'
Not implemented
'
)
raise
NameError
(
'
Not implemented
'
)
...
@@ -742,7 +781,7 @@ series.
...
@@ -742,7 +781,7 @@ series.
tailmarker
.
loc
[
0
,
'
x
'
]
=
lollipop_tail_length
tailmarker
.
loc
[
0
,
'
x
'
]
=
lollipop_tail_length
else
:
else
:
tailmarker
.
loc
[
0
,
'
x
'
]
=
-
lollipop_tail_length
tailmarker
.
loc
[
0
,
'
x
'
]
=
-
lollipop_tail_length
tail
=
self
.
world
2body
(
tailmarker
,
indeces
=
indeces
)
tail
=
self
.
body2
world
(
tailmarker
,
indeces
=
indeces
)
tail
=
tail
.
loc
[:,
0
]
tail
=
tail
.
loc
[:,
0
]
# Plot the agent trajectory
# Plot the agent trajectory
# - loop through consecutive point
# - loop through consecutive point
...
...
This diff is collapsed.
Click to expand it.
navipy/trajectories/test_trajectory.py
+
1
−
1
View file @
9621a84c
...
@@ -40,7 +40,7 @@ class TestTrajectoryTransform(unittest.TestCase):
...
@@ -40,7 +40,7 @@ class TestTrajectoryTransform(unittest.TestCase):
for
euler_axes
in
list
(
htconst
.
_AXES2TUPLE
.
keys
()):
for
euler_axes
in
list
(
htconst
.
_AXES2TUPLE
.
keys
()):
trajectory
.
rotation_mode
=
euler_axes
trajectory
.
rotation_mode
=
euler_axes
traj_test
.
rotation_mode
=
euler_axes
traj_test
.
rotation_mode
=
euler_axes
transformed_markers
=
trajectory
.
world
2body
(
markers
)
transformed_markers
=
trajectory
.
body2
world
(
markers
)
# reverse
# reverse
for
triangle_mode
in
[
'
x-axis=median-from-0
'
,
for
triangle_mode
in
[
'
x-axis=median-from-0
'
,
'
y-axis=1-2
'
]:
'
y-axis=1-2
'
]:
...
...
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