Skip to content

Commit 61f99da

Browse files
add_aw_pose_covariance_modifier_node
Signed-off-by: melike <melike@leodrive.ai>
1 parent 871f8f2 commit 61f99da

File tree

10 files changed

+316
-8
lines changed

10 files changed

+316
-8
lines changed

launch/tier4_localization_launch/launch/pose_twist_estimator/pose_twist_estimator.launch.xml

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<!-- When gnss_enabled is false, automatic_pose_initializer will not run, only manual initial position estimation is available. -->
88
<arg name="gnss_enabled" default="true" description="gnss availability for initial position estimation"/>
99

10+
<!-- When use_pose_covariance_modifier is true, gnss and NDT poses will be used together in localization-->
11+
<arg name="use_pose_covariance_modifier" default="true" description="parameter for using gnss and NDT together with covariance modifier"/>
12+
1013
<!-- split string with underscores -->
1114
<let name="available_args" value="[\'ndt\',\'yabloc\',\'eagleye\',\'artag\']"/>
1215
<let name="split_function" value="list(set('$(var pose_source)'.split('_')).intersection($(var available_args)))"/>
@@ -80,6 +83,11 @@
8083
</include>
8184
</group>
8285

86+
<!-- AW Pose Covariance Modifier Node -->
87+
<group if="$(var use_pose_covariance_modifier)">
88+
<include file="$(find-pkg-share aw_pose_covariance_modifier_node)/launch/aw_pose_covariance_modifier_node.launch.xml"/>
89+
</group>
90+
8391
<!-- Util Launch -->
8492
<group>
8593
<push-ros-namespace namespace="util"/>
@@ -113,4 +121,5 @@
113121
<arg name="input_pointcloud" value="$(var override_input_pointcloud)"/>
114122
</include>
115123
</group>
124+
116125
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(aw_pose_covariance_modifier_node)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
find_package(rclcpp REQUIRED)
7+
find_package(geometry_msgs REQUIRED)
8+
find_package(std_srvs REQUIRED)
9+
10+
set(NODE_NAME ${PROJECT_NAME})
11+
set(EXEC_NAME ${PROJECT_NAME}_exe)
12+
13+
add_executable(${PROJECT_NAME} src/aw_pose_covariance_modifier_node.cpp)
14+
15+
ament_target_dependencies(${PROJECT_NAME} rclcpp geometry_msgs std_srvs)
16+
17+
install(TARGETS
18+
${PROJECT_NAME}
19+
DESTINATION lib/${PROJECT_NAME}
20+
)
21+
include_directories(src/include/)
22+
23+
#ament_auto_add_library(${NODE_NAME}
24+
# src/include/aw_pose_covariance_modifier_node.hpp
25+
# src/aw_pose_covariance_modifier_node.cpp)
26+
27+
#rclcpp_components_register_node(${NODE_NAME}
28+
# PLUGIN "aw_pose_covariance_modifier_node::AWPoseCovarianceModifierNode"
29+
# EXECUTABLE ${EXEC_NAME})
30+
31+
32+
ament_auto_package(INSTALL_TO_SHARE
33+
launch)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# aw_pose_covariance_modifier
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<launch>
3+
<arg name="input_trusted_pose_with_cov_topic" default="/sensing/gnss/pose_with_covariance" description="Trusted pose input .. "/>
4+
<arg name="output_pose_with_covariance_topic" default="/localization/pose_estimator/pose_with_covariance" description="Estimated self position with covariance"/>
5+
6+
7+
<node pkg="aw_pose_covariance_modifier_node" exec="aw_pose_covariance_modifier_node" name="aw_pose_covariance_modifier_node" output="screen" >
8+
<remap from="input_trusted_pose_with_cov_topic" to="$(var input_trusted_pose_with_cov_topic)"/>
9+
<remap from="output_pose_with_covariance_topic" to="$(var output_pose_with_covariance_topic)"/>
10+
11+
</node>
12+
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>aw_pose_covariance_modifier_node</name>
5+
<version>1.0.0</version>
6+
<description>Converts an autoware_msgs message to autoware_auto_msgs version and publishes it.</description>
7+
8+
<maintainer email="melike@leodrive.ai">Melike Tanrikulu</maintainer>
9+
10+
<license>Apache License 2.0</license>
11+
12+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
13+
<buildtool_depend>autoware_cmake</buildtool_depend>
14+
15+
<build_depend>rosidl_default_generators</build_depend>
16+
17+
<depend>rclcpp</depend>
18+
<depend>rclcpp_components</depend>
19+
20+
<depend>geometry_msgs</depend>
21+
<depend>std_srvs</depend>
22+
23+
<export>
24+
<build_type>ament_cmake</build_type>
25+
</export>
26+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2024 The Autoware Foundation
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 "include/aw_pose_covariance_modifier_node.hpp"
16+
#include <rclcpp/rclcpp.hpp>
17+
18+
19+
AWPoseCovarianceModifierNode::AWPoseCovarianceModifierNode()
20+
: Node("AWPoseCovarianceModifierNode")
21+
{
22+
trusted_pose_with_cov_sub_ = this->create_subscription<geometry_msgs::msg::PoseWithCovarianceStamped>(
23+
"input_trusted_pose_with_cov_topic",10000,std::bind(&AWPoseCovarianceModifierNode::trusted_pose_with_cov_callback,this,std::placeholders::_1));
24+
25+
26+
new_pose_estimator_pub_ = this->create_publisher<geometry_msgs::msg::PoseWithCovarianceStamped>("output_pose_with_covariance_topic",10);
27+
28+
client_ = this->create_client<std_srvs::srv::SetBool>("/localization/pose_estimator/covariance_modifier");
29+
30+
startNDTCovModifier = AWPoseCovarianceModifierNode::callNDTCovarianceModifier();
31+
if(startNDTCovModifier == 1){
32+
RCLCPP_INFO(get_logger(), "NDT pose covariance modifier activated ...");
33+
34+
}
35+
36+
}
37+
38+
bool AWPoseCovarianceModifierNode::callNDTCovarianceModifier(){
39+
40+
while (!client_->wait_for_service(std::chrono::seconds(1))) {
41+
if (!rclcpp::ok()) {
42+
RCLCPP_ERROR(get_logger(), "Interrupted while waiting for the service. Exiting.");
43+
return false;
44+
}
45+
RCLCPP_INFO(get_logger(), "Service not available, waiting again...");
46+
}
47+
48+
auto request = std::make_shared<std_srvs::srv::SetBool::Request>();
49+
request->data = true;
50+
51+
auto future_result = client_->async_send_request(request);
52+
if (rclcpp::spin_until_future_complete(get_node_base_interface(), future_result) ==
53+
rclcpp::FutureReturnCode::SUCCESS)
54+
{
55+
auto response = future_result.get();
56+
RCLCPP_INFO(get_logger(), "Response: %d", response->success);
57+
return true;
58+
}
59+
else {
60+
RCLCPP_ERROR(get_logger(), "Failed to receive response.");
61+
return false;
62+
}
63+
}
64+
void AWPoseCovarianceModifierNode::trusted_pose_with_cov_callback(const geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr &msg) {
65+
66+
geometry_msgs::msg::PoseWithCovarianceStamped pose_estimator_pose = *msg;
67+
68+
trusted_pose_rmse_ = (std::sqrt(pose_estimator_pose.pose.covariance[0]) + std::sqrt(pose_estimator_pose.pose.covariance[7]) ) / 2;
69+
trusted_pose_yaw_rmse_in_degrees_ = std::sqrt(pose_estimator_pose.pose.covariance[35]) * 180 / M_PI;
70+
71+
if (trusted_pose_rmse_ > 0.25){
72+
RCLCPP_INFO(this->get_logger(),"Trusted Pose RMSE is under the threshold. It will not be used as a pose source.");
73+
}
74+
else{
75+
76+
if (trusted_pose_yaw_rmse_in_degrees_ >= 0.3){
77+
pose_estimator_pose.pose.covariance[35] = 1000000;
78+
}
79+
80+
new_pose_estimator_pub_->publish(pose_estimator_pose);
81+
82+
}
83+
84+
}
85+
int main(int argc, char *argv[]) {
86+
rclcpp::init(argc, argv);
87+
rclcpp::spin(std::make_shared<AWPoseCovarianceModifierNode>());
88+
rclcpp::shutdown();
89+
return 0;
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2024 The Autoware Foundation
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+
#ifndef AW_POSE_COVARIANCE_MODIFIER_NODE_HPP_
15+
#define AW_POSE_COVARIANCE_MODIFIER_NODE_HPP_
16+
17+
#include <rclcpp/rclcpp.hpp>
18+
#include <std_srvs/srv/set_bool.hpp>
19+
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
20+
#include <string>
21+
22+
using namespace std::chrono_literals;
23+
24+
class AWPoseCovarianceModifierNode : public rclcpp::Node
25+
{
26+
public:
27+
AWPoseCovarianceModifierNode();
28+
29+
rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr trusted_pose_with_cov_sub_;
30+
rclcpp::Publisher<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr new_pose_estimator_pub_;
31+
rclcpp::Client<std_srvs::srv::SetBool>::SharedPtr client_;
32+
33+
void trusted_pose_with_cov_callback(const geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr &msg);
34+
bool callNDTCovarianceModifier();
35+
private:
36+
double trusted_pose_rmse_;
37+
double trusted_pose_yaw_rmse_in_degrees_;
38+
bool startNDTCovModifier = 0;
39+
};
40+
41+
42+
#endif // AW_POSE_COVARIANCE_MODIFIER_NODE_HPP_

localization/ndt_scan_matcher/include/ndt_scan_matcher/ndt_scan_matcher_core.hpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,18 @@ class NDTScanMatcher : public rclcpp::Node
8383
void service_trigger_node(
8484
const std_srvs::srv::SetBool::Request::SharedPtr req,
8585
std_srvs::srv::SetBool::Response::SharedPtr res);
86-
86+
void activate_pose_covariance_modifier(
87+
const std_srvs::srv::SetBool::Request::SharedPtr req,
88+
std_srvs::srv::SetBool::Response::SharedPtr res);
8789
void callback_timer();
8890
void callback_sensor_points(
8991
sensor_msgs::msg::PointCloud2::ConstSharedPtr sensor_points_msg_in_sensor_frame);
9092
void callback_initial_pose(
9193
geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr initial_pose_msg_ptr);
9294
void callback_regularization_pose(
9395
geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr pose_conv_msg_ptr);
96+
void callback_trusted_source_pose(
97+
geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr pose_conv_msg_ptr);
9498

9599
geometry_msgs::msg::PoseWithCovarianceStamped align_pose(
96100
const geometry_msgs::msg::PoseWithCovarianceStamped & initial_pose_with_cov);
@@ -136,8 +140,9 @@ class NDTScanMatcher : public rclcpp::Node
136140
rclcpp::TimerBase::SharedPtr map_update_timer_;
137141
rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr initial_pose_sub_;
138142
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr sensor_points_sub_;
143+
rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr regularization_pose_sub_;
139144
rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr
140-
regularization_pose_sub_;
145+
trusted_source_pose_sub_;
141146

142147
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr sensor_aligned_pose_pub_;
143148
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr no_ground_points_aligned_pose_pub_;
@@ -172,6 +177,7 @@ class NDTScanMatcher : public rclcpp::Node
172177

173178
rclcpp::Service<tier4_localization_msgs::srv::PoseWithCovarianceStamped>::SharedPtr service_;
174179
rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr service_trigger_node_;
180+
rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr server_covariance_modifier_;
175181

176182
tf2_ros::TransformBroadcaster tf2_broadcaster_;
177183
tf2_ros::Buffer tf2_buffer_;
@@ -193,10 +199,20 @@ class NDTScanMatcher : public rclcpp::Node
193199

194200
std::unique_ptr<SmartPoseBuffer> regularization_pose_buffer_;
195201

202+
geometry_msgs::msg::PoseWithCovarianceStamped trusted_source_pose_;
203+
bool activate_pose_covariance_modifier_;
204+
bool close_ndt_pose_source_ = false;
205+
struct trusted_pose_{
206+
double pose_avarage_rmse_xy = 0.0;
207+
double yaw_rmse = 0.0;
208+
}trustedPose;
209+
196210
std::atomic<bool> is_activated_;
197211
std::unique_ptr<MapUpdateModule> map_update_module_;
198212
std::unique_ptr<tier4_autoware_utils::LoggerLevelConfigure> logger_configure_;
199213

214+
std::array<double, 36> covariance_modifier(std::array<double, 36> & in_ndt_covariance);
215+
200216
HyperParameters param_;
201217
};
202218

localization/ndt_scan_matcher/launch/ndt_scan_matcher.launch.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<arg name="input_initial_pose_topic" default="ekf_pose_with_covariance" description="Initial position topic to align"/>
77
<arg name="input_regularization_pose_topic" default="regularization_pose_with_covariance" description="Regularization pose topic"/>
88
<arg name="input_service_trigger_node" default="trigger_node" description="Trigger node service name"/>
9+
<arg name="input_covariance_modifier_trusted_pose_topic" default="/sensing/gnss/pose_with_covariance" description="AW Pose cov modifier trusted PoseWithCov topic"/>
910

1011
<arg name="output_pose_topic" default="ndt_pose" description="Estimated self position"/>
1112
<arg name="output_pose_with_covariance_topic" default="ndt_pose_with_covariance" description="Estimated self position with covariance"/>
@@ -14,11 +15,12 @@
1415

1516
<arg name="node_name" default="ndt_scan_matcher" description="Use a different name for this node"/>
1617

17-
<node pkg="ndt_scan_matcher" exec="ndt_scan_matcher" name="$(var node_name)" output="log">
18+
<node pkg="ndt_scan_matcher" exec="ndt_scan_matcher" name="$(var node_name)" output="screen">
1819
<remap from="points_raw" to="$(var input_pointcloud)"/>
1920
<remap from="ekf_pose_with_covariance" to="$(var input_initial_pose_topic)"/>
2021
<remap from="regularization_pose_with_covariance" to="$(var input_regularization_pose_topic)"/>
2122
<remap from="trigger_node_srv" to="$(var input_service_trigger_node)"/>
23+
<remap from="input_trusted_pose_topic" to="$(var input_covariance_modifier_trusted_pose_topic)"/>
2224

2325
<remap from="ndt_pose" to="$(var output_pose_topic)"/>
2426
<remap from="ndt_pose_with_covariance" to="$(var output_pose_with_covariance_topic)"/>

0 commit comments

Comments
 (0)