diff --git a/src/cpm_application.cpp b/src/cpm_application.cpp index bc2b084..2fc381e 100644 --- a/src/cpm_application.cpp +++ b/src/cpm_application.cpp @@ -93,13 +93,16 @@ namespace v2x { std::string mgrs; int zone; + int grid_num_x = 4; + int grid_num_y = 39; + int grid_size = 100000; bool northp; double x, y; GeographicLib::UTMUPS::Forward(lat, lon, zone, northp, x, y); - GeographicLib::MGRS::Forward(zone, northp, x, y, lat, 5, mgrs); + // GeographicLib::MGRS::Forward(zone, northp, x, y, lat, 5, mgrs); - int x_mgrs = std::stoi(mgrs.substr(5, 5)); - int y_mgrs = std::stoi(mgrs.substr(10, 5)); + double x_mgrs = x - grid_num_x * grid_size; + double y_mgrs = y - grid_num_y * grid_size; // RCLCPP_INFO(node_->get_logger(), "cpm.(RP).mgrs = %s, %d, %d", mgrs.c_str(), x_mgrs, y_mgrs); // Calculate orientation from Heading diff --git a/src/v2x_app.cpp b/src/v2x_app.cpp index 3ed234f..e8a25c1 100644 --- a/src/v2x_app.cpp +++ b/src/v2x_app.cpp @@ -74,15 +74,33 @@ namespace v2x double roll, pitch, yaw; matrix.getRPY(roll, pitch, yaw); - char mgrs[20]; - int zone, prec; - bool northp; + char mgrs[30]; + int zone = 54; + int grid_num_x = 4; + int grid_num_y = 39; + int grid_size = 100000; + int prec; + bool northp = true; double x_mgrs, y_mgrs; - double lat, lon; - sprintf(mgrs, "54SVE%.5d%.5d", (int)x, (int)y); - GeographicLib::MGRS::Reverse(mgrs, zone, northp, x_mgrs, y_mgrs, prec); - GeographicLib::UTMUPS::Reverse(zone, northp, x_mgrs, y_mgrs, lat, lon); + double lat, lon; + // sprintf(mgrs, "54SVE%.3f%.3f", x, y); + // RCLCPP_INFO(node_->get_logger(), "%s", mgrs); + + // Convert MGRS coordinate to UTM coordinate. + // GeographicLib::MGRS::Reverse(mgrs, zone, northp, x_mgrs, y_mgrs, prec); + + // Reverse projection from UTM to geographic. + GeographicLib::UTMUPS::Reverse( + zone, + northp, + grid_num_x * grid_size + x, + grid_num_y * grid_size + y, + lat, + lon + ); + + RCLCPP_INFO(node_->get_logger(), "%f, %f", lat, lon); if (cp && cp_started_) { cp->updateMGRS(&x, &y);