Skip to content

fix(esp-box): Fix example IMU vector calculation on ESP-BOX #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2025

Conversation

finger563
Copy link
Contributor

Description

  • Update the esp-box/example to rotate the gravity vector depending on the box type, since the original ESP-BOX has a different IMU orientation on board.

Motivation and Context

Ensures the output of the example is the same across ESP-BOX and ESP-BOX-3

How has this been tested?

Build and run esp-box/example on ESP-BOX and ensure that in the default screen orientation, the gravity vectors on screen point in the right direction.

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

@finger563 finger563 requested a review from Copilot July 12, 2025 23:13
@finger563 finger563 self-assigned this Jul 12, 2025
@finger563 finger563 added bug Something isn't working examples esp-box labels Jul 12, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the ESP-BOX example to rotate the gravity and computed vectors when running on the original ESP-BOX, ensuring consistent output across ESP-BOX and ESP-BOX-3.

  • Introduce a box_type check to conditionally swap and flip the gravity vector.
  • Apply the same conditional rotation logic to the vx and vy components.
Comments suppressed due to low confidence (1)

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

  • There are no tests covering the new IMU orientation adjustment; consider adding unit or integration tests to verify the gravity vector and computed vector rotations for different box types.
         auto box_type = box.box_type();

Comment on lines 248 to +254

auto box_type = box.box_type();
if (box_type == espp::EspBox::BoxType::BOX) {
std::swap(gravity_vector.x, gravity_vector.y);
gravity_vector.y = -gravity_vector.y; // flip y axis
}

Copy link
Preview

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the box-type check and vector rotation logic into a shared helper function or moving the box_type declaration closer to both uses to reduce duplicated code and improve readability.

Suggested change
auto box_type = box.box_type();
if (box_type == espp::EspBox::BoxType::BOX) {
std::swap(gravity_vector.x, gravity_vector.y);
gravity_vector.y = -gravity_vector.y; // flip y axis
}
gravity_vector = adjust_gravity_vector(gravity_vector, box.box_type());

Copilot uses AI. Check for mistakes.

@@ -246,6 +246,12 @@ extern "C" void app_main(void) {
auto orientation = imu->get_orientation();
auto gravity_vector = imu->get_gravity_vector();

auto box_type = box.box_type();
if (box_type == espp::EspBox::BoxType::BOX) {
std::swap(gravity_vector.x, gravity_vector.y);
Copy link
Preview

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The swap-and-flip pattern is duplicated for both the gravity vector and the (vx, vy) calculations; extracting this transformation into a reusable helper would avoid duplication and make future adjustments easier.

Copilot uses AI. Check for mistakes.

@finger563 finger563 merged commit 04ddec6 into main Jul 12, 2025
84 of 85 checks passed
@finger563 finger563 deleted the fix/esp-box-example branch July 12, 2025 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working esp-box examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant