Skip to content

Commit

Permalink
Fix interleaved reading/writing of the application point, force and t…
Browse files Browse the repository at this point in the history
…orque in ForceTorqueTrack
  • Loading branch information
Marcos A. Núñez committed Jul 3, 2024
1 parent 4902f8e commit 131c0bd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
26 changes: 11 additions & 15 deletions src/basictdf/tdfForce3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,10 @@ def _build(stream, frames: int) -> "ForceTorqueTrack":
torque_data[:] = np.nan

for startFrame, nFrames in segmentData:
application_point_data[
startFrame : startFrame + nFrames
] = ApplicationPointType.bread(stream, nFrames)
force_data[startFrame : startFrame + nFrames] = ForceType.bread(
stream, nFrames
)
torque_data[startFrame : startFrame + nFrames] = TorqueType.bread(
stream, nFrames
)
for frame in range(startFrame, startFrame + nFrames):
application_point_data[frame] = ApplicationPointType.bread(stream)
force_data[frame] = ForceType.bread(stream)
torque_data[frame] = TorqueType.bread(stream)
return ForceTorqueTrack(
label=label,
application_point=application_point_data,
Expand Down Expand Up @@ -127,12 +122,13 @@ def _write(self, file: BinaryIO) -> None:
i32.bwrite(file, segment.stop - segment.start)

for segment in segments:
# applicationPoint
ApplicationPointType.bwrite(file, self.application_point[segment])
# force
ForceType.bwrite(file, self.force[segment])
# torque
TorqueType.bwrite(file, self.torque[segment])
for frame in range(segment.start, segment.stop):
# applicationPoint
ApplicationPointType.bwrite(file, self.application_point[frame])
# force
ForceType.bwrite(file, self.force[frame])
# torque
TorqueType.bwrite(file, self.torque[frame])

def __repr__(self) -> str:
return f"ForceTorqueTrack(label={self.label}, nFrames={self.nFrames})"
Expand Down
28 changes: 15 additions & 13 deletions tests/test_ForceTorque3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,21 @@ def test_build(self):
# nFrames
b += b"\x02\x00\x00\x00"

# application point
b += ApplicationPointType.write(cop)
for i in range(2):
# application point
b += ApplicationPointType.write(cop[i])

# force
b += ForceType.write(force)
# force
b += ForceType.write(force[i])

# torque
b += TorqueType.write(torque)
# torque
b += TorqueType.write(torque[i])

c = BytesIO(b)
a = ForceTorqueTrack._build(c, 2)
self.assertEqual(a.label, "r_gr")
self.assertEqual(a.nFrames, 2)
np.testing.assert_equal(a.application_point, cop)
np.testing.assert_almost_equal(a.application_point, cop)

self.assertEqual(a.application_point.shape, (2, 3))
self.assertEqual(a.force.shape, (2, 3))
Expand Down Expand Up @@ -116,14 +117,15 @@ def test_write(self):
# nFrames
b += b"\x02\x00\x00\x00"

# application point
b += ApplicationPointType.write(cop)
for i in range(2):
# application point
b += ApplicationPointType.write(cop[i])

# force
b += ForceType.write(force)
# force
b += ForceType.write(force[i])

# torque
b += TorqueType.write(torque)
# torque
b += TorqueType.write(torque[i])

i = BytesIO(b)
other = BytesIO()
Expand Down

0 comments on commit 131c0bd

Please sign in to comment.