|
25 | 25 | #include "imu_filter_madgwick/imu_filter_ros.h" |
26 | 26 | #include "imu_filter_madgwick/stateless_orientation.h" |
27 | 27 | #include "geometry_msgs/TransformStamped.h" |
| 28 | +#include "geometry_msgs/PoseStamped.h" |
28 | 29 | #include <tf2/LinearMath/Quaternion.h> |
29 | 30 | #include <tf2/LinearMath/Matrix3x3.h> |
30 | 31 |
|
31 | 32 | ImuFilterRos::ImuFilterRos(ros::NodeHandle nh, ros::NodeHandle nh_private) |
32 | | - : nh_(nh), nh_private_(nh_private), initialized_(false) |
| 33 | + : nh_(nh), |
| 34 | + nh_private_(nh_private), |
| 35 | + initialized_(false), |
| 36 | + tf_listener_(tf_buffer_) |
33 | 37 | { |
34 | 38 | ROS_INFO("Starting ImuFilter"); |
35 | 39 |
|
@@ -121,6 +125,10 @@ ImuFilterRos::ImuFilterRos(ros::NodeHandle nh, ros::NodeHandle nh_private) |
121 | 125 |
|
122 | 126 | rpy_raw_debug_publisher_ = nh_.advertise<geometry_msgs::Vector3Stamped>( |
123 | 127 | ros::names::resolve("imu") + "/rpy/raw", 5); |
| 128 | + |
| 129 | + orientation_filtered_publisher_ = |
| 130 | + nh_private.advertise<geometry_msgs::PoseStamped>( |
| 131 | + ros::names::resolve("imu") + "/orientation_filtered", 5); |
124 | 132 | } |
125 | 133 |
|
126 | 134 | // **** register subscribers |
@@ -407,9 +415,37 @@ void ImuFilterRos::publishFilteredMsg(const ImuMsg::ConstPtr& imu_msg_raw) |
407 | 415 |
|
408 | 416 | rpy.header = imu_msg_raw->header; |
409 | 417 | rpy_filtered_debug_publisher_.publish(rpy); |
| 418 | + |
| 419 | + publishOrientationFiltered(imu_msg); |
410 | 420 | } |
411 | 421 | } |
412 | 422 |
|
| 423 | +void ImuFilterRos::publishOrientationFiltered(const ImuMsg::ConstPtr& imu_msg) |
| 424 | +{ |
| 425 | + geometry_msgs::PoseStamped pose_msg; |
| 426 | + pose_msg.header.stamp = imu_msg->header.stamp; |
| 427 | + pose_msg.header.frame_id = fixed_frame_; |
| 428 | + pose_msg.pose.orientation = imu_msg->orientation; |
| 429 | + |
| 430 | + // get the current transform from the fixed frame to the imu frame |
| 431 | + geometry_msgs::TransformStamped transform; |
| 432 | + try |
| 433 | + { |
| 434 | + transform = tf_buffer_.lookupTransform( |
| 435 | + fixed_frame_, imu_msg->header.frame_id, imu_msg->header.stamp); |
| 436 | + } catch (tf2::TransformException& ex) |
| 437 | + { |
| 438 | + ROS_WARN("%s", ex.what()); |
| 439 | + return; |
| 440 | + } |
| 441 | + |
| 442 | + pose_msg.pose.position.x = transform.transform.translation.x; |
| 443 | + pose_msg.pose.position.y = transform.transform.translation.y; |
| 444 | + pose_msg.pose.position.z = transform.transform.translation.z; |
| 445 | + |
| 446 | + orientation_filtered_publisher_.publish(pose_msg); |
| 447 | +} |
| 448 | + |
413 | 449 | void ImuFilterRos::publishRawMsg(const ros::Time& t, float roll, float pitch, |
414 | 450 | float yaw) |
415 | 451 | { |
|
0 commit comments