Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4159539

Browse filesBrowse files
committed
handle animation of pose object with multi values
1 parent fa5b3d9 commit 4159539
Copy full SHA for 4159539

File tree

Expand file treeCollapse file tree

2 files changed

+27
-10
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-10
lines changed

‎spatialmath/base/animate.py

Copy file name to clipboardExpand all lines: spatialmath/base/animate.py
+15-7Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import matplotlib.pyplot as plt
1414
from matplotlib import animation
1515
from spatialmath import base
16-
from collections.abc import Iterable, Generator
16+
from collections.abc import Iterable, Generator, Iterator
1717

1818

1919
class Animate:
@@ -158,24 +158,32 @@ def run(self, movie=None, axes=None, repeat=False, interval=50, nframes=100, pau
158158
- invokes the draw() method of every object in the display list
159159
"""
160160

161-
def update(frame, a):
162-
# if contains trajectory:
161+
def update(frame, animation):
163162
if self.trajectory is not None:
163+
# passed a trajectory as an iterator or generator, get next
164164
T = next(self.trajectory)
165165
else:
166+
# passed a single transform, interpolate it
166167
T = base.trinterp(start=self.start, end=self.end, s=frame / nframes)
167-
a._draw(T)
168+
# ensure result is SE(3)
169+
if T.shape == (3,3):
170+
T = base.r2t(T)
171+
172+
# update the scene
173+
animation._draw(T)
174+
175+
# are we done yet
168176
if frame == nframes - 1:
169-
a.done = True
170-
return a.artists()
177+
animation.done = True
178+
return animation.artists()
171179

172180
# blit leaves a trail and first frame
173181
if movie is not None:
174182
repeat = False
175183

176184
self.done = False
177185
if self.trajectory is not None:
178-
if not isinstance(self.trajectory, Iterable):
186+
if not isinstance(self.trajectory, Iterator):
179187
# make it iterable, eg. if a list or tuple
180188
self.trajectory = iter(self.trajectory)
181189
frames = None

‎spatialmath/super_pose.py

Copy file name to clipboardExpand all lines: spatialmath/super_pose.py
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,19 @@ def animate(self, *args, start=None, **kwargs):
851851
"""
852852
if start is not None:
853853
start = start.A
854-
if self.N == 2:
855-
base.tranimate2(self.A, start=start, *args, **kwargs)
854+
855+
if len(self) > 1:
856+
# trajectory case
857+
if self.N == 2:
858+
base.tranimate2(self.data, *args, **kwargs)
859+
else:
860+
base.tranimate(self.data, *args, **kwargs)
856861
else:
857-
base.tranimate(self.A, start=start, *args, **kwargs)
862+
# singleton case
863+
if self.N == 2:
864+
base.tranimate2(self.A, start=start, *args, **kwargs)
865+
else:
866+
base.tranimate(self.A, start=start, *args, **kwargs)
858867

859868

860869
# ------------------------------------------------------------------------ #

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.