Skip to content
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

Feat/cv orchestrator localize, (GSD Implementation with Unit Tests) #158

Merged
merged 9 commits into from
Apr 27, 2024

Conversation

miyatakazuya
Copy link
Contributor

Closes #20

  • Implements GSD-based Localization Algorithm
  • Added Unit Tests from Blender sim test cases
  • Currently permits >15ft error, most of the time 1~13ft.
  • Further test cases required for edge cases.

@miyatakazuya miyatakazuya self-assigned this Apr 22, 2024
@miyatakazuya miyatakazuya added the feature New feature or request label Apr 22, 2024
@miyatakazuya miyatakazuya marked this pull request as ready for review April 26, 2024 00:24
@miyatakazuya miyatakazuya requested a review from atar13 April 26, 2024 01:19
Copy link
Member

@atar13 atar13 left a comment

Choose a reason for hiding this comment

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

Great job on getting this completed and putting in all the work to make sure the code is readable and well documented. Test cases are a great addition that will give us a lot more confidence in our localization algorithm.

This should be ready to merge once you update this branch with the recent changes on main. You can do this by running git fetch and then git merge origin/main. There will be a few conflicting files so feel free to let me know if you're unsure about which changes to keep.

@@ -81,6 +84,8 @@ class ECEFLocalization : Localization {
class GSDLocalization : Localization {
public:
GPSCoord localize(const ImageTelemetry& telemetry, const Bbox& targetBbox) override;
GPSCoord CalcOffset(const double offset_x, const double offset_y, const double lat, const double lon);
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: I wouldn't hate a more descriptive name instead of CalcOffset but it's not that big of a deal.

Comment on lines 113 to 138
double GSD = (SENSOR_WIDTH * (telemetry.altitude)) / (FOCAL_LENGTH_MM * IMG_WIDTH_PX);

// Midpoints of the image
double img_mid_x = IMG_WIDTH_PX / 2;
double img_mid_y = IMG_HEIGHT_PX / 2;

//midpoints of bounding box around the target
double target_x = (targetBbox.x1 + targetBbox.x2)/2;
double target_y = (targetBbox.y1 + targetBbox.y2)/2;

// calculations of bearing
// L = (distance(middle, bbox))*GSD
double length = (sqrt(pow((target_x - img_mid_x), 2) + pow((target_y - img_mid_y), 2) * GSD));

//Translate Image Cordinates to Camera Cordinate Frame (Origin to Center of Image instead of Top Left)
double target_camera_cord_x = target_x - (IMG_WIDTH_PX / 2);
double target_camera_cord_y = (IMG_HEIGHT_PX / 2) - target_y;

//Angle of Bearing (Angle from north to target)
double thetaB = telemetry.heading + atan(target_camera_cord_x / target_camera_cord_y);

//Translate bearing to the 3 quadrant if applicable
if (target_camera_cord_x < 0 && target_camera_cord_y < 0){
thetaB = 180.0 + thetaB;
}
Copy link
Member

Choose a reason for hiding this comment

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

Fantastic comments on this function. They really make it a lot easier to parse what's going on.

*/

double GSDLocalization::distanceInMetersBetweenCords(const double lat1, const double lon1, const double lat2, const double lon2){
Copy link
Member

Choose a reason for hiding this comment

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

I really like the inclusion of this function for reasoning about accuracy in terms of feet/meters instead of latitude/longitude.

@miyatakazuya
Copy link
Contributor Author

@atar13 What do you want me to do for the interface.hpp ImageTelemetry? I added the heading parameter because the GSD requires it but it is not on the main version of ImageTelemetry.

@atar13
Copy link
Member

atar13 commented Apr 26, 2024

@atar13 What do you want me to do for the interface.hpp ImageTelemetry? I added the heading parameter because the GSD requires it but it is not on the main version of ImageTelemetry.

We should keep your version with heading. You'll just need to update anywhere the ImageTelemetry struct is instantiated to have a heading value. You can verify you fixed everything by running ninja obcpp to make sure everything's still compiling.

@miyatakazuya
Copy link
Contributor Author

@atar13 The merge was good and it compiles along with the tests. It didn't pass the format checker so let me know if I should try to resolve that. Otherwise the localization unit test still outputs cout values so if I should remove those lmk but they do help with seeing the current state/accuracy of localization.

...
[----------] 1 test from CVLocalization
[ RUN      ] CVLocalization.LocalizationAccuracy
directly underneath
Error: 0.0162771 feet
Blender Case 1
Error: 13.8251 feet
Blender Case 2
Error: 1.10303 feet
Blender Case 3
Error: 13.2471 feet
Blender Case 4
Error: 12.2687 feet
Blender Case 5
Error: 3.38631 feet
Blender Case 6
Error: 4.55962 feet
[       OK ] CVLocalization.LocalizationAccuracy (0 ms)
[----------] 1 test from CVLocalization (0 ms total)
...

@atar13
Copy link
Member

atar13 commented Apr 27, 2024

@atar13 The merge was good and it compiles along with the tests. It didn't pass the format checker so let me know if I should try to resolve that. Otherwise the localization unit test still outputs cout values so if I should remove those lmk but they do help with seeing the current state/accuracy of localization.

...
[----------] 1 test from CVLocalization
[ RUN      ] CVLocalization.LocalizationAccuracy
directly underneath
Error: 0.0162771 feet
Blender Case 1
Error: 13.8251 feet
Blender Case 2
Error: 1.10303 feet
Blender Case 3
Error: 13.2471 feet
Blender Case 4
Error: 12.2687 feet
Blender Case 5
Error: 3.38631 feet
Blender Case 6
Error: 4.55962 feet
[       OK ] CVLocalization.LocalizationAccuracy (0 ms)
[----------] 1 test from CVLocalization (0 ms total)
...

Yeah, the last thing before merging will be to address the linting/format errors. You can see what it's complaining about here or by running make lint in the build directory locally. If you want to ignore any errors you can follow the instructions here.

I think the prints in the unit test should be fine. Some of the other tests already print to standard out so it's not an issue.

@miyatakazuya miyatakazuya merged commit c5acd6c into main Apr 27, 2024
2 checks passed
@codyprupp codyprupp deleted the feat/cv-orchestrator-localize branch May 4, 2024 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate Localization
2 participants