Skip to content

Commit 39bfa78

Browse files
authored
Merge pull request #62 from pascalau/feature/tf2
Migration to tf2
2 parents f608216 + 450e17f commit 39bfa78

File tree

4 files changed

+36
-44
lines changed

4 files changed

+36
-44
lines changed

package.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
<!-- Dependencies needed after this package is compiled. -->
2323
<depend>roscpp</depend>
24-
<depend>tf</depend>
24+
<depend>tf2_ros</depend>
25+
<depend>tf2_geometry_msgs</depend>
26+
<depend>tf2_eigen</depend>
2527
<depend>geometry_msgs</depend>
2628
<depend>nav_msgs</depend>
2729
<depend>vrpn_catkin</depend>

src/ros_vrpn_client.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
#include <vrpn_Connection.h>
4949
#include <vrpn_Tracker.h>
5050
#include <Eigen/Geometry>
51-
#include <eigen_conversions/eigen_msg.h>
5251
#include <nav_msgs/Odometry.h>
5352
#include <geometry_msgs/TransformStamped.h>
54-
#include <tf/transform_broadcaster.h>
53+
#include <tf2_ros/transform_broadcaster.h>
54+
#include <tf2_eigen/tf2_eigen.h>
5555
#include <glog/logging.h>
5656

5757
#include "vicon_odometry_estimator.h"
@@ -155,7 +155,7 @@ class Rigid_Body {
155155
ros::Publisher measured_target_transform_pub_;
156156
ros::Publisher estimated_target_transform_pub_;
157157
ros::Publisher estimated_target_odometry_pub_;
158-
tf::TransformBroadcaster br;
158+
tf2_ros::TransformBroadcaster br;
159159
// Vprn object pointers
160160
vrpn_Connection* connection;
161161
vrpn_Tracker_Remote* tracker;
@@ -319,33 +319,29 @@ void VRPN_CALLBACK track_target(void*, const vrpn_TRACKERCB tracker) {
319319
target_state->measured_transform.header.stamp = timestamp;
320320
target_state->measured_transform.header.frame_id = coordinate_system_string;
321321
target_state->measured_transform.child_frame_id = object_name;
322-
tf::vectorEigenToMsg(position_measured_W,
322+
tf2::toMsg(position_measured_W,
323323
target_state->measured_transform.transform.translation);
324-
tf::quaternionEigenToMsg(orientation_measured_B_W,
325-
target_state->measured_transform.transform.rotation);
324+
target_state->measured_transform.transform.rotation = tf2::toMsg(orientation_measured_B_W);
326325

327326
// Populate the estimated transform message. Published in main loop.
328327
target_state->estimated_transform.header.stamp = timestamp;
329328
target_state->estimated_transform.header.frame_id = coordinate_system_string;
330329
target_state->estimated_transform.child_frame_id = object_name;
331-
tf::vectorEigenToMsg(position_estimate_W,
330+
tf2::toMsg(position_estimate_W,
332331
target_state->estimated_transform.transform.translation);
333-
tf::quaternionEigenToMsg(
334-
orientation_estimate_B_W,
335-
target_state->estimated_transform.transform.rotation);
332+
target_state->estimated_transform.transform.rotation = tf2::toMsg(
333+
orientation_estimate_B_W);
336334

337335
// Populate the estimated odometry message. Published in main loop.
338336
target_state->estimated_odometry.header.stamp = timestamp;
339337
target_state->estimated_odometry.header.frame_id = coordinate_system_string;
340338
target_state->estimated_odometry.child_frame_id = object_name;
341-
tf::pointEigenToMsg(position_estimate_W,
342-
target_state->estimated_odometry.pose.pose.position);
343-
tf::quaternionEigenToMsg(
344-
orientation_estimate_B_W,
345-
target_state->estimated_odometry.pose.pose.orientation);
346-
tf::vectorEigenToMsg(velocity_estimate_B,
339+
target_state->estimated_odometry.pose.pose.position = tf2::toMsg(position_estimate_W);
340+
target_state->estimated_odometry.pose.pose.orientation = tf2::toMsg(
341+
orientation_estimate_B_W);
342+
tf2::toMsg(velocity_estimate_B,
347343
target_state->estimated_odometry.twist.twist.linear);
348-
tf::vectorEigenToMsg(rate_estimate_B,
344+
tf2::toMsg(rate_estimate_B,
349345
target_state->estimated_odometry.twist.twist.angular);
350346

351347
// Indicating to the main loop the data is ready for publishing.

src/vicon_estimation_node.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <geometry_msgs/TransformStamped.h>
3232
#include <nav_msgs/Odometry.h>
3333
#include <Eigen/Geometry>
34-
#include <eigen_conversions/eigen_msg.h>
34+
#include <tf2_eigen/tf2_eigen.h>
3535

3636
#include "vicon_odometry_estimator.h"
3737

@@ -63,8 +63,8 @@ class ViconDataListener {
6363
// Extracting the relavent data from the message
6464
Eigen::Vector3d position_measured_W;
6565
Eigen::Quaterniond orientation_measured_B_W;
66-
tf::vectorMsgToEigen(msg->transform.translation, position_measured_W);
67-
tf::quaternionMsgToEigen(msg->transform.rotation, orientation_measured_B_W);
66+
tf2::fromMsg(msg->transform.translation, position_measured_W);
67+
tf2::fromMsg(msg->transform.rotation, orientation_measured_B_W);
6868
ros::Time timestamp = msg->header.stamp;
6969
// Passing the received data to the estimator
7070
vicon_odometry_estimator_->updateEstimate(position_measured_W,
@@ -85,21 +85,18 @@ class ViconDataListener {
8585
// Creating estimated transform message
8686
geometry_msgs::TransformStamped estimated_transform;
8787
estimated_transform.header = msg->header;
88-
tf::vectorEigenToMsg(position_estimate_W,
88+
tf2::toMsg(position_estimate_W,
8989
estimated_transform.transform.translation);
90-
tf::quaternionEigenToMsg(orientation_estimate_B_W,
91-
estimated_transform.transform.rotation);
90+
estimated_transform.transform.rotation = tf2::toMsg(orientation_estimate_B_W);
9291
// Creating estimated odometry message
9392
nav_msgs::Odometry estimated_odometry;
9493
estimated_odometry.header = msg->header;
9594
estimated_odometry.child_frame_id = object_name_;
96-
tf::pointEigenToMsg(position_estimate_W,
97-
estimated_odometry.pose.pose.position);
98-
tf::quaternionEigenToMsg(orientation_estimate_B_W,
99-
estimated_odometry.pose.pose.orientation);
100-
tf::vectorEigenToMsg(velocity_estimate_B,
95+
estimated_odometry.pose.pose.position = tf2::toMsg(position_estimate_W);
96+
estimated_odometry.pose.pose.orientation = tf2::toMsg(orientation_estimate_B_W);
97+
tf2::toMsg(velocity_estimate_B,
10198
estimated_odometry.twist.twist.linear);
102-
tf::vectorEigenToMsg(rate_estimate_B,
99+
tf2::toMsg(rate_estimate_B,
103100
estimated_odometry.twist.twist.angular);
104101
// Publishing the estimates
105102
estimated_transform_pub_.publish(estimated_transform);

src/wrapper/vicon_odometry_estimator.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* limitations under the License.
2020
*/
2121

22-
#include <eigen_conversions/eigen_msg.h>
22+
#include <tf2_eigen/tf2_eigen.h>
2323

2424
#include "vicon_odometry_estimator.h"
2525

@@ -121,30 +121,27 @@ void ViconOdometryEstimator::publishIntermediateResults(ros::Time timestamp) {
121121
msg.header.stamp = timestamp;
122122

123123
// Writing the measurement to the message object
124-
tf::vectorEigenToMsg(translational_estimator_results.position_measured_,
124+
tf2::toMsg(translational_estimator_results.position_measured_,
125125
msg.pos_measured);
126126
// Writing the old estimates to the message object
127-
tf::vectorEigenToMsg(translational_estimator_results.position_old_,
127+
tf2::toMsg(translational_estimator_results.position_old_,
128128
msg.pos_old);
129-
tf::vectorEigenToMsg(translational_estimator_results.velocity_old_,
129+
tf2::toMsg(translational_estimator_results.velocity_old_,
130130
msg.vel_old);
131131
// Posteriori results
132-
tf::vectorEigenToMsg(translational_estimator_results.position_estimate_,
132+
tf2::toMsg(translational_estimator_results.position_estimate_,
133133
msg.pos_est);
134-
tf::vectorEigenToMsg(translational_estimator_results.velocity_estimate_,
134+
tf2::toMsg(translational_estimator_results.velocity_estimate_,
135135
msg.vel_est);
136136

137137
// Writing the measurement to the message object
138-
tf::quaternionEigenToMsg(rotational_estimator_results.orientation_measured_,
139-
msg.quat_measured);
138+
msg.quat_measured = tf2::toMsg(rotational_estimator_results.orientation_measured_);
140139
// Writing the old estimates to the message object
141-
tf::quaternionEigenToMsg(rotational_estimator_results.orientation_old_,
142-
msg.quat_old);
143-
tf::vectorEigenToMsg(rotational_estimator_results.rate_old_, msg.omega_old);
140+
msg.quat_old = tf2::toMsg(rotational_estimator_results.orientation_old_);
141+
tf2::toMsg(rotational_estimator_results.rate_old_, msg.omega_old);
144142
// Posteriori results
145-
tf::quaternionEigenToMsg(rotational_estimator_results.orientation_estimate_,
146-
msg.quat_est);
147-
tf::vectorEigenToMsg(rotational_estimator_results.rate_estimate_,
143+
msg.quat_est = tf2::toMsg(rotational_estimator_results.orientation_estimate_);
144+
tf2::toMsg(rotational_estimator_results.rate_estimate_,
148145
msg.omega_est);
149146

150147
// Data to do with the orientation measurement outlier detection

0 commit comments

Comments
 (0)