Gazebo Msgs

API Reference

12.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 auto result = msgs::SphericalCoordinatesType::LOCAL;
38 switch (_sc)
39 {
40 case math::SphericalCoordinates::CoordinateType::ECEF:
41 result = msgs::SphericalCoordinatesType::ECEF;
42 break;
43 case math::SphericalCoordinates::CoordinateType::GLOBAL:
44 result = msgs::SphericalCoordinatesType::GLOBAL;
45 break;
46 case math::SphericalCoordinates::CoordinateType::SPHERICAL:
47 result = msgs::SphericalCoordinatesType::SPHERICAL;
48 break;
49 case math::SphericalCoordinates::CoordinateType::LOCAL:
50 result = msgs::SphericalCoordinatesType::LOCAL;
51 break;
52 default:
53 std::cerr << "Invalid coordinate type passed" << std::endl;
54 }
55 return result;
56}
57
60 const msgs::SphericalCoordinatesType &_sc)
61{
62 switch (_sc)
63 {
64 case msgs::SphericalCoordinatesType::ECEF:
65 return math::SphericalCoordinates::CoordinateType::ECEF;
66 case msgs::SphericalCoordinatesType::GLOBAL:
67 return math::SphericalCoordinates::CoordinateType::GLOBAL;
68 case msgs::SphericalCoordinatesType::SPHERICAL:
69 return math::SphericalCoordinates::CoordinateType::SPHERICAL;
70 case msgs::SphericalCoordinatesType::LOCAL:
71 return math::SphericalCoordinates::CoordinateType::LOCAL;
72 default:
73 std::cerr << "Invalid coordinate type passed" << std::endl;
74 }
75 return math::SphericalCoordinates::CoordinateType::LOCAL;
76}
77
79inline void Set(gz::msgs::SphericalCoordinates *_msg,
81{
82 if (_data.Surface() == math::SphericalCoordinates::EARTH_WGS84)
83 {
84 _msg->set_surface_model(msgs::SphericalCoordinates::EARTH_WGS84);
85 }
86 else if (_data.Surface() == math::SphericalCoordinates::MOON_SCS)
87 {
88 _msg->set_surface_model(msgs::SphericalCoordinates::MOON_SCS);
89 }
90 else if (_data.Surface() ==
91 math::SphericalCoordinates::CUSTOM_SURFACE)
92 {
93 _msg->set_surface_model(
94 msgs::SphericalCoordinates::CUSTOM_SURFACE);
95 _msg->set_surface_axis_equatorial(_data.SurfaceAxisEquatorial());
96 _msg->set_surface_axis_polar(_data.SurfaceAxisPolar());
97 }
98 else
99 {
100 std::cerr << "Unrecognized spherical surface type ["
101 << _data.Surface()
102 << "]. Not populating message field." << std::endl;
103 }
104 _msg->set_latitude_deg(_data.LatitudeReference().Degree());
105 _msg->set_longitude_deg(_data.LongitudeReference().Degree());
106 _msg->set_elevation(_data.ElevationReference());
107 _msg->set_heading_deg(_data.HeadingOffset().Degree());
108}
109
111 const gz::msgs::SphericalCoordinates &_msg)
112{
113 if (_msg.surface_model() == msgs::SphericalCoordinates::EARTH_WGS84)
114 {
115 _data->SetSurface(math::SphericalCoordinates::EARTH_WGS84);
116 }
117 else if (_msg.surface_model() == msgs::SphericalCoordinates::MOON_SCS)
118 {
119 _data->SetSurface(math::SphericalCoordinates::MOON_SCS);
120 }
121 else if (_msg.surface_model() == msgs::SphericalCoordinates::CUSTOM_SURFACE)
122 {
123 _data->SetSurface(math::SphericalCoordinates::CUSTOM_SURFACE,
124 _msg.surface_axis_equatorial(),
125 _msg.surface_axis_polar());
126 }
127 else
128 {
129 std::cerr << "Unrecognized spherical surface type ["
130 << _msg.surface_model()
131 << "]. Not populating data field." << std::endl;
132 }
133
134 auto lat = gz::math::Angle();
135 lat.SetDegree(_msg.latitude_deg());
136 _data->SetLatitudeReference(lat);
137
138 auto lon = gz::math::Angle();
139 lon.SetDegree(_msg.longitude_deg());
140 _data->SetLongitudeReference(lon);
141
142 auto head = gz::math::Angle();
143 head.SetDegree(_msg.heading_deg());
144 _data->SetHeadingOffset(head);
145
146 _data->SetElevationReference(_msg.elevation());
147}
148
149inline gz::msgs::SphericalCoordinates
151{
152 gz::msgs::SphericalCoordinates ret;
153 Set(&ret, _data);
154 return ret;
155}
156
158 Convert(const gz::msgs::SphericalCoordinates &_msg)
159{
161 Set(&ret, _msg);
162 return ret;
163}
164} // namespace
165} // namespace gz::msgs
166#endif // GZ_MSGS_CONVERT_VECTOR3_HH_