Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
GNSSToMapConvertor.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2018-2021 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <rclcpp/rclcpp.hpp>
20#include <functional>
21
22#include <std_msgs/msg/string.hpp>
23#include <std_srvs/srv/empty.hpp>
24
25#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
26#include <geometry_msgs/msg/pose.hpp>
27#include <geometry_msgs/msg/pose_stamped.hpp>
28#include <geometry_msgs/msg/transform_stamped.hpp>
29#include <sensor_msgs/msg/nav_sat_fix.hpp>
30
31#include <tf2/LinearMath/Transform.h>
32
33#include <carma_ros2_utils/carma_lifecycle_node.hpp>
34
35#include <boost/optional.hpp>
36#include <memory>
37
38#include <gps_msgs/msg/gps_fix.hpp>
39#include <wgs84_utils/wgs84_utils.h>
40
41#include <lanelet2_extension/projection/local_frame_projector.h>
42
49{
51{
52public:
53 using PosePubCallback = std::function<void(geometry_msgs::msg::PoseStamped)>;
54
61 std::function<boost::optional<geometry_msgs::msg::TransformStamped>(const std::string&, const std::string&)>;
62
74 GNSSToMapConvertor(PosePubCallback pose_pub, TransformLookupCallback tf_lookup, std::string map_frame_id,
75 std::string base_link_frame_id, std::string heading_frame_id, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger);
76
83 void gnssFixCb(gps_msgs::msg::GPSFix::UniquePtr fix_msg);
84
94 void geoReferenceCallback(std_msgs::msg::String::UniquePtr geo_ref);
95
99 boost::optional<tf2::Quaternion> getNedInMapRotation();
100
104 std::shared_ptr<lanelet::projection::LocalFrameProjector> getMapProjector();
105
127 geometry_msgs::msg::PoseWithCovarianceStamped poseFromGnss(const tf2::Transform& baselink_in_sensor,
128 const tf2::Quaternion& sensor_in_ned_heading_rotation,
129 const lanelet::projection::LocalFrameProjector& projector,
130 const tf2::Quaternion& ned_in_map_rotation,
131 gps_msgs::msg::GPSFix fix_msg);
132
133private:
134 PosePubCallback pose_pub_; // Function which can forward the output from this component
135 TransformLookupCallback tf_lookup_; // Function which accesses a buffer of transforms for query lookups
136 std::string map_frame_id_; // The frame id of the map which the output pose will be in.
137 std::string base_link_frame_id_; // The frame id of the final reported pose
138 std::string heading_frame_id_; // The frame id of the heading frame
139 std::string georeference_{""};
140
141 // Rotation describing the orientation of an NED frame relative to the map frame located at the map origin.
142 // This is derived from the received georeference
143 boost::optional<tf2::Quaternion> ned_in_map_rotation_;
144
145 // Rotation describing orientation of sensor in heading frame
146 boost::optional<tf2::Quaternion> sensor_in_ned_heading_rotation_;
147
148 std::shared_ptr<lanelet::projection::LocalFrameProjector> map_projector_; // Must be shared pointer instead of
149 // optional since for some reason optional
150 // does not work with this class
151
152 boost::optional<tf2::Transform> baselink_in_sensor_; // A transform describing the relation of the baselink frame
153 // with the frame provided by the gnss message
154
155 // Logger interface
156 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_;
157
158};
159
160}; // namespace gnss_to_map_convertor
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
std::function< void(geometry_msgs::msg::PoseStamped)> PosePubCallback
void geoReferenceCallback(std_msgs::msg::String::UniquePtr geo_ref)
Map georeference callback The geodetic description of the map frame should be provided to this callba...
std::function< boost::optional< geometry_msgs::msg::TransformStamped >(const std::string &, const std::string &)> TransformLookupCallback
boost::optional< tf2::Quaternion > sensor_in_ned_heading_rotation_
void gnssFixCb(gps_msgs::msg::GPSFix::UniquePtr fix_msg)
GNSS Fix callback which will publish a pose representing that fix in the map frame if the required tr...
std::shared_ptr< lanelet::projection::LocalFrameProjector > getMapProjector()
Get the projector built from the provided georeference via the callback.
GNSSToMapConvertor(PosePubCallback pose_pub, TransformLookupCallback tf_lookup, std::string map_frame_id, std::string base_link_frame_id, std::string heading_frame_id, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger)
Constructor.
boost::optional< tf2::Transform > baselink_in_sensor_
boost::optional< tf2::Quaternion > ned_in_map_rotation_
geometry_msgs::msg::PoseWithCovarianceStamped poseFromGnss(const tf2::Transform &baselink_in_sensor, const tf2::Quaternion &sensor_in_ned_heading_rotation, const lanelet::projection::LocalFrameProjector &projector, const tf2::Quaternion &ned_in_map_rotation, gps_msgs::msg::GPSFix fix_msg)
Converts a provided GNSS fix message into a pose message for the map frame describibed by the provide...
boost::optional< tf2::Quaternion > getNedInMapRotation()
Get the rotation computed from the recieved georeference or boost::none if unset.
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_