Mar 5, 2024
This article is written in Chinese. The English version is translated by GPT-4o. Please refer to the original Chinese version for the original content.
Pose estimation and a general application.
Distinguishing between points and vectors:
Points and vectors in space are real entities that do not change in nature due to changes in the coordinate system. However, we need a coordinate system to describe these entities.
For an -dimensional space, we use linearly independent vectors to describe the space. This set of vectors is called a basis. With a basis, we can describe any vector in the space. After defining the origin of the coordinate system, we translate the starting point of the vector to the origin, allowing us to represent any point in the space with an -dimensional vector.
Below is a set of basis vectors in three-dimensional space to represent any vector in the space.
Here, form a basis, and are the coordinates of vector under this basis.
The transformation between two coordinate systems can be represented by a rotation matrix and a translation vector.
From the above, we know that the same vector does not change with the choice of coordinate system. Therefore, during coordinate transformation, the following equation holds.
Multiplying both sides by on the left, we get
Here, is the rotation matrix. It is composed of the inner products of the two sets of basis vectors and describes the relationship between the coordinates before and after rotation.
The set of -dimensional rotation matrices forms a special Lie group called the special orthogonal group .
Using the rotation matrix for rotation is abstract, and we cannot directly obtain specific rotation information from it. It is also difficult to derive the rotation matrix from a known rotation.
A rotation can be described by a rotation axis and a rotation angle. The direction of the rotation vector is determined by the right-hand rule, represented by a unit vector . The magnitude of the rotation vector is determined by the rotation angle, represented by . With the rotation vector, we can describe any fixed-axis rotation in space. This rotation is related to the rotation matrix mentioned earlier, and this relationship is given by Rodrigues’ rotation formula.
For example, if we want to rotate a vector around the z-axis by degrees, we can use Rodrigues’ formula to describe this rotation. The rotation vector is . Substituting into the formula, we get the rotated vector.
This is a polar coordinate representation in the xy-plane, which aligns well with our expected result.
Rodrigues’ formula only provides a way to rotate a vector, but we need to transform it into a rotation matrix.
Here, is the skew-symmetric matrix generated by . The characteristic of a skew-symmetric matrix is , which converts the cross product operation into a matrix multiplication.
Proof:
Euler angles are a common way to describe rotation. Euler angles decompose a complex rotation into three simple rotations. In three-dimensional space, we typically use yaw-pitch-roll to describe rotation. That is, rotating degrees around the x-axis, degrees around the y-axis, and degrees around the z-axis.
Conventionally, rotation around the -axis is called roll, rotation around the -axis is called pitch, and rotation around the -axis is called yaw.
It is important to note that the order of rotation is crucial when using Euler angles. Different rotation orders result in different rotation matrices and produce different rotation effects. The multiplication of rotation matrices follows the right-associative property of vector products, meaning the rightmost rotation is performed first. In the above equation, the rotation order should be read from right to left, i.e., yaw-pitch-roll.
Translation transformation moves the origin of the coordinate system to another position. Translation can be represented by a vector. Translation is a linear transformation that does not change the direction of the vector, only its position.
Here, is the translation vector.
By adding a 1 at the end of a three-dimensional vector, we obtain a four-dimensional vector called homogeneous coordinates. This allows rotation and translation to be uniformly represented as a matrix multiplication.
Here, is the rotation matrix, and is the translation vector.
The set of transformation matrices between -dimensional spaces forms a special Lie group, denoted as . For convenience in later descriptions, when multiplying coordinates by an transformation, we will not first convert the coordinates to homogeneous coordinates.
In practical applications, we may need multiple coordinate system transformations. In such cases, we can combine multiple transformations into a single transformation matrix. This allows us to describe the transformation from one coordinate system to another with a single transformation matrix.
Here, .
In a common automatic aiming turret structure, we typically define four coordinate systems.
This article stipulates that when using subscripts to represent transformation matrices, the right subscript represents the original coordinate system, and the left subscript represents the transformed coordinate system.
For example, represents the transformation from the armor coordinate system to the world coordinate system. That is, . This notation aligns well with the right-multiplication property of transformations.
The relationship between the armor plate coordinate system and the camera coordinate system depends only on the pose of the armor plate. The pose of the armor plate is typically calculated using PnP.
Through PnP, we can obtain the transformation from the armor plate coordinate system to the camera coordinate system, including the rotation vector (rvec) and translation vector (tvec). These can be combined to form a transformation matrix. However, OpenCV’s default camera coordinate system has the z-axis pointing forward, the x-axis pointing to the right, and the y-axis pointing downward. Therefore, we need to transform the rvec and tvec by left-multiplying a corresponding coordinate axis transformation matrix.
Here, and are the rvec and tvec obtained from PnP.
The relationship between the camera coordinate system and the turret coordinate system depends only on the camera’s mounting. This is typically determined from mechanical assembly drawings, with adjustments made to correct for minor angle errors during assembly. In practice, many long-distance calculation errors stem from small angle errors during camera assembly.
Similarly, we have the following equation.
can also be decomposed into a rotation matrix and a translation vector. Let’s consider how to determine the rotation matrix and translation vector.
We start with a simpler problem. Assume that in the mechanical design, the camera and the gun barrel have a pitch angle rotation and a translation along the z-axis. and are defined in the turret coordinate system, and in the figure below, they should be negative values.
We now need to determine the transformation matrix for this process. An intuitive method is to assume a vector in the camera coordinate system. According to our earlier definition, this vector points directly forward from the camera. To represent the same vector in the turret coordinate system, we need to rotate this vector downward by the pitch angle. The rotation matrix is given by Rodrigues’ formula, .
To represent the point in the camera coordinate system, we also need to translate it. The translation vector is the vector from the turret coordinate system origin to the camera coordinate system origin. Since we rotate first and then translate, this vector needs to be expressed in the turret coordinate system. The translation vector is .
Combining these two steps, the representation of in the camera coordinate system in the turret coordinate system is .
Considering the full form of the problem, assume that the camera and turret have a complete Euler angle transformation and a full translation. The Euler angle relationship between the camera and turret is typically described from the turret’s perspective, following the yaw-pitch-roll rotation order to describe the rotation from the turret to the camera. However, when we need to go from the camera back to the turret, we need to reverse the order, i.e., roll-pitch-yaw. The corresponding rotation vector is . The translation vector is the vector from the turret coordinate system origin to the camera coordinate system origin, expressed in the turret coordinate system.
Through these two examples, we can further abstract this process. When solving for the transformation from coordinate system A to B, we typically know the pose of A in the B coordinate system. From the above analysis, we see that the rotation matrix and translation matrix have a consistent form. Although we need to transform a coordinate from A to B, the transformation matrix is derived using the transformation values from B to A.
Combining these two steps, the transformation of in the camera coordinate system to the turret coordinate system is . The corresponding transformation is .
The transformation from the turret coordinate system to the world coordinate system is obtained through the gyroscope. The gyroscope’s zero position is the origin of the world coordinate system. The gyroscope’s output is the transformation from the turret coordinate system to the world coordinate system.
Generally, we align the turret and world coordinate system origins, so no additional translation is needed. Therefore, we only need to convert the gyroscope data into a rotation matrix. The process is similar to the derivation from the camera coordinate system to the turret coordinate system, and readers are encouraged to think through it.
The motion equation of the projectile is:
Here, is the projectile velocity, is the acceleration, is the projectile air resistance coefficient, is the projectile mass, and is the gravitational acceleration.
The initial conditions of the projectile in the turret coordinate system are:
Here, is the initial velocity of the projectile.
Note that in the motion equation, we use the velocity in the world coordinate system. Therefore, we need to transform the velocity from the turret coordinate system to the world coordinate system.
The flight path equation is:
The target hitting point constraint is:
Combining the above equations, we can determine the unique pitch angle and yaw angle .
In the absence of a roll angle, we can directly control the yaw to align the projectile’s flight plane with the target point. Thus, the yaw value can be directly determined. We only need to solve for the pitch angle within a plane.
First, project the target point onto the xy-plane and calculate the azimuth angle of the target point, which is the yaw angle.
Since air resistance is considered, we need to solve the above ballistic differential equation. We can use the Newton-Raphson method to obtain an approximate numerical solution.
Here, is the height difference between the target point and the projectile’s flight path, is the projectile velocity, is the flight time, is the gravitational acceleration, is the flight distance, and is the projectile air resistance coefficient.
PNP — Mar 5, 2024
Unless otherwise stated, all content on this blog is licensed under CC BY-NC-SA 4.0.
RSS subscribe
鄂ICP备2025091178号
中文