dfki-ric / pytransform3d

3D transformations for Python.
https://dfki-ric.github.io/pytransform3d/
Other
631 stars 68 forks source link

How to update the transformation in TransformManager? Should remove the old transformation and add again? #163

Closed caimingxue closed 3 years ago

caimingxue commented 3 years ago

Just like the example, In real robot control, if we change the transformation, such as ee2robot, object2cam, how should we pass the new data to the defined transformation ,tm.add_transform("camera", "robot", cam2robot), should we delete the old one and add again? Moreover, how we plot the whole TransformManager in animation to avoid plot the old one, just keep the newest frame.

bugs---1

import numpy as np import matplotlib.pyplot as plt from pytransform3d import rotations as pr from pytransform3d import transformations as pt from pytransform3d.transform_manager import TransformManager

random_state = np.random.RandomState(0)

ee2robot = pt.transform_from_pq( np.hstack((np.array([0.4, -0.3, 0.5]), pr.random_quaternion(random_state)))) cam2robot = pt.transform_from_pq( np.hstack((np.array([0.0, 0.0, 0.8]), pr.q_id))) object2cam = pt.transform_from( pr.active_matrix_from_intrinsic_euler_xyz(np.array([0.0, 0.0, -0.5])), np.array([0.5, 0.1, 0.1]))

tm = TransformManager() tm.add_transform("end-effector", "robot", ee2robot) tm.add_transform("camera", "robot", cam2robot) tm.add_transform("object", "camera", object2cam)

tm.add_transform("end-effector", "robot", object2cam)

ee2object = tm.get_transform("end-effector", "object")

ax = tm.plot_frames_in("robot", s=0.1) ax.set_xlim((-0.25, 0.75)) ax.set_ylim((-0.5, 0.5)) ax.set_zlim((0.0, 1.0)) plt.show()

AlexanderFabisch commented 3 years ago

Hi @caimingxue ,

have you considered using the Open3D-based visualizer for your use case? It should support animations of TransformManager objects. (It is mostly tested with UrdfTransformManager though.)

Supporting the same functionality in Matplotlib would be more complicated and is not currently supported.

In your specific example I assume that you plotted the same graph with updated transformations multiple times on the same axis? That's the behaviour that I would expect in this case.

You can find an example of how to do animations with matplotlib here: https://github.com/rock-learning/pytransform3d/blob/master/examples/animations/animate_rotation.py

A missing piece to support animations of TransformManagers in matplotlib is a corresponding Artist object, like the Frame object in the previous example. This is not currently available in pytransform3d.

AlexanderFabisch commented 3 years ago

Sorry, I didn't answer your original question from the title. To update a transformation in the TransformManager, you just have to call add_transform. This will update existing transformations.