Skip to content

Commit

Permalink
Adds a message that allows loading environments via a topic
Browse files Browse the repository at this point in the history
Required by gazebosim/gz-sim#1842

Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org>
  • Loading branch information
arjo129 committed Jan 25, 2023
1 parent f88966e commit f4b43a5
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/gz/msgs/Utility.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions proto/gz/msgs/data_load_options.proto
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 20 additions & 0 deletions proto/gz/msgs/spherical_coordinates.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions src/Utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
23 changes: 23 additions & 0 deletions src/Utility_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit f4b43a5

Please sign in to comment.