|
| 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 |
0 commit comments