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
75 GNSSToMapConvertor(PosePubCallback pose_pub, TransformLookupCallback tf_lookup, std::string map_frame_id,
76 std::string base_link_frame_id, std::string heading_frame_id,
77 std::shared_ptr<carma_ros2_utils::CarmaLifecycleNode> nh);
78
85 void gnssFixCb(gps_msgs::msg::GPSFix::UniquePtr fix_msg);
86
96 void geoReferenceCallback(std_msgs::msg::String::UniquePtr geo_ref);
97
101 boost::optional<tf2::Quaternion> getNedInMapRotation();
102
106 std::shared_ptr<lanelet::projection::LocalFrameProjector> getMapProjector();
107
129 geometry_msgs::msg::PoseWithCovarianceStamped poseFromGnss(const tf2::Transform& baselink_in_sensor,
130 const tf2::Quaternion& sensor_in_ned_heading_rotation,
131 const lanelet::projection::LocalFrameProjector& projector,
132 const tf2::Quaternion& ned_in_map_rotation,
133 gps_msgs::msg::GPSFix fix_msg);
134
135private:
136 PosePubCallback pose_pub_; // Function which can forward the output from this component
137 TransformLookupCallback tf_lookup_; // Function which accesses a buffer of transforms for query lookups
138 std::string map_frame_id_; // The frame id of the map which the output pose will be in.
139 std::string base_link_frame_id_; // The frame id of the final reported pose
140 std::string heading_frame_id_; // The frame id of the heading frame
141 std::string georeference_{""};
142
143 // Rotation describing the orientation of an NED frame relative to the map frame located at the map origin.
144 // This is derived from the received georeference
145 boost::optional<tf2::Quaternion> ned_in_map_rotation_;
146
147 // Rotation describing orientation of sensor in heading frame
148 boost::optional<tf2::Quaternion> sensor_in_ned_heading_rotation_;
149
150 std::shared_ptr<lanelet::projection::LocalFrameProjector> map_projector_; // Must be shared pointer instead of
151 // optional since for some reason optional
152 // does not work with this class
153
154 boost::optional<tf2::Transform> baselink_in_sensor_; // A transform describing the relation of the baselink frame
155 // with the frame provided by the gnss message
156
157 // Nodehandle
158 std::shared_ptr<carma_ros2_utils::CarmaLifecycleNode> nh_;
159
160
161};
162
163}; // 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.
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...
GNSSToMapConvertor(PosePubCallback pose_pub, TransformLookupCallback tf_lookup, std::string map_frame_id, std::string base_link_frame_id, std::string heading_frame_id, std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh)
Constructor.
boost::optional< tf2::Quaternion > getNedInMapRotation()
Get the rotation computed from the recieved georeference or boost::none if unset.
std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh_