From f4b43a5ac0a9ad8d942fe90749e3df6b29ae386f Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Tue, 20 Dec 2022 22:10:46 +0800 Subject: [PATCH] Adds a message that allows loading environments via a topic Required by https://github.com/gazebosim/gz-sim/pull/1842 Signed-off-by: Arjo Chakravarty --- include/gz/msgs/Utility.hh | 16 ++++++ proto/gz/msgs/data_load_options.proto | 60 +++++++++++++++++++++++ proto/gz/msgs/spherical_coordinates.proto | 20 ++++++++ src/Utility.cc | 38 ++++++++++++++ src/Utility_TEST.cc | 23 +++++++++ 5 files changed, 157 insertions(+) create mode 100644 proto/gz/msgs/data_load_options.proto diff --git a/include/gz/msgs/Utility.hh b/include/gz/msgs/Utility.hh index b737da96..1d57c5ac 100644 --- a/include/gz/msgs/Utility.hh +++ b/include/gz/msgs/Utility.hh @@ -94,6 +94,14 @@ namespace gz math::SphericalCoordinates Convert( const msgs::SphericalCoordinates &_coord); + /// \brief Convert a msgs::SphericalCoordinatesType to an + /// gz::math::SphericalCoordinates::CoordinateTpye + /// \param[in] _sc The spherical coordinate type to convert + /// \return A gz::math::SphericalCoordinatesType object + GZ_MSGS_VISIBLE + math::SphericalCoordinates::CoordinateType Convert( + const msgs::SphericalCoordinatesType &_sc); + /// \brief Convert a msgs::AxisAlignedBox to an /// gz::math::AxisAlignedBox /// \param[in] _b The axis aligned box to convert @@ -212,6 +220,14 @@ namespace gz msgs::SphericalCoordinates Convert( const math::SphericalCoordinates &_coord); + /// \brief Convert a msgs::SphericalCoordinatesType to an + /// gz::math::SphericalCoordinates::CoordinateTpye + /// \param[in] _coord The spherical coordinates to convert + /// \return A gz::math::SphericalCoordinatesType object + GZ_MSGS_VISIBLE + msgs::SphericalCoordinatesType ConvertCoord( + const math::SphericalCoordinates::CoordinateType &_sc); + /// \brief Convert a gz::math::Planed to a msgs::PlaneGeom /// \param[in] _p The plane to convert /// \return A msgs::PlaneGeom object diff --git a/proto/gz/msgs/data_load_options.proto b/proto/gz/msgs/data_load_options.proto new file mode 100644 index 00000000..f83c630f --- /dev/null +++ b/proto/gz/msgs/data_load_options.proto @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2022 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +syntax = "proto3"; +package gz.msgs; +option java_package = "com.gz.msgs"; +option java_outer_classname = "DataLoadPathOptions"; + +import "gz/msgs/spherical_coordinates.proto"; + + + +/// \brief Used for specifying how to load environmental data +message DataLoadPathOptions +{ + /// \brief + enum DataAngularUnits + { + RADIANS = 0; + DEGREES = 1; + } + + /// \brief File path to load + string path = 1; + + /// \brief Name of time axis + string time = 2; + + /// \brief Is the data static in time + bool static_time = 3; + + /// \brief Name of x axis + string x = 4; + + /// \brief Name of y axis + string y = 5; + + /// \brief Name of z axis + string z = 6; + + /// Units + DataAngularUnits units = 7; + + /// Spherical Coodinate type + gz.msgs.SphericalCoordinatesType coordinate_type = 8; +} \ No newline at end of file diff --git a/proto/gz/msgs/spherical_coordinates.proto b/proto/gz/msgs/spherical_coordinates.proto index 9b485277..aa2135ca 100644 --- a/proto/gz/msgs/spherical_coordinates.proto +++ b/proto/gz/msgs/spherical_coordinates.proto @@ -27,6 +27,26 @@ option java_outer_classname = "SphericalCoordinatesProtos"; import "gz/msgs/entity.proto"; import "gz/msgs/header.proto"; +enum SphericalCoordinatesType +{ + /// \brief Latitude, Longitude and Altitude by SurfaceType + SPHERICAL = 0; + + /// \brief Earth centered, earth fixed Cartesian + ECEF = 1; + + /// \brief Local tangent plane (East, North, Up) + GLOBAL = 2; + + /// \brief Heading-adjusted tangent plane (X, Y, Z) + /// This has kept a bug for backwards compatibility, use + /// LOCAL2 for the correct behaviour. + LOCAL = 3; + + /// \brief Heading-adjusted tangent plane (X, Y, Z) + LOCAL2 = 4; +} + message SphericalCoordinates { /// \brief Planetary surface models. diff --git a/src/Utility.cc b/src/Utility.cc index dfc7995b..44b59d66 100644 --- a/src/Utility.cc +++ b/src/Utility.cc @@ -183,6 +183,25 @@ namespace gz return out; } + ///////////////////////////////////////////// + math::SphericalCoordinates::CoordinateType Convert( + const msgs::SphericalCoordinatesType &_sc) + { + switch (_sc) + { + case msgs::SphericalCoordinatesType::ECEF: + return math::SphericalCoordinates::CoordinateType::ECEF; + case msgs::SphericalCoordinatesType::GLOBAL: + return math::SphericalCoordinates::CoordinateType::GLOBAL; + case msgs::SphericalCoordinatesType::SPHERICAL: + return math::SphericalCoordinates::CoordinateType::SPHERICAL; + case msgs::SphericalCoordinatesType::LOCAL: + return math::SphericalCoordinates::CoordinateType::LOCAL; + case msgs::SphericalCoordinatesType::LOCAL2: + return math::SphericalCoordinates::CoordinateType::LOCAL2; + } + } + ///////////////////////////////////////////// math::AxisAlignedBox Convert(const msgs::AxisAlignedBox &_b) { @@ -349,6 +368,25 @@ namespace gz return result; } + ///////////////////////////////////////////// + msgs::SphericalCoordinatesType ConvertCoord( + const math::SphericalCoordinates::CoordinateType &_sc) + { + switch (_sc) + { + case math::SphericalCoordinates::CoordinateType::ECEF: + return msgs::SphericalCoordinatesType::ECEF; + case math::SphericalCoordinates::CoordinateType::GLOBAL: + return msgs::SphericalCoordinatesType::GLOBAL; + case math::SphericalCoordinates::CoordinateType::SPHERICAL: + return msgs::SphericalCoordinatesType::SPHERICAL; + case math::SphericalCoordinates::CoordinateType::LOCAL: + return msgs::SphericalCoordinatesType::LOCAL; + case math::SphericalCoordinates::CoordinateType::LOCAL2: + return msgs::SphericalCoordinatesType::LOCAL2; + } + } + ///////////////////////////////////////////// msgs::PlaneGeom Convert(const gz::math::Planed &_p) { diff --git a/src/Utility_TEST.cc b/src/Utility_TEST.cc index dac61e9e..82caa059 100644 --- a/src/Utility_TEST.cc +++ b/src/Utility_TEST.cc @@ -398,6 +398,29 @@ TEST(MsgsTest, ConvertMathSphericalCoordinatesToMsgs) EXPECT_DOUBLE_EQ(10000, mathCustom.SurfaceAxisPolar()); } +///////////////////////////////////////////////// +TEST(MsgsTest, ConvertMsgsSphericalCoordinatesTypeToMath) +{ + EXPECT_EQ(Convert(msgs::SphericalCoordinatesType::ECEF), + math::SphericalCoordinates::CoordinateType::ECEF); + EXPECT_EQ(Convert(msgs::SphericalCoordinatesType::GLOBAL), + math::SphericalCoordinates::CoordinateType::GLOBAL); + EXPECT_EQ(Convert(msgs::SphericalCoordinatesType::SPHERICAL), + math::SphericalCoordinates::CoordinateType::SPHERICAL); + EXPECT_EQ(Convert(msgs::SphericalCoordinatesType::LOCAL), + math::SphericalCoordinates::CoordinateType::LOCAL); + EXPECT_EQ(Convert(msgs::SphericalCoordinatesType::LOCAL2), + math::SphericalCoordinates::CoordinateType::LOCAL2); +} + +///////////////////////////////////////////////// +TEST(MsgsTest, ConvertMathSphericalCoordinatedTypeToMsg) +{ + EXPECT_EQ(msgs::ConvertCoord( + math::SphericalCoordinates::CoordinateType::ECEF), + msgs::SphericalCoordinatesType::ECEF); +} + ///////////////////////////////////////////////// TEST(UtilityTest, ConvertStringMsg) {