From bc990239b5992d03355da3ed6973571d60c31aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pe=C5=82ka?= Date: Tue, 20 Aug 2024 16:33:44 +0200 Subject: [PATCH] Adjusted to review, refactor columns to use AZStd::optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Pełka --- .../Tools/SplineToolsEditorComponent.cpp | 65 ++++++++++++------- .../Source/Tools/SplineToolsEditorComponent.h | 3 +- readme.md | 6 +- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Gems/RobotecSplineTools/Code/Source/Tools/SplineToolsEditorComponent.cpp b/Gems/RobotecSplineTools/Code/Source/Tools/SplineToolsEditorComponent.cpp index 42402cb..cdd4d5c 100644 --- a/Gems/RobotecSplineTools/Code/Source/Tools/SplineToolsEditorComponent.cpp +++ b/Gems/RobotecSplineTools/Code/Source/Tools/SplineToolsEditorComponent.cpp @@ -122,7 +122,7 @@ namespace SplineTools } AZ::Transform worldInvTm(AZ::Transform::Identity()); - if (m_isLocalCoordinates && m_isLatLonAlt) + if (m_isLocalCoordinates && m_isCoordinateLatLon) { AZ_Error("SplineToolsEditorComponent", false, "Cannot use lat, lon, alt coordinates in local coordinates"); QMessageBox::warning( @@ -178,6 +178,15 @@ namespace SplineTools AZStd::vector SplineToolsEditorComponent::GetSplinePointsFromCsv(const AZStd::string& csvFilePath) { + auto getOptionalColumn = [](int column) -> AZStd::optional + { + if (column < 0) + { + return AZStd::nullopt; + } + return column; + }; + try { AZStd::vector ret; @@ -185,54 +194,60 @@ namespace SplineTools csv::CSVReader reader(csvFilePath.c_str()); reader.get_col_names(); - const int index_X = reader.index_of("x"); - const int index_Y = reader.index_of("y"); - const int index_Z = reader.index_of("z"); + const auto indexX = getOptionalColumn(reader.index_of("x")); + const auto indexY = getOptionalColumn(reader.index_of("y")); + const auto indexZ = getOptionalColumn(reader.index_of("z")); - const int index_Lat = reader.index_of("lat"); - const int index_Lon = reader.index_of("lon"); - const int index_Alt = reader.index_of("alt"); + const auto indexLat = getOptionalColumn(reader.index_of("lat")); + const auto indexLon = getOptionalColumn(reader.index_of("lon")); + const auto indexAlt = getOptionalColumn(reader.index_of("alt")); - const bool isCoordinateXY = !(index_X < 0 || index_Y < 0); - const bool isCoordinateLatLon = !(index_Lat < 0 || index_Lon < 0 || index_Alt < 0); - const bool isCoordinateCorrect = isCoordinateXY || isCoordinateLatLon; + m_isCoordinateXY = indexX && indexY; + m_isCoordinateLatLon = indexLat && indexLon && indexAlt; + const bool isCoordinateCorrect = (m_isCoordinateLatLon || m_isCoordinateXY); if (!isCoordinateCorrect) { - AZ_Error("SplineToolsEditorComponent", false, "CSV file must have columns named x, y or lat, lon"); + AZ_Error("SplineToolsEditorComponent", false, "CSV file must have columns named x, y or lat, lon, alt"); + AZStd::string columns; + for (const auto& columnName : reader.get_col_names()) + { + columns += AZStd::string(columnName.c_str()) + ", "; + } + AZ_Printf("SplineToolsEditorComponent", "CSV file columns: %s", columns.c_str()); QMessageBox::warning( - AzToolsFramework::GetActiveWindow(), "Error", "CSV file must have columns named x, y or lat, lon", QMessageBox::Ok); + AzToolsFramework::GetActiveWindow(), + "Error", + "CSV file must have columns named x, y or lat, lon, alt", + QMessageBox::Ok); return {}; } - if (isCoordinateXY) + if (m_isCoordinateXY) { - m_isLatLonAlt = false; for (csv::CSVRow& row : reader) { - AZ::Vector3 point = AZ::Vector3(row[index_X].get(), row[index_Y].get(), 0); + AZ::Vector3 point = AZ::Vector3(row[*indexX].get(), row[*indexY].get(), 0); - // handle Z column - if (index_Z > 0) + if (indexZ > 0) { - point.SetZ(row[index_Z].get()); + point.SetZ(row[*indexZ].get()); } ret.emplace_back(AZStd::move(point)); } } - else if (isCoordinateLatLon) + else if (m_isCoordinateLatLon) { - m_isLatLonAlt = true; for (csv::CSVRow& row : reader) { ROS2::WGS::WGS84Coordinate coordinate; - coordinate.m_latitude = row[index_Lat].get(); - coordinate.m_longitude = row[index_Lon].get(); - coordinate.m_altitude = row[index_Alt].get(); - AZ::Vector3 coordinateInLevel = AZ::Vector3(-1); + coordinate.m_latitude = row[*indexLat].get(); + coordinate.m_longitude = row[*indexLon].get(); + coordinate.m_altitude = row[*indexAlt].get(); + auto coordinateInLevel = AZ::Vector3(-1); ROS2::GeoreferenceRequestsBus::BroadcastResult( - coordinateInLevel, &ROS2::GeoreferenceRequests::ConvertFromWSG84ToLevel, coordinate); + coordinateInLevel, &ROS2::GeoreferenceRequests::ConvertFromWGS84ToLevel, coordinate); ret.emplace_back(AZStd::move(coordinateInLevel)); } diff --git a/Gems/RobotecSplineTools/Code/Source/Tools/SplineToolsEditorComponent.h b/Gems/RobotecSplineTools/Code/Source/Tools/SplineToolsEditorComponent.h index 35fecd0..bffb24b 100644 --- a/Gems/RobotecSplineTools/Code/Source/Tools/SplineToolsEditorComponent.h +++ b/Gems/RobotecSplineTools/Code/Source/Tools/SplineToolsEditorComponent.h @@ -39,7 +39,8 @@ namespace SplineTools private: bool m_isLocalCoordinates = true; - bool m_isLatLonAlt = false; + bool m_isCoordinateXY = false; + bool m_isCoordinateLatLon = false; void ReloadCSVAsset(); AZStd::vector GetSplinePointsFromCsv(const AZStd::string& csvFilePath); diff --git a/readme.md b/readme.md index d5e9f69..f8303cc 100644 --- a/readme.md +++ b/readme.md @@ -53,8 +53,6 @@ TBD A tool that allows to adjust frequency, activate and deactive sensor during game mode. -# Smoothing +# ExposeConsoleToRos -Gem contains a smoothing component that will mimic the movement of an attached entity with the tracked entity. It offers multiple smoothing methods. It allows the lock Z axis to point up direction. -Useful for robots' movement smoothing. -![alt text](doc/Smoothing.png) \ No newline at end of file +A handy, dangerous tool that expose O3DE's console to ROS 2 topic. Please do not use.