Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import numpy as np
import matplotlib.pyplot as plt
from pytransform3d.plot_utils import make_3d_axis
from pytransform3d.transformations import random_transform
from pytransform3d.transform_manager import TransformManager
random_state = np.random.RandomState(0)
A2world = random_transform(random_state)
B2world = random_transform(random_state)
A2C = random_transform(random_state)
D2B = random_transform(random_state)
tm = TransformManager()
tm.add_transform("A", "world", A2world)
tm.add_transform("B", "world", B2world)
tm.add_transform("A", "C", A2C)
tm.add_transform("D", "B", D2B)
plt.figure(figsize=(10, 5))
ax = make_3d_axis(3, 121)
ax = tm.plot_frames_in("world", ax=ax, alpha=0.6)
ax.view_init(30, 20)
ax = make_3d_axis(3, 122)
ax = tm.plot_frames_in("A", ax=ax, alpha=0.6)
ax.view_init(30, 20)
plt.show()
def _init_transform_manager(self, transform_manager, frame):
"""Transform all nodes into the reference frame."""
tm = TransformManager()
if frame not in transform_manager.nodes:
raise KeyError("Unknown frame '%s'" % frame)
for node in transform_manager.nodes:
try:
node2frame = transform_manager.get_transform(node, frame)
tm.add_transform(node, frame, node2frame)
except KeyError:
pass # Frame is not connected to the reference frame
return tm
"""
=====================
Transformation Editor
=====================
The transformation editor can be used to manipulate transformations.
"""
from pytransform3d.transform_manager import TransformManager
from pytransform3d.editor import TransformEditor
from pytransform3d.transformations import transform_from
from pytransform3d.rotations import matrix_from_euler_xyz
tm = TransformManager()
tm.add_transform(
"tree", "world",
transform_from(
matrix_from_euler_xyz([0, 0.5, 0]),
[0, 0, 0.5]
)
)
tm.add_transform(
"car", "world",
transform_from(
matrix_from_euler_xyz([0.5, 0, 0]),
[0.5, 0, 0]
)
)
"""Load transformations from URDF files."""
import numpy as np
from bs4 import BeautifulSoup
from .transform_manager import TransformManager
from .transformations import transform_from, concat, transform
from .rotations import matrix_from_euler_xyz, matrix_from_axis_angle
from .plot_utils import make_3d_axis
class UrdfTransformManager(TransformManager):
"""Transformation manager that can load URDF files.
URDF is the `Unified Robot Description Format `_.
URDF allows to define joints between links that can be rotated about one
axis. This transformation manager allows to set the joint angles after
joints have been added or loaded from an URDF.
.. warning::
Note that this module requires the Python package beautifulsoup4.
.. note::
Joint angles must be given in radians.
"""
def __init__(self):
from pytransform3d.rotations import (random_quaternion, matrix_from_euler_xyz,
q_id)
from pytransform3d.transformations import transform_from_pq, transform_from
from pytransform3d.transform_manager import TransformManager
random_state = np.random.RandomState(0)
ee2robot = transform_from_pq(
np.hstack((np.array([0.4, -0.3, 0.5]), random_quaternion(random_state))))
cam2robot = transform_from_pq(
np.hstack((np.array([0.0, 0.0, 0.8]), q_id)))
object2cam = transform_from(
matrix_from_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)
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()
import matplotlib.pyplot as plt
from pytransform3d.rotations import random_quaternion, q_id
from pytransform3d.transformations import transform_from_pq
from pytransform3d.transform_manager import TransformManager
random_state = np.random.RandomState(0)
camera2body = transform_from_pq(
np.hstack((np.array([0.4, -0.3, 0.5]),
random_quaternion(random_state))))
object2camera = transform_from_pq(
np.hstack((np.array([0.0, 0.0, 0.3]),
random_quaternion(random_state))))
tm = TransformManager()
tm.add_transform("camera", "body", camera2body)
tm.add_transform("object", "camera", object2camera)
ax = tm.plot_frames_in("body", s=0.1)
ax.set_xlim((-0.15, 0.65))
ax.set_ylim((-0.4, 0.4))
ax.set_zlim((0.0, 0.8))
plt.show()