Skip to content

Commit faf456b

Browse files
committed
debug eskf publishers. Ros node cleanup
1 parent ab1e33a commit faf456b

5 files changed

Lines changed: 64 additions & 19 deletions

File tree

navigation/eskf/config/eskf_params.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
dvl_frame_t: [ 0.4, 0.0, 0.2 ]
1717

1818
depth_frame_t: [ 0.0, 0.0, 0.0 ]
19-
use_tf_transforms: false
19+
use_tf_transforms: true
2020
publish_tf: true
2121
publish_pose: true
2222
publish_twist: true

navigation/eskf/config/eskf_params_real_world.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
dvl_frame_t: [ 0.4, 0.0, 0.2 ]
1717

1818
depth_frame_t: [ 0.0, 0.0, 0.0 ]
19-
use_tf_transforms: false
19+
use_tf_transforms: true
2020
publish_tf: true
2121
publish_pose: true
2222
publish_twist: true

navigation/eskf/include/eskf/eskf_ros.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <tf2_eigen/tf2_eigen.hpp>
2323
#include "eskf/eskf.hpp"
2424
#include "eskf/typedefs.hpp"
25-
#include "spdlog/spdlog.h"
2625

2726
class ESKFNode : public rclcpp::Node {
2827
public:
@@ -32,14 +31,16 @@ class ESKFNode : public rclcpp::Node {
3231
private:
3332
// @brief Callback function for the imu topic
3433
// @param msg: Imu message containing the imu data
35-
void imu_callback(const sensor_msgs::msg::Imu::SharedPtr msg);
34+
void imu_callback(const sensor_msgs::msg::Imu::ConstSharedPtr msg);
3635

3736
// @brief Callback function for the dvl topic
3837
// @param msg: TwistWithCovarianceStamped message containing the dvl data
3938
void dvl_callback(
40-
const geometry_msgs::msg::TwistWithCovarianceStamped::SharedPtr msg);
39+
const geometry_msgs::msg::TwistWithCovarianceStamped::ConstSharedPtr
40+
msg);
4141

42-
void depth_callback(const sensor_msgs::msg::FluidPressure::SharedPtr msg);
42+
void pressure_callback(
43+
const sensor_msgs::msg::FluidPressure::ConstSharedPtr msg);
4344

4445
// @brief Publish the odometry message
4546
void publish_odom();
@@ -121,6 +122,8 @@ class ESKFNode : public rclcpp::Node {
121122
return frame_prefix_.empty() ? name : frame_prefix_ + "/" + name;
122123
}
123124

125+
bool publish_debug_{false};
126+
124127
// Flags and Storage
125128
std::string frame_prefix_{""};
126129
bool use_tf_transforms_ = false;

navigation/eskf/launch/eskf.launch.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
def launch_setup(context, *args, **kwargs):
1616
drone, namespace = resolve_drone_and_namespace(context)
17+
debug_output = (
18+
LaunchConfiguration('debug_output').perform(context).lower() == 'true'
19+
)
1720

1821
drone_params = os.path.join(
1922
get_package_share_directory("auv_setup"),
@@ -42,6 +45,7 @@ def launch_setup(context, *args, **kwargs):
4245
eskf_params,
4346
drone_params,
4447
{"frame_prefix": namespace},
48+
{"publish_debug": debug_output},
4549
],
4650
output="screen",
4751
)
@@ -55,8 +59,13 @@ def generate_launch_description():
5559
default_value='false',
5660
description='Set to "false" to load real-world hardware parameters.',
5761
)
62+
debug_output_arg = DeclareLaunchArgument(
63+
'debug_output',
64+
default_value='true',
65+
description='If true, publish ESKF outputs on debug/private topics and disable TF publishing.',
66+
)
5867
return LaunchDescription(
59-
[sim_arg]
68+
[sim_arg, debug_output_arg]
6069
+ declare_drone_and_namespace_args()
6170
+ [OpaqueFunction(function=launch_setup)]
6271
)

navigation/eskf/src/eskf_ros.cpp

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ ESKFNode::ESKFNode(const rclcpp::NodeOptions& options)
2424
}
2525
spdlog::info("frame_prefix set to '{}'", frame_prefix_);
2626

27-
publish_tf_ = this->declare_parameter<bool>("publish_tf");
27+
publish_debug_ = this->declare_parameter<bool>("publish_debug");
28+
if (publish_debug_) {
29+
spdlog::info(
30+
"Debug output enabled: Publishing ESKF outputs on debug/private "
31+
"topics and disabling TF publishing.");
32+
} else {
33+
spdlog::info(
34+
"Debug output disabled: Publishing ESKF outputs on standard topics "
35+
"and enabling TF publishing.");
36+
}
37+
38+
publish_tf_ =
39+
this->declare_parameter<bool>("publish_tf") && !publish_debug_;
2840
if (publish_tf_) {
2941
tf_broadcaster_ =
3042
std::make_unique<tf2_ros::TransformBroadcaster>(*this);
@@ -35,8 +47,6 @@ ESKFNode::ESKFNode(const rclcpp::NodeOptions& options)
3547

3648
publish_biases_ = this->declare_parameter<bool>("publish_biases");
3749

38-
// Declare these here so they appear in `ros2 param list` from startup,
39-
// even though they are read in complete_initialization().
4050
this->declare_parameter<int>("publish_rate_ms");
4151
this->declare_parameter<std::string>("topics.imu");
4252
this->declare_parameter<std::string>("topics.dvl_twist");
@@ -65,26 +75,46 @@ void ESKFNode::set_subscribers_and_publisher() {
6575
std::string imu_topic = this->get_parameter("topics.imu").as_string();
6676
imu_sub_ = this->create_subscription<sensor_msgs::msg::Imu>(
6777
imu_topic, qos_sensor_data,
68-
std::bind(&ESKFNode::imu_callback, this, std::placeholders::_1));
78+
[this](const sensor_msgs::msg::Imu::ConstSharedPtr msg) {
79+
imu_callback(msg);
80+
});
6981

7082
std::string dvl_topic = this->get_parameter("topics.dvl_twist").as_string();
7183
dvl_sub_ = this->create_subscription<
7284
geometry_msgs::msg::TwistWithCovarianceStamped>(
7385
dvl_topic, qos_sensor_data,
74-
std::bind(&ESKFNode::dvl_callback, this, std::placeholders::_1));
86+
[this](
87+
const geometry_msgs::msg::TwistWithCovarianceStamped::ConstSharedPtr
88+
msg) { dvl_callback(msg); });
7589

7690
std::string pressure_topic =
7791
this->get_parameter("topics.pressure_sensor").as_string();
7892
depth_sub_ = this->create_subscription<sensor_msgs::msg::FluidPressure>(
7993
pressure_topic, qos_sensor_data,
80-
std::bind(&ESKFNode::depth_callback, this, std::placeholders::_1));
94+
[this](const sensor_msgs::msg::FluidPressure::ConstSharedPtr msg) {
95+
pressure_callback(msg);
96+
});
97+
98+
auto eskf_debug_topic = [](std::string& topic_name) {
99+
const std::string prefix = "eskf/";
100+
101+
if (topic_name.rfind(prefix, 0) != 0) {
102+
topic_name = prefix + topic_name;
103+
}
104+
};
81105

82106
std::string odom_topic = this->get_parameter("topics.odom").as_string();
107+
if (publish_debug_) {
108+
eskf_debug_topic(odom_topic);
109+
}
83110
odom_pub_ = this->create_publisher<nav_msgs::msg::Odometry>(
84111
odom_topic, qos_sensor_data);
85112

86113
if (publish_pose_) {
87114
std::string pose_topic = this->get_parameter("topics.pose").as_string();
115+
if (publish_debug_) {
116+
eskf_debug_topic(pose_topic);
117+
}
88118
pose_pub_ = this->create_publisher<
89119
geometry_msgs::msg::PoseWithCovarianceStamped>(pose_topic,
90120
qos_sensor_data);
@@ -93,6 +123,9 @@ void ESKFNode::set_subscribers_and_publisher() {
93123
if (publish_twist_) {
94124
std::string twist_topic =
95125
this->get_parameter("topics.twist").as_string();
126+
if (publish_debug_) {
127+
eskf_debug_topic(twist_topic);
128+
}
96129
twist_pub_ = this->create_publisher<
97130
geometry_msgs::msg::TwistWithCovarianceStamped>(twist_topic,
98131
qos_sensor_data);
@@ -202,7 +235,7 @@ void ESKFNode::set_parameters() {
202235
spdlog::info("add_gravity_to_imu: {}", add_gravity_to_imu_);
203236
}
204237

205-
void ESKFNode::imu_callback(const sensor_msgs::msg::Imu::SharedPtr msg) {
238+
void ESKFNode::imu_callback(const sensor_msgs::msg::Imu::ConstSharedPtr msg) {
206239
rclcpp::Time current_time = msg->header.stamp;
207240

208241
if (!first_imu_msg_received_) {
@@ -253,7 +286,7 @@ void ESKFNode::imu_callback(const sensor_msgs::msg::Imu::SharedPtr msg) {
253286
}
254287

255288
void ESKFNode::dvl_callback(
256-
const geometry_msgs::msg::TwistWithCovarianceStamped::SharedPtr msg) {
289+
const geometry_msgs::msg::TwistWithCovarianceStamped::ConstSharedPtr msg) {
257290
SensorDVL dvl_sensor;
258291

259292
dvl_sensor.measurement << msg->twist.twist.linear.x,
@@ -286,8 +319,8 @@ void ESKFNode::dvl_callback(
286319
#endif
287320
}
288321

289-
void ESKFNode::depth_callback(
290-
const sensor_msgs::msg::FluidPressure::SharedPtr msg) {
322+
void ESKFNode::pressure_callback(
323+
const sensor_msgs::msg::FluidPressure::ConstSharedPtr msg) {
291324
SensorDepth depth_sensor;
292325
// the simulation is a gauge sensor so we don't subtract atmospheric
293326
// pressure.
@@ -448,8 +481,8 @@ void ESKFNode::complete_initialization() {
448481

449482
time_step_ = std::chrono::milliseconds(
450483
this->get_parameter("publish_rate_ms").as_int());
451-
odom_pub_timer_ = this->create_wall_timer(
452-
time_step_, std::bind(&ESKFNode::publish_odom, this));
484+
odom_pub_timer_ =
485+
this->create_wall_timer(time_step_, [this]() { publish_odom(); });
453486

454487
spdlog::info(start_message);
455488

0 commit comments

Comments
 (0)