dji_log_parser/record/virtual_stick.rs
1use binrw::binread;
2use serde::Serialize;
3#[cfg(target_arch = "wasm32")]
4use tsify_next::Tsify;
5
6use crate::utils::sub_byte_field;
7
8#[binread]
9#[derive(Serialize, Debug)]
10#[serde(rename_all = "camelCase")]
11#[br(little)]
12#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
13pub struct VirtualStick {
14 #[br(temp)]
15 _bitpack1: u8,
16 #[br(calc(VirtualStickVerticalControlMode::from(sub_byte_field(_bitpack1, 0x30))))]
17 pub vertical_control_mode: VirtualStickVerticalControlMode,
18 #[br(calc(VirtualStickRollPitchControlMode::from(sub_byte_field(_bitpack1, 0xC0))))]
19 pub roll_pitch_control_mode: VirtualStickRollPitchControlMode,
20 #[br(calc(VirtualStickYawControlMode::from(sub_byte_field(_bitpack1, 0x08))))]
21 pub yaw_control_mode: VirtualStickYawControlMode,
22 #[br(calc(VirtualStickFlightCoordinateSystem::from(sub_byte_field(_bitpack1, 0x06))))]
23 pub coordinate_system: VirtualStickFlightCoordinateSystem,
24
25 /// Aircraft Roll. left and right panning [-30, 30] degrees
26 pub roll: f32,
27 /// Aircraft Pitch. forward or reverse [-30, 30] degrees.
28 pub pitch: f32,
29 /// Aircraft Yaw. left and right rotation [-180, 180] degrees
30 pub yaw: f32,
31 /// Aircraft throttle. Up or down [-5, 5]m/s
32 pub throttle: f32,
33}
34
35#[derive(Serialize, Debug)]
36#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
37pub enum VirtualStickVerticalControlMode {
38 /// Sets the virtual stick vertical control values to be a vertical velocity.
39 /// Positive and negative vertical velocity is for the aircraft ascending and
40 /// descending respectively. Maximum vertical velocity is defined as 4 m/s. Minimum
41 /// vertical velocity is defined as -4 m/s.
42 Velocity,
43 /// Sets the virtual stick vertical control values to be an altitude. Maximum
44 /// position is defined as 500 m. Minimum position is defined as 0 m.
45 Position,
46 #[serde(untagged)]
47 Unknown(u8),
48}
49
50impl From<u8> for VirtualStickVerticalControlMode {
51 fn from(value: u8) -> Self {
52 match value {
53 0 => VirtualStickVerticalControlMode::Velocity,
54 1 => VirtualStickVerticalControlMode::Position,
55 _ => VirtualStickVerticalControlMode::Unknown(value),
56 }
57 }
58}
59
60#[derive(Serialize, Debug)]
61#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
62pub enum VirtualStickRollPitchControlMode {
63 /// Sets the roll and pitch values to be an angle relative to a level aircraft. In
64 /// the body coordinate system, positive and negative pitch angle is for the
65 /// aircraft rotating about the y-axis in the positive direction or negative
66 /// direction, respectively. Positive and negative roll angle is the positive
67 /// direction or negative direction rotation angle about the x-axis, respectively.
68 /// However in the ground coordinate system, positive and negative pitch angle is
69 /// the angle value for the aircraft moving south and north, respectively. Positive
70 /// and negative roll angle is the angle when the aircraft is moving east and west,
71 /// respectively. Maximum angle is defined as 30 degrees. Minimum angle is defined
72 /// as -30 degrees.
73 Angle,
74 /// Sets the roll and pitch values to be a velocity. In the body coordinate system,
75 /// positive and negative pitch velocity is for the aircraft moving towards the
76 /// positive direction or negative direction along the pitch axis and y-axis,
77 /// respectively. Positive and negative roll velocity is when the aircraft is moving
78 /// towards the positive direction or negative direction along the roll axis and
79 /// x-axis, respectively. However, in the ground coordinate system, positive and
80 /// negative pitch velocity is for the aircraft moving east and west, respectively.
81 /// Positive and negative roll velocity is when the aircraft is moving north and
82 /// south, respectively. Maximum velocity is defined as 15 meters/s. Minimum
83 /// velocity is defined as -15 meters/s.
84 Velocity,
85 #[serde(untagged)]
86 Unknown(u8),
87}
88
89impl From<u8> for VirtualStickRollPitchControlMode {
90 fn from(value: u8) -> Self {
91 match value {
92 0 => VirtualStickRollPitchControlMode::Angle,
93 1 => VirtualStickRollPitchControlMode::Velocity,
94 _ => VirtualStickRollPitchControlMode::Unknown(value),
95 }
96 }
97}
98
99#[derive(Serialize, Debug)]
100#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
101pub enum VirtualStickYawControlMode {
102 /// Sets the yaw values to be an angle relative to the north. Positive and negative
103 /// yaw angle is for the aircraft rotating clockwise and counterclockwise,
104 /// respectively. Maximum yaw angle is defined as 180 degrees. Minimum yaw angle is
105 /// defined as -180 degrees.
106 Angle,
107 /// Sets the yaw values to be an angular velocity. Positive and negative angular
108 /// velocity is for the aircraft rotating clockwise and counterclockwise,
109 /// respectively. Maximum yaw angular velocity is defined as 100 degrees/s. Minimum
110 /// yaw angular velocity is defined as -100 degrees/s.
111 Velocity,
112 #[serde(untagged)]
113 Unknown(u8),
114}
115
116impl From<u8> for VirtualStickYawControlMode {
117 fn from(value: u8) -> Self {
118 match value {
119 0 => VirtualStickYawControlMode::Angle,
120 1 => VirtualStickYawControlMode::Velocity,
121 _ => VirtualStickYawControlMode::Unknown(value),
122 }
123 }
124}
125
126#[derive(Serialize, Debug)]
127#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
128pub enum VirtualStickFlightCoordinateSystem {
129 /// Ground coordinate system.
130 Ground,
131 /// Body coordinate system.
132 Body,
133 #[serde(untagged)]
134 Unknown(u8),
135}
136
137impl From<u8> for VirtualStickFlightCoordinateSystem {
138 fn from(value: u8) -> Self {
139 match value {
140 0 => VirtualStickFlightCoordinateSystem::Ground,
141 1 => VirtualStickFlightCoordinateSystem::Body,
142 _ => VirtualStickFlightCoordinateSystem::Unknown(value),
143 }
144 }
145}