Skip to content

Commit 831525e

Browse files
authored
Merge branch 'main' into chapulina/7/new_ign
2 parents 59c68de + 0a09d3d commit 831525e

File tree

3 files changed

+131
-8
lines changed

3 files changed

+131
-8
lines changed

proto/gz/msgs/spherical_coordinates.proto

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,42 @@ message SphericalCoordinates
3333
enum SurfaceModel
3434
{
3535
/// \brief World Geodetic System 1984
36-
EARTH_WGS84 = 0;
36+
EARTH_WGS84 = 0;
37+
38+
/// \brief Model of the moon, based on the Selenographic
39+
/// coordinate system, see wikipedia: Selenographic
40+
/// Coordinate System.
41+
MOON_SCS = 1;
42+
43+
/// \brief Custom surface type
44+
CUSTOM_SURFACE = 2;
3745
}
3846

3947
/// \brief Optional header data.
40-
Header header = 1;
48+
Header header = 1;
4149

4250
/// \brief Planetary surface model.
43-
SurfaceModel surface_model = 2;
51+
SurfaceModel surface_model = 2;
4452

4553
/// \brief Latitude in degrees.
46-
double latitude_deg = 3;
54+
double latitude_deg = 3;
4755

4856
/// \brief Longitude in degrees.
49-
double longitude_deg = 4;
57+
double longitude_deg = 4;
5058

5159
/// \brief Elevation in meters.
52-
double elevation = 5;
60+
double elevation = 5;
5361

5462
/// \brief Heading in degrees.
55-
double heading_deg = 6;
63+
double heading_deg = 6;
5664

5765
/// \brief Entity that the coordinates apply to.
5866
/// If not set, defaults to the world origin.
59-
Entity entity = 7;
67+
Entity entity = 7;
68+
69+
/// \brief Equatorial axis in meters.
70+
double surface_axis_equatorial = 8;
71+
72+
/// \brief Polar axis in meters.
73+
double surface_axis_polar = 9;
6074
}

src/Utility.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ namespace gz
130130
{
131131
out.SetSurface(math::SphericalCoordinates::EARTH_WGS84);
132132
}
133+
else if (_sc.surface_model() == msgs::SphericalCoordinates::MOON_SCS)
134+
{
135+
out.SetSurface(math::SphericalCoordinates::MOON_SCS);
136+
}
137+
else if (_sc.surface_model() ==
138+
msgs::SphericalCoordinates::CUSTOM_SURFACE)
139+
{
140+
out.SetSurface(math::SphericalCoordinates::CUSTOM_SURFACE,
141+
_sc.surface_axis_equatorial(), _sc.surface_axis_polar());
142+
}
133143
else
134144
{
135145
std::cerr << "Unrecognized spherical surface type ["
@@ -472,6 +482,18 @@ namespace gz
472482
{
473483
_sc->set_surface_model(msgs::SphericalCoordinates::EARTH_WGS84);
474484
}
485+
else if (_m.Surface() == math::SphericalCoordinates::MOON_SCS)
486+
{
487+
_sc->set_surface_model(msgs::SphericalCoordinates::MOON_SCS);
488+
}
489+
else if (_m.Surface() ==
490+
math::SphericalCoordinates::CUSTOM_SURFACE)
491+
{
492+
_sc->set_surface_model(
493+
msgs::SphericalCoordinates::CUSTOM_SURFACE);
494+
_sc->set_surface_axis_equatorial(_m.SurfaceAxisEquatorial());
495+
_sc->set_surface_axis_polar(_m.SurfaceAxisPolar());
496+
}
475497
else
476498
{
477499
std::cerr << "Unrecognized spherical surface type ["

src/Utility_TEST.cc

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,59 @@ TEST(MsgsTest, ConvertMathSphericalCoordinatesToMsgs)
258258
EXPECT_DOUBLE_EQ(2.2, math.LongitudeReference().Degree());
259259
EXPECT_DOUBLE_EQ(3.3, math.ElevationReference());
260260
EXPECT_DOUBLE_EQ(0.4, math.HeadingOffset().Degree());
261+
262+
// For Moon's surface.
263+
auto msgMoon = msgs::Convert(
264+
math::SphericalCoordinates(
265+
math::SphericalCoordinates::SurfaceType::MOON_SCS,
266+
GZ_DTOR(1.1), GZ_DTOR(2.2), 3.3, GZ_DTOR(0.4)));
267+
268+
EXPECT_EQ(msgs::SphericalCoordinates::MOON_SCS,
269+
msgMoon.surface_model());
270+
EXPECT_DOUBLE_EQ(1.1, msgMoon.latitude_deg());
271+
EXPECT_DOUBLE_EQ(2.2, msgMoon.longitude_deg());
272+
EXPECT_DOUBLE_EQ(3.3, msgMoon.elevation());
273+
EXPECT_DOUBLE_EQ(0.4, msgMoon.heading_deg());
274+
275+
auto mathMoon = msgs::Convert(msgMoon);
276+
277+
EXPECT_EQ(math::SphericalCoordinates::MOON_SCS,
278+
mathMoon.Surface());
279+
EXPECT_DOUBLE_EQ(1.1, mathMoon.LatitudeReference().Degree());
280+
EXPECT_DOUBLE_EQ(2.2, mathMoon.LongitudeReference().Degree());
281+
EXPECT_DOUBLE_EQ(3.3, mathMoon.ElevationReference());
282+
EXPECT_DOUBLE_EQ(0.4, mathMoon.HeadingOffset().Degree());
283+
284+
// For custom surfaces.
285+
auto sc = math::SphericalCoordinates(
286+
math::SphericalCoordinates::CUSTOM_SURFACE,
287+
12000, 10000);
288+
sc.SetLatitudeReference(GZ_DTOR(1.1));
289+
sc.SetLongitudeReference(GZ_DTOR(2.2));
290+
sc.SetElevationReference(3.3);
291+
sc.SetHeadingOffset(GZ_DTOR(0.4));
292+
293+
auto msgCustom = msgs::Convert(sc);
294+
295+
EXPECT_EQ(msgs::SphericalCoordinates::CUSTOM_SURFACE,
296+
msgCustom.surface_model());
297+
EXPECT_DOUBLE_EQ(1.1, msgCustom.latitude_deg());
298+
EXPECT_DOUBLE_EQ(2.2, msgCustom.longitude_deg());
299+
EXPECT_DOUBLE_EQ(3.3, msgCustom.elevation());
300+
EXPECT_DOUBLE_EQ(0.4, msgCustom.heading_deg());
301+
EXPECT_DOUBLE_EQ(12000, msgCustom.surface_axis_equatorial());
302+
EXPECT_DOUBLE_EQ(10000, msgCustom.surface_axis_polar());
303+
304+
auto mathCustom = msgs::Convert(msgCustom);
305+
306+
EXPECT_EQ(math::SphericalCoordinates::CUSTOM_SURFACE,
307+
mathCustom.Surface());
308+
EXPECT_DOUBLE_EQ(1.1, mathCustom.LatitudeReference().Degree());
309+
EXPECT_DOUBLE_EQ(2.2, mathCustom.LongitudeReference().Degree());
310+
EXPECT_DOUBLE_EQ(3.3, mathCustom.ElevationReference());
311+
EXPECT_DOUBLE_EQ(0.4, mathCustom.HeadingOffset().Degree());
312+
EXPECT_DOUBLE_EQ(12000, mathCustom.SurfaceAxisEquatorial());
313+
EXPECT_DOUBLE_EQ(10000, mathCustom.SurfaceAxisPolar());
261314
}
262315

263316
/////////////////////////////////////////////////
@@ -488,6 +541,40 @@ TEST(MsgsTest, SetSphericalCoordinates)
488541
EXPECT_DOUBLE_EQ(2.2, msg.longitude_deg());
489542
EXPECT_DOUBLE_EQ(3.3, msg.elevation());
490543
EXPECT_DOUBLE_EQ(0.4, msg.heading_deg());
544+
545+
// For Moon's surface.
546+
msgs::SphericalCoordinates msgMoon;
547+
msgs::Set(&msgMoon, math::SphericalCoordinates(
548+
math::SphericalCoordinates::SurfaceType::MOON_SCS,
549+
GZ_DTOR(1.2), GZ_DTOR(2.3), 3.4, GZ_DTOR(0.5)));
550+
551+
EXPECT_EQ(msgs::SphericalCoordinates::MOON_SCS,
552+
msgMoon.surface_model());
553+
EXPECT_DOUBLE_EQ(1.2, msgMoon.latitude_deg());
554+
EXPECT_DOUBLE_EQ(2.3, msgMoon.longitude_deg());
555+
EXPECT_DOUBLE_EQ(3.4, msgMoon.elevation());
556+
EXPECT_DOUBLE_EQ(0.5, msgMoon.heading_deg());
557+
558+
// For a custom surface.
559+
msgs::SphericalCoordinates msgCustom;
560+
auto sc = math::SphericalCoordinates(
561+
math::SphericalCoordinates::CUSTOM_SURFACE,
562+
12000, 10000);
563+
sc.SetLatitudeReference(GZ_DTOR(1.9));
564+
sc.SetLongitudeReference(GZ_DTOR(2.8));
565+
sc.SetElevationReference(3.7);
566+
sc.SetHeadingOffset(GZ_DTOR(0.6));
567+
568+
msgs::Set(&msgCustom, sc);
569+
570+
EXPECT_EQ(msgs::SphericalCoordinates::CUSTOM_SURFACE,
571+
msgCustom.surface_model());
572+
EXPECT_DOUBLE_EQ(1.9, msgCustom.latitude_deg());
573+
EXPECT_DOUBLE_EQ(2.8, msgCustom.longitude_deg());
574+
EXPECT_DOUBLE_EQ(3.7, msgCustom.elevation());
575+
EXPECT_DOUBLE_EQ(0.6, msgCustom.heading_deg());
576+
EXPECT_DOUBLE_EQ(12000, msgCustom.surface_axis_equatorial());
577+
EXPECT_DOUBLE_EQ(10000, msgCustom.surface_axis_polar());
491578
}
492579

493580
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)