Gazebo Msgs

API Reference

11.0.0~pre1
SphericalCoordinates.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17#ifndef GZ_MSGS_CONVERT_SPHERICALCOORDINATES_HH_
18#define GZ_MSGS_CONVERT_SPHERICALCOORDINATES_HH_
19
20#include <gz/msgs/config.hh>
21
22// Message Headers
23#include "gz/msgs/spherical_coordinates.pb.h"
24
25// Data Headers
27
28namespace gz::msgs {
29// Inline bracket to help doxygen filtering.
30inline namespace GZ_MSGS_VERSION_NAMESPACE {
31
32
34inline msgs::SphericalCoordinatesType ConvertCoord(
36{
37 GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION
38 auto result = msgs::SphericalCoordinatesType::LOCAL2;
39 GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION
40 switch (_sc)
41 {
42 case math::SphericalCoordinates::CoordinateType::ECEF:
43 result = msgs::SphericalCoordinatesType::ECEF;
44 break;
45 case math::SphericalCoordinates::CoordinateType::GLOBAL:
46 result = msgs::SphericalCoordinatesType::GLOBAL;
47 break;
48 case math::SphericalCoordinates::CoordinateType::SPHERICAL:
49 result = msgs::SphericalCoordinatesType::SPHERICAL;
50 break;
51 case math::SphericalCoordinates::CoordinateType::LOCAL:
52 result = msgs::SphericalCoordinatesType::LOCAL;
53 break;
54 GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION
55 case math::SphericalCoordinates::CoordinateType::LOCAL2:
56 result = msgs::SphericalCoordinatesType::LOCAL2;
57 break;
58 GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION
59 default:
60 std::cerr << "Invalid coordinate type passed" << std::endl;
61 }
62 return result;
63}
64
67 const msgs::SphericalCoordinatesType &_sc)
68{
69 switch (_sc)
70 {
71 case msgs::SphericalCoordinatesType::ECEF:
72 return math::SphericalCoordinates::CoordinateType::ECEF;
73 case msgs::SphericalCoordinatesType::GLOBAL:
74 return math::SphericalCoordinates::CoordinateType::GLOBAL;
75 case msgs::SphericalCoordinatesType::SPHERICAL:
76 return math::SphericalCoordinates::CoordinateType::SPHERICAL;
77 case msgs::SphericalCoordinatesType::LOCAL:
78 return math::SphericalCoordinates::CoordinateType::LOCAL;
79 GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION
80 case msgs::SphericalCoordinatesType::LOCAL2:
81 return math::SphericalCoordinates::CoordinateType::LOCAL2;
82 GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION
83 default:
84 std::cerr << "Invalid coordinate type passed" << std::endl;
85 }
86 GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION
87 return math::SphericalCoordinates::CoordinateType::LOCAL2;
88 GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION
89}
90
92inline void Set(gz::msgs::SphericalCoordinates *_msg,
94{
95 if (_data.Surface() == math::SphericalCoordinates::EARTH_WGS84)
96 {
97 _msg->set_surface_model(msgs::SphericalCoordinates::EARTH_WGS84);
98 }
99 else if (_data.Surface() == math::SphericalCoordinates::MOON_SCS)
100 {
101 _msg->set_surface_model(msgs::SphericalCoordinates::MOON_SCS);
102 }
103 else if (_data.Surface() ==
104 math::SphericalCoordinates::CUSTOM_SURFACE)
105 {
106 _msg->set_surface_model(
107 msgs::SphericalCoordinates::CUSTOM_SURFACE);
108 _msg->set_surface_axis_equatorial(_data.SurfaceAxisEquatorial());
109 _msg->set_surface_axis_polar(_data.SurfaceAxisPolar());
110 }
111 else
112 {
113 std::cerr << "Unrecognized spherical surface type ["
114 << _data.Surface()
115 << "]. Not populating message field." << std::endl;
116 }
117 _msg->set_latitude_deg(_data.LatitudeReference().Degree());
118 _msg->set_longitude_deg(_data.LongitudeReference().Degree());
119 _msg->set_elevation(_data.ElevationReference());
120 _msg->set_heading_deg(_data.HeadingOffset().Degree());
121}
122
124 const gz::msgs::SphericalCoordinates &_msg)
125{
126 if (_msg.surface_model() == msgs::SphericalCoordinates::EARTH_WGS84)
127 {
128 _data->SetSurface(math::SphericalCoordinates::EARTH_WGS84);
129 }
130 else if (_msg.surface_model() == msgs::SphericalCoordinates::MOON_SCS)
131 {
132 _data->SetSurface(math::SphericalCoordinates::MOON_SCS);
133 }
134 else if (_msg.surface_model() == msgs::SphericalCoordinates::CUSTOM_SURFACE)
135 {
136 _data->SetSurface(math::SphericalCoordinates::CUSTOM_SURFACE,
137 _msg.surface_axis_equatorial(),
138 _msg.surface_axis_polar());
139 }
140 else
141 {
142 std::cerr << "Unrecognized spherical surface type ["
143 << _msg.surface_model()
144 << "]. Not populating data field." << std::endl;
145 }
146
147 auto lat = gz::math::Angle();
148 lat.SetDegree(_msg.latitude_deg());
149 _data->SetLatitudeReference(lat);
150
151 auto lon = gz::math::Angle();
152 lon.SetDegree(_msg.longitude_deg());
153 _data->SetLongitudeReference(lon);
154
155 auto head = gz::math::Angle();
156 head.SetDegree(_msg.heading_deg());
157 _data->SetHeadingOffset(head);
158
159 _data->SetElevationReference(_msg.elevation());
160}
161
162inline gz::msgs::SphericalCoordinates
164{
165 gz::msgs::SphericalCoordinates ret;
166 Set(&ret, _data);
167 return ret;
168}
169
171 Convert(const gz::msgs::SphericalCoordinates &_msg)
172{
174 Set(&ret, _msg);
175 return ret;
176}
177} // namespce
178} // namespace gz::msgs
179#endif // GZ_MSGS_CONVERT_VECTOR3_HH_