Skip to content

Commit 6ac3e62

Browse files
committed
changed message publisher to publish entire pose
1 parent d00f3e4 commit 6ac3e62

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

vortex_utility_nodes/src/message_publisher.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
#include <variant>
12
#include <vortex/utils/math.hpp>
23
#include "geometry_msgs/msg/pose_stamped.hpp"
34
#include "geometry_msgs/msg/pose_with_covariance_stamped.hpp"
45
#include "nav_msgs/msg/odometry.hpp"
56
#include "rclcpp/rclcpp.hpp"
7+
#include "vortex_msgs/msg/pose_euler_stamped.hpp"
68
#include "vortex_msgs/msg/reference_filter_quat.hpp"
7-
#include "vortex_msgs/msg/rpy.hpp"
89
#include "vortex_msgs/msg/waypoint.hpp"
910

10-
#include <variant>
11-
1211
class MessagePublisherNode : public rclcpp::Node {
1312
public:
1413
MessagePublisherNode() : Node("message_publisher_node") {
@@ -27,8 +26,8 @@ class MessagePublisherNode : public rclcpp::Node {
2726
rclcpp::QoS qos_profile(2);
2827
qos_profile.best_effort();
2928

30-
rpy_pub_ = this->create_publisher<vortex_msgs::msg::RPY>(output_topic,
31-
qos_profile);
29+
pose_pub_ = this->create_publisher<vortex_msgs::msg::PoseEulerStamped>(
30+
output_topic, qos_profile);
3231

3332
if (input_type == "odometry") {
3433
auto topic = this->get_parameter("topics.odometry").as_string();
@@ -37,19 +36,17 @@ class MessagePublisherNode : public rclcpp::Node {
3736
std::bind(&MessagePublisherNode::odom_callback, this,
3837
std::placeholders::_1));
3938
RCLCPP_INFO(this->get_logger(),
40-
"Euler publisher [odometry]: %s -> %s", topic.c_str(),
39+
"Pose publisher [odometry]: %s -> %s", topic.c_str(),
4140
output_topic.c_str());
42-
4341
} else if (input_type == "waypoint") {
4442
auto topic = this->get_parameter("topics.waypoint").as_string();
4543
sub_ = this->create_subscription<vortex_msgs::msg::Waypoint>(
4644
topic, qos_profile,
4745
std::bind(&MessagePublisherNode::waypoint_callback, this,
4846
std::placeholders::_1));
4947
RCLCPP_INFO(this->get_logger(),
50-
"Euler publisher [waypoint]: %s -> %s", topic.c_str(),
48+
"Pose publisher [waypoint]: %s -> %s", topic.c_str(),
5149
output_topic.c_str());
52-
5350
} else if (input_type == "reference_filter") {
5451
auto topic =
5552
this->get_parameter("topics.reference_filter").as_string();
@@ -59,19 +56,17 @@ class MessagePublisherNode : public rclcpp::Node {
5956
std::bind(&MessagePublisherNode::ref_filter_callback, this,
6057
std::placeholders::_1));
6158
RCLCPP_INFO(this->get_logger(),
62-
"Euler publisher [reference_filter]: %s -> %s",
59+
"Pose publisher [reference_filter]: %s -> %s",
6360
topic.c_str(), output_topic.c_str());
64-
6561
} else if (input_type == "pose_stamped") {
6662
auto topic = this->get_parameter("topics.pose_stamped").as_string();
6763
sub_ = this->create_subscription<geometry_msgs::msg::PoseStamped>(
6864
topic, qos_profile,
6965
std::bind(&MessagePublisherNode::pose_stamped_callback, this,
7066
std::placeholders::_1));
7167
RCLCPP_INFO(this->get_logger(),
72-
"Euler publisher [pose_stamped]: %s -> %s",
68+
"Pose publisher [pose_stamped]: %s -> %s",
7369
topic.c_str(), output_topic.c_str());
74-
7570
} else if (input_type == "pose_with_covariance_stamped") {
7671
auto topic =
7772
this->get_parameter("topics.pose_with_covariance_stamped")
@@ -84,9 +79,8 @@ class MessagePublisherNode : public rclcpp::Node {
8479
this, std::placeholders::_1));
8580
RCLCPP_INFO(
8681
this->get_logger(),
87-
"Euler publisher [pose_with_covariance_stamped]: %s -> %s",
82+
"Pose publisher [pose_with_covariance_stamped]: %s -> %s",
8883
topic.c_str(), output_topic.c_str());
89-
9084
} else {
9185
RCLCPP_FATAL(
9286
this->get_logger(),
@@ -105,48 +99,59 @@ class MessagePublisherNode : public rclcpp::Node {
10599
return vortex::utils::math::quat_to_euler(eigen_q);
106100
}
107101

108-
void publish_rpy(const std_msgs::msg::Header& header,
109-
const Eigen::Vector3d& euler) {
110-
vortex_msgs::msg::RPY msg;
102+
void publish_pose(const std_msgs::msg::Header& header,
103+
double x,
104+
double y,
105+
double z,
106+
const Eigen::Vector3d& euler) {
107+
vortex_msgs::msg::PoseEulerStamped msg;
108+
111109
msg.header = header;
110+
msg.x = x;
111+
msg.y = y;
112+
msg.z = z;
112113
msg.roll = euler.x();
113114
msg.pitch = euler.y();
114115
msg.yaw = euler.z();
115-
rpy_pub_->publish(msg);
116+
pose_pub_->publish(msg);
116117
}
117118

118119
void odom_callback(const nav_msgs::msg::Odometry::SharedPtr msg) {
120+
const auto& pos = msg->pose.pose.position;
119121
const auto& q = msg->pose.pose.orientation;
120122
auto euler = convert_quat(q.w, q.x, q.y, q.z);
121-
publish_rpy(msg->header, euler);
123+
publish_pose(msg->header, pos.x, pos.y, pos.z, euler);
122124
}
123125

124126
void waypoint_callback(const vortex_msgs::msg::Waypoint::SharedPtr msg) {
127+
const auto& pos = msg->pose.position;
125128
const auto& q = msg->pose.orientation;
126129
auto euler = convert_quat(q.w, q.x, q.y, q.z);
127130
std_msgs::msg::Header header;
128131
header.stamp = this->now();
129-
publish_rpy(header, euler);
132+
publish_pose(header, pos.x, pos.y, pos.z, euler);
130133
}
131134

132135
void ref_filter_callback(
133136
const vortex_msgs::msg::ReferenceFilterQuat::SharedPtr msg) {
134137
auto euler = convert_quat(msg->qw, msg->qx, msg->qy, msg->qz);
135-
publish_rpy(msg->header, euler);
138+
publish_pose(msg->header, msg->x, msg->y, msg->z, euler);
136139
}
137140

138141
void pose_stamped_callback(
139142
const geometry_msgs::msg::PoseStamped::SharedPtr msg) {
143+
const auto& pos = msg->pose.position;
140144
const auto& q = msg->pose.orientation;
141145
auto euler = convert_quat(q.w, q.x, q.y, q.z);
142-
publish_rpy(msg->header, euler);
146+
publish_pose(msg->header, pos.x, pos.y, pos.z, euler);
143147
}
144148

145149
void pose_with_covariance_stamped_callback(
146150
const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg) {
151+
const auto& pos = msg->pose.pose.position;
147152
const auto& q = msg->pose.pose.orientation;
148153
auto euler = convert_quat(q.w, q.x, q.y, q.z);
149-
publish_rpy(msg->header, euler);
154+
publish_pose(msg->header, pos.x, pos.y, pos.z, euler);
150155
}
151156

152157
using SubVariant = std::variant<
@@ -158,7 +163,7 @@ class MessagePublisherNode : public rclcpp::Node {
158163
geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr>;
159164

160165
SubVariant sub_;
161-
rclcpp::Publisher<vortex_msgs::msg::RPY>::SharedPtr rpy_pub_;
166+
rclcpp::Publisher<vortex_msgs::msg::PoseEulerStamped>::SharedPtr pose_pub_;
162167
};
163168

164169
int main(int argc, char** argv) {

0 commit comments

Comments
 (0)