Skip to content

Commit a348c07

Browse files
ahcordevincentrou
andauthored
[backport Humble] Create bridge for GPSFix msg (gazebosim#316) (gazebosim#538)
Signed-off-by: Vincent Rousseau <[email protected]> Signed-off-by: Alejandro Hernández Cordero <[email protected]> Co-authored-by: Rousseau Vincent <[email protected]>
1 parent 2699e3f commit a348c07

File tree

10 files changed

+217
-0
lines changed

10 files changed

+217
-0
lines changed

ros_gz_bridge/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ set(BRIDGE_MESSAGE_TYPES
7171
builtin_interfaces
7272
actuator_msgs
7373
geometry_msgs
74+
gps_msgs
7475
nav_msgs
7576
rcl_interfaces
7677
ros_gz_interfaces

ros_gz_bridge/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The following message types can be bridged for topics:
3232
| geometry_msgs/msg/TwistStamped | ignition::msgs::Twist |
3333
| geometry_msgs/msg/TwistWithCovariance | ignition::msgs::TwistWithCovariance |
3434
| geometry_msgs/msg/TwistWithCovarianceStamped| ignition::msgs::TwistWithCovariance |
35+
| gps_msgs/GPSFix | ignition::msgs::NavSat |
3536
| nav_msgs/msg/Odometry | ignition::msgs::Odometry |
3637
| nav_msgs/msg/Odometry | ignition::msgs::OdometryWithCovariance |
3738
| rcl_interfaces/msg/ParameterValue | ignition::msgs::Any |

ros_gz_bridge/include/ros_gz_bridge/convert.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <ros_gz_bridge/convert/actuator_msgs.hpp>
1919
#include <ros_gz_bridge/convert/geometry_msgs.hpp>
20+
#include <ros_gz_bridge/convert/gps_msgs.hpp>
2021
#include <ros_gz_bridge/convert/nav_msgs.hpp>
2122
#include <ros_gz_bridge/convert/ros_gz_interfaces.hpp>
2223
#include <ros_gz_bridge/convert/rosgraph_msgs.hpp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2022 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef ROS_GZ_BRIDGE__CONVERT__GPS_MSGS_HPP_
16+
#define ROS_GZ_BRIDGE__CONVERT__GPS_MSGS_HPP_
17+
18+
// Gazebo Msgs
19+
#include <gz/msgs/navsat.pb.h>
20+
21+
// ROS 2 messages
22+
#include <gps_msgs/msg/gps_fix.hpp>
23+
24+
#include <ros_gz_bridge/convert_decl.hpp>
25+
26+
namespace ros_gz_bridge
27+
{
28+
template<>
29+
void
30+
convert_ros_to_gz(
31+
const gps_msgs::msg::GPSFix & ros_msg,
32+
gz::msgs::NavSat & gz_msg);
33+
34+
template<>
35+
void
36+
convert_gz_to_ros(
37+
const gz::msgs::NavSat & gz_msg,
38+
gps_msgs::msg::GPSFix & ros_msg);
39+
} // namespace ros_gz_bridge
40+
41+
#endif // ROS_GZ_BRIDGE__CONVERT__GPS_MSGS_HPP_

ros_gz_bridge/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<depend>actuator_msgs</depend>
1717
<depend>geometry_msgs</depend>
18+
<depend>gps_msgs</depend>
1819
<depend>nav_msgs</depend>
1920
<depend>rclcpp</depend>
2021
<depend>rclcpp_components</depend>

ros_gz_bridge/ros_gz_bridge/mappings.py

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
Mapping('WrenchStamped', 'Wrench'),
4848
Mapping('Vector3', 'Vector3d'),
4949
],
50+
'gps_msgs': [
51+
Mapping('GPSFix', 'NavSat'),
52+
],
5053
'nav_msgs': [
5154
Mapping('Odometry', 'Odometry'),
5255
Mapping('Odometry', 'OdometryWithCovariance'),
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2022 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <cmath>
16+
17+
#include "convert/utils.hpp"
18+
#include "ros_gz_bridge/convert/gps_msgs.hpp"
19+
20+
namespace ros_gz_bridge
21+
{
22+
23+
template<>
24+
void
25+
convert_ros_to_gz(
26+
const gps_msgs::msg::GPSFix & ros_msg,
27+
gz::msgs::NavSat & gz_msg)
28+
{
29+
convert_ros_to_gz(ros_msg.header, (*gz_msg.mutable_header()));
30+
gz_msg.set_latitude_deg(ros_msg.latitude);
31+
gz_msg.set_longitude_deg(ros_msg.longitude);
32+
gz_msg.set_altitude(ros_msg.altitude);
33+
gz_msg.set_frame_id(ros_msg.header.frame_id);
34+
35+
gz_msg.set_velocity_east(cos(ros_msg.track) * ros_msg.speed);
36+
gz_msg.set_velocity_north(sin(ros_msg.track) * ros_msg.speed);
37+
gz_msg.set_velocity_up(ros_msg.climb);
38+
}
39+
40+
template<>
41+
void
42+
convert_gz_to_ros(
43+
const gz::msgs::NavSat & gz_msg,
44+
gps_msgs::msg::GPSFix & ros_msg)
45+
{
46+
convert_gz_to_ros(gz_msg.header(), ros_msg.header);
47+
ros_msg.header.frame_id = frame_id_gz_to_ros(gz_msg.frame_id());
48+
ros_msg.latitude = gz_msg.latitude_deg();
49+
ros_msg.longitude = gz_msg.longitude_deg();
50+
ros_msg.altitude = gz_msg.altitude();
51+
52+
ros_msg.speed = sqrt(
53+
gz_msg.velocity_east() * gz_msg.velocity_east() +
54+
gz_msg.velocity_north() * gz_msg.velocity_north());
55+
ros_msg.track = atan2(gz_msg.velocity_north(), gz_msg.velocity_east());
56+
ros_msg.climb = gz_msg.velocity_up();
57+
58+
// position_covariance is not supported in Ignition::Msgs::NavSat.
59+
ros_msg.position_covariance_type = gps_msgs::msg::GPSFix::COVARIANCE_TYPE_UNKNOWN;
60+
ros_msg.status.status = gps_msgs::msg::GPSStatus::STATUS_GBAS_FIX;
61+
}
62+
63+
} // namespace ros_gz_bridge

ros_gz_bridge/test/utils/ros_test_msg.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,38 @@ void compareTestMsg(const std::shared_ptr<geometry_msgs::msg::WrenchStamped> & _
521521
compareTestMsg(std::make_shared<geometry_msgs::msg::Vector3>(_msg->wrench.force));
522522
compareTestMsg(std::make_shared<geometry_msgs::msg::Vector3>(_msg->wrench.torque));
523523
}
524+
525+
void createTestMsg(gps_msgs::msg::GPSFix & _msg)
526+
{
527+
std_msgs::msg::Header header_msg;
528+
createTestMsg(header_msg);
529+
530+
_msg.header = header_msg;
531+
_msg.status.status = gps_msgs::msg::GPSStatus::STATUS_GBAS_FIX;
532+
_msg.latitude = 0.00;
533+
_msg.longitude = 0.00;
534+
_msg.altitude = 0.00;
535+
_msg.position_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
536+
_msg.position_covariance_type = gps_msgs::msg::GPSFix::COVARIANCE_TYPE_UNKNOWN;
537+
}
538+
539+
void compareTestMsg(const std::shared_ptr<gps_msgs::msg::GPSFix> & _msg)
540+
{
541+
gps_msgs::msg::GPSFix expected_msg;
542+
createTestMsg(expected_msg);
543+
544+
compareTestMsg(_msg->header);
545+
EXPECT_EQ(expected_msg.status, _msg->status);
546+
EXPECT_FLOAT_EQ(expected_msg.latitude, _msg->latitude);
547+
EXPECT_FLOAT_EQ(expected_msg.longitude, _msg->longitude);
548+
EXPECT_FLOAT_EQ(expected_msg.altitude, _msg->altitude);
549+
EXPECT_EQ(expected_msg.position_covariance_type, _msg->position_covariance_type);
550+
551+
for (auto i = 0u; i < 9; ++i) {
552+
EXPECT_FLOAT_EQ(0, _msg->position_covariance[i]);
553+
}
554+
}
555+
524556
void createTestMsg(ros_gz_interfaces::msg::Light & _msg)
525557
{
526558
createTestMsg(_msg.header);

ros_gz_bridge/test/utils/ros_test_msg.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <geometry_msgs/msg/vector3.hpp>
4646
#include <geometry_msgs/msg/wrench.hpp>
4747
#include <geometry_msgs/msg/wrench_stamped.hpp>
48+
#include <gps_msgs/msg/gps_fix.hpp>
4849
#include <nav_msgs/msg/odometry.hpp>
4950
#include <ros_gz_interfaces/msg/altimeter.hpp>
5051
#include <ros_gz_interfaces/msg/entity.hpp>
@@ -343,6 +344,16 @@ void createTestMsg(geometry_msgs::msg::WrenchStamped & _msg);
343344
/// \param[in] _msg The message to compare.
344345
void compareTestMsg(const std::shared_ptr<geometry_msgs::msg::WrenchStamped> & _msg);
345346

347+
/// gps_msgs
348+
349+
/// \brief Create a message used for testing.
350+
/// \param[out] _msg The message populated.
351+
void createTestMsg(gps_msgs::msg::GPSFix & _msg);
352+
353+
/// \brief Compare a message with the populated for testing.
354+
/// \param[in] _msg The message to compare.
355+
void compareTestMsg(const std::shared_ptr<gps_msgs::msg::GPSFix> & _msg);
356+
346357
/// tf2_msgs
347358

348359
/// \brief Create a message used for testing.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2022 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
from ament_index_python.packages import get_package_share_directory
18+
19+
from launch import LaunchDescription
20+
from launch.actions import DeclareLaunchArgument
21+
from launch.actions import IncludeLaunchDescription
22+
from launch.conditions import IfCondition
23+
from launch.launch_description_sources import PythonLaunchDescriptionSource
24+
from launch.substitutions import LaunchConfiguration
25+
26+
from launch_ros.actions import Node
27+
28+
29+
def generate_launch_description():
30+
31+
pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim')
32+
33+
gz_sim = IncludeLaunchDescription(
34+
PythonLaunchDescriptionSource(
35+
os.path.join(pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py')),
36+
launch_arguments={
37+
'gz_args': '-v 4 -r spherical_coordinates.sdf'
38+
}.items(),
39+
)
40+
41+
# RQt
42+
rqt = Node(
43+
package='rqt_topic',
44+
executable='rqt_topic',
45+
arguments=['-t'],
46+
condition=IfCondition(LaunchConfiguration('rqt'))
47+
)
48+
49+
# Bridge
50+
bridge = Node(
51+
package='ros_gz_bridge',
52+
executable='parameter_bridge',
53+
arguments=['/navsat@gps_msgs/msg/[email protected]'],
54+
output='screen'
55+
)
56+
57+
return LaunchDescription([
58+
gz_sim,
59+
DeclareLaunchArgument('rqt', default_value='true',
60+
description='Open RQt.'),
61+
bridge,
62+
rqt
63+
])

0 commit comments

Comments
 (0)