Skip to content
Zdeněk Materna edited this page Jan 5, 2022 · 3 revisions

Within our system, poses are defined by the Pose class. Let's take an example:

>>> from arcor2.data.common import Pose
>>> p=Pose()
>>> p
Pose(position=Position(x=0.0, y=0.0, z=0.0), orientation=Orientation(x=0.0, y=0.0, z=0.0, w=1.0))

As you can see, the pose is composed of position (3D vector) and orientation (4D quaternion). We are following ROS conventions (SI units, orientation is right-handed). Positions as well orientation components can be accessed by its members or iterated:

>>> p.position.x
0.0
>>> p.position[0]
0.0
>>> list(p.position)
[0.0, 0.0, 0.0]

Expert tip: for some advanced stuff, you can get pose as a transformation matrix (4x4 NumPy array) by calling the as_tr_matrix method. In reverse, you can call Pose.from_tr_matrix(m) to get instance of Pose from transformation matrix. In case you need to invert the pose (e.g. to get the pose of the marker wrt. camera instead of the pose of the camera wrt. marker), we got you covered with the inversed() method, which returns an inversed copy of the pose.

The classes for position and orientation defines many helpful methods, so you can perform common operations with them:

>>> from arcor2.data.common import Position
>>> p1=Position(1,2,3)
>>> p2=Position(3,2,1)
>>> p1+p2
Position(x=4, y=4, z=4)

Please note that after any modification, orientations are automatically normalized. To find more, please see the code.

In order to make work with poses as simple as possible, we (most of the time, see below) deal with global poses - with respect to the global origin. There is a convention, that all Object Types are consuming and producing global poses. So if you call any method of Object Type returning Pose, it should be a global one. However, if there is e.g. a hierarchy of action points in the project, the poses are (naturally) stored as relative ones (with respect to the parent action point or scene object) but to make the programer live easier, all relative poses are automatically converted to absolute during runtime, which is handled by the Resources class (arcor2_runtime).

As there is often a need to transform a relative pose into a global one and vice versa, there is a set of helper functions for this in arcor2.transformations. See the example which makes one pose relative to the other one:

>>> from arcor2.transformations import make_pose_rel
>>> abs_pose=Pose(Position(1,0,0))
>>> abs_pose2=Pose(Position(0,0,0))
>>> make_pose_rel(abs_pose, abs_pose2)
Pose(position=Position(x=-1.0, y=0.0, z=0.0), orientation=Orientation(x=0.0, y=0.0, z=0.0, w=1.0))

Expert tip: Within the module, there are also functions that work with the project, so if you need to e.g. transform a relative action point into a global one, check the code.

Clone this wiki locally