Tft display motorcycle.A rotating pyramid. The TFT screen shows a rotating pyramid. The effect was so cool that it instantly aroused my interest.
1. Hardware preparation and function introduction.
One Arduino MEGA2560 board, one TFT screen (compatible with Arduino pins), and two rocker modules removed from the toy remote control to make a 4-channel handle.
The two rocker modules output four analog signals, which are used to control the scaling of the pyramid and rotate around the X, Y and Z axes of the screen coordinate system, paying attention to the coordinate system: the screen coordinate system, instead of rotating around the X, Y and Z axes of the pyramid.
2. Design ideas.
1. Establish a coordinate system-screen coordinate system with the center of the screen as the origin, and another coordinate system-pyramid coordinate system with the center of the pyramid as the origin, and the origin of the two coordinate systems coincide.
2. The analog quantities of four rocker potentiometers are collected by AD conversion, one of which is mapped to the scaling coefficient, and the other three values are mapped to the angular velocity values of rotation around the three axes of the screen coordinate system (converted to radians), which are used to calculate the rotation vector, including the coordinates and rotation angle values of the rotation axis in the screen coordinate system.
3. Establish a rotation matrix (DCM- direction cosine matrix) from the screen coordinate system to the pyramid coordinate system, then project the rotation vector (axis-angle) in the screen coordinate system to the pyramid coordinate system through the rotation matrix, decompose the angular velocity around the X, Y, Z axis of the pyramid coordinate system, update the rotation matrix, and then orthogonalize the rotation matrix.
4. The five vertex coordinates of the pyramid (in the pyramid coordinate system) are projected to the screen coordinate system by the rotation matrix, and then multiplied by the scaling coefficient to get the coordinate values of the five vertices in the screen coordinate system. Omit the values of the Z axis of the five vertex coordinates and take their two-dimensional coordinate values (XPowerY), drive the TFT screen to “draw lines” in the way of “point-point” according to the set color values, draw the eight edges of the pyramid, and draw lines according to the coordinate values calculated by the screen background color in the same way, in order to achieve the effect of “clearing the screen”.
3. Knowledge preparation.
1. Vector operation: the calculation and geometric physical meaning of addition and subtraction, inner product (dot product) and outer product (cross product).
2. The synthesis of angular velocity vector and its physical meaning.
3. the derivation of rotation matrix, the update and orthogonalization of rotation matrix, and the projection calculation of rotation matrix.
In the following articles, the derivation process of these calculations will be introduced in detail, as well as the source code of the whole project. If there are any mistakes, please give criticism and correction.。