Skip to content

Commit 04ddec6

Browse files
authored
fix(esp-box): Fix example IMU vector calculation on ESP-BOX (#474)
1 parent 17f243e commit 04ddec6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

components/esp-box/example/main/esp_box_example.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ extern "C" void app_main(void) {
246246
auto orientation = imu->get_orientation();
247247
auto gravity_vector = imu->get_gravity_vector();
248248

249+
auto box_type = box.box_type();
250+
if (box_type == espp::EspBox::BoxType::BOX) {
251+
std::swap(gravity_vector.x, gravity_vector.y);
252+
gravity_vector.y = -gravity_vector.y; // flip y axis
253+
}
254+
249255
std::string text = fmt::format("{}\n\n\n\n\n", label_text);
250256
text += fmt::format("Accel: {:02.2f} {:02.2f} {:02.2f}\n", accel.x, accel.y, accel.z);
251257
text += fmt::format("Gyro: {:03.2f} {:03.2f} {:03.2f}\n", espp::deg_to_rad(gyro.x),
@@ -274,6 +280,12 @@ extern "C" void app_main(void) {
274280
float vx = sin(pitch);
275281
float vy = -cos(pitch) * sin(roll);
276282
[[maybe_unused]] float vz = -cos(pitch) * cos(roll);
283+
284+
if (box_type == espp::EspBox::BoxType::BOX) {
285+
std::swap(vx, vy);
286+
vy = -vy; // flip y axis
287+
}
288+
277289
x1 = x0 + 50 * vx;
278290
y1 = y0 + 50 * vy;
279291

0 commit comments

Comments
 (0)