Skip to content

Commit

Permalink
uas mavlink#71: Use single TF2 objects for broadcasting and subscript…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
vooon authored and TSC21 committed Jul 12, 2015
1 parent 182fb73 commit 0a20ace
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 8 additions & 0 deletions mavros/include/mavros/mavros_uas.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <Eigen/Eigen>
#include <Eigen/Geometry>
#include <tf/transform_datatypes.h>
#include <tf2_ros/transform_listener.h>
#include <tf2_ros/transform_broadcaster.h>
#include <diagnostic_updater/diagnostic_updater.h>
#include <mavconn/interface.h>

Expand Down Expand Up @@ -202,6 +204,12 @@ class UAS {
sensor_msgs::NavSatFix::Ptr get_gps_fix();


/* -*- transform -*- */

tf2_ros::Buffer tf2_buffer;
tf2_ros::TransformListener tf2_listener;
tf2_ros::TransformBroadcaster tf2_broadcaster;

/* -*- time sync -*- */

inline void set_time_offset(uint64_t offset_ns) {
Expand Down
1 change: 1 addition & 0 deletions mavros/src/lib/uas_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using namespace mavros;

UAS::UAS() :
tf2_listener(tf2_buffer, true),
type(MAV_TYPE_GENERIC),
autopilot(MAV_AUTOPILOT_GENERIC),
target_system(1),
Expand Down
5 changes: 1 addition & 4 deletions mavros/src/plugins/global_position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <mavros/gps_conversions.h>
#include <pluginlib/class_list_macros.h>
#include <eigen_conversions/eigen_msg.h>
#include <tf2_ros/transform_broadcaster.h>

#include <std_msgs/Float64.h>
#include <sensor_msgs/NavSatFix.h>
Expand Down Expand Up @@ -95,8 +94,6 @@ class GlobalPositionPlugin : public MavRosPlugin {
ros::Publisher gp_hdg_pub;
ros::Publisher gp_rel_alt_pub;

tf2_ros::TransformBroadcaster tf2_broadcaster;

std::string frame_id; //!< frame for topic headers
std::string tf_frame_id; //!< origin for TF
std::string tf_child_frame_id; //!< frame for TF and Pose
Expand Down Expand Up @@ -282,7 +279,7 @@ class GlobalPositionPlugin : public MavRosPlugin {
transform.transform.translation.y = pose_cov->pose.pose.position.y;
transform.transform.translation.z = pose_cov->pose.pose.position.z;

tf2_broadcaster.sendTransform(transform);
uas->tf2_broadcaster.sendTransform(transform);
}
}

Expand Down
4 changes: 1 addition & 3 deletions mavros/src/plugins/local_position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <mavros/mavros_plugin.h>
#include <pluginlib/class_list_macros.h>
#include <tf2_ros/transform_broadcaster.h>
#include <eigen_conversions/eigen_msg.h>

#include <geometry_msgs/PoseStamped.h>
Expand Down Expand Up @@ -61,7 +60,6 @@ class LocalPositionPlugin : public MavRosPlugin {
UAS *uas;

ros::Publisher local_position;
tf2_ros::TransformBroadcaster tf2_broadcaster;

std::string frame_id; //!< frame for Pose
std::string tf_frame_id; //!< origin for TF
Expand Down Expand Up @@ -96,7 +94,7 @@ class LocalPositionPlugin : public MavRosPlugin {
transform.transform.rotation = pose->pose.orientation;
tf::vectorEigenToMsg(position, transform.transform.translation);

tf2_broadcaster.sendTransform(transform);
uas->tf2_broadcaster.sendTransform(transform);
}
}
};
Expand Down

0 comments on commit 0a20ace

Please sign in to comment.