use new tf broadcaster with vectors

This commit is contained in:
wim 2010-04-23 23:18:33 +00:00
parent c8cb7dce19
commit e5fc479762
2 changed files with 10 additions and 18 deletions

View File

@ -40,7 +40,7 @@
#include <ros/ros.h> #include <ros/ros.h>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <tf/tf.h> #include <tf/tf.h>
#include <tf/tfMessage.h> #include <tf/transform_broadcaster.h>
#include "robot_state_publisher/treefksolverposfull_recursive.hpp" #include "robot_state_publisher/treefksolverposfull_recursive.hpp"
namespace robot_state_publisher{ namespace robot_state_publisher{
@ -68,8 +68,8 @@ private:
KDL::Tree tree_; KDL::Tree tree_;
boost::scoped_ptr<KDL::TreeFkSolverPosFull_recursive> solver_; boost::scoped_ptr<KDL::TreeFkSolverPosFull_recursive> solver_;
std::string root_; std::string root_;
std::string tf_prefix_; std::vector<tf::StampedTransform> transforms_;
tf::tfMessage tf_msg_; tf::TransformBroadcaster tf_broadcaster_;
class empty_tree_exception: public std::exception{ class empty_tree_exception: public std::exception{
virtual const char* what() const throw(){ virtual const char* what() const throw(){

View File

@ -49,12 +49,6 @@ namespace robot_state_publisher{
RobotStatePublisher::RobotStatePublisher(const Tree& tree) RobotStatePublisher::RobotStatePublisher(const Tree& tree)
:tree_(tree) :tree_(tree)
{ {
// get tf prefix
NodeHandle n_local("~");
std::string searched_param;
n_local.searchParam("tf_prefix", searched_param);
n_local.param(searched_param, tf_prefix_, std::string());
// build tree solver // build tree solver
solver_.reset(new TreeFkSolverPosFull_recursive(tree_)); solver_.reset(new TreeFkSolverPosFull_recursive(tree_));
@ -78,21 +72,19 @@ bool RobotStatePublisher::publishTransforms(const map<string, double>& joint_pos
ROS_ERROR("Could not compute link poses. The tree or the state is invalid."); ROS_ERROR("Could not compute link poses. The tree or the state is invalid.");
return false; return false;
} }
tf_msg_.transforms.resize(link_poses.size()); transforms_.resize(link_poses.size());
// send transforms to tf // send transforms to tf
geometry_msgs::TransformStamped trans;
tf::Transform tf_frame; tf::Transform tf_frame;
unsigned int i = 0; unsigned int i = 0;
for (map<string, Frame>::const_iterator f=link_poses.begin(); f!=link_poses.end(); f++){ for (map<string, Frame>::const_iterator f=link_poses.begin(); f!=link_poses.end(); f++){
tf::TransformKDLToTF(f->second, tf_frame); tf::TransformKDLToTF(f->second, transforms_[i]);
trans.header.stamp = time; transforms_[i].stamp_ = time;
trans.header.frame_id = tf::resolve(tf_prefix_, root_); transforms_[i].frame_id_ = root_;
trans.child_frame_id = tf::resolve(tf_prefix_, f->first); transforms_[i].child_frame_id_ = f->first;
tf::transformTFToMsg(tf_frame, trans.transform); i++;
tf_msg_.transforms[i++] = trans;
} }
tf_publisher_.publish(tf_msg_); tf_broadcaster_.sendTransform(transforms_);
return true; return true;
} }