ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

reading a specific tf frame

asked 2014-09-24 12:58:11 -0500

choog gravatar image

updated 2014-09-25 17:38:10 -0500

Hello,

Does anyone know if there is a function that lets you read a specific tf frame such as:

.readFrame("/base_link" , time(latest info published), //frame reference);

I need to be able to read a specific frame. I know you can do: tf::StampedTransform transform; .lookUpTransform("target frame", "original frame" , time , transform);

The reason why I don't want a lookUpTransform is because I am actually not trying to take the transform of anything here. Unless I am not understanding something here, I would appreciate some feed back here.

This is what I have so far. Please give me some feed back on the frames that I am using. Because to my understanding The "base_link" frame should be transformed to the "map" frame, If I have a .yaml map file running on top of the navigation stack right?

  #include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <geometry_msgs/TransformStamped.h>
#include <tf/transform_listener.h>
#include <tf/transform_broadcaster.h>
#include <tf/transform_broadcaster.h>

using namespace std;

int main(int argc, char** argv) {
    ros::init(argc, argv, "readTFframe");
    ros::NodeHandle nh;
        tf::Transform leader_base_link;
    tf::Quaternion q;
    tf::Vector3 v;  
    tf::TransformListener listener;
    geometry_msgs::TransformStamped transformConverter;

    ros::Time current_time, last_time;
        current_time = ros::Time::now();
        last_time = ros::Time::now();

    ros::Publisher pub = nh.advertise<geometry_msgs::TransformStamped>("/leader/tf", 1);

    static tf::TransformBroadcaster br;

    double yaw; 


ros::Rate loopRate(10);
while(ros::ok()){
    tf::StampedTransform transform;
    current_time = ros::Time::now();


    try {
                        listener.waitForTransform("base_link", "base_footprint", ros::Time(0), ros::Duration(10.0));
            listener.lookupTransform("base_link", "base_footprint", ros::Time(0), transform);
        }
        catch (tf::TransformException &ex) {
            ROS_ERROR("%s",ex.what());
        }
    yaw =   tf::getYaw(transform.getRotation()); 
        v.setValue(transform.getOrigin().x() , transform.getOrigin().y() , transform.getOrigin().z());

    leader_base_link.setOrigin(v);
    q.setRPY(0.0, 0.0, yaw);
    leader_base_link.setRotation(q );
    br.sendTransform(tf::StampedTransform(leader_base_link, ros::Time::now(), "base_footprint", "leader_base_link"));

/*
    ROS_INFO_STREAM("X pose " <<  transform.getOrigin().x() );
    ROS_INFO_STREAM("Y pose " << transform.getOrigin().y() );
    ROS_INFO_STREAM("Z pose " << transform.getOrigin().z() );
    ROS_INFO_STREAM("Yaw "<< yaw );
*/  
double th = yaw;
 geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw(th);
    transformConverter.header.stamp = current_time; 
    transformConverter.header.frame_id = "base_footprint";
    transformConverter.child_frame_id = "base_link";
    transformConverter.transform.translation.x = transform.getOrigin().x();
    transformConverter.transform.translation.y = transform.getOrigin().y();
    transformConverter.transform.translation.z = transform.getOrigin().z();
    transformConverter.transform.rotation = odom_quat;
    ROS_INFO_STREAM("X pose " <<  transformConverter.transform.translation.x );
    ROS_INFO_STREAM("Y pose " << transformConverter.transform.translation.y);
    ROS_INFO_STREAM("Z pose " << transformConverter.transform.translation.z );
    ROS_INFO_STREAM("Yaw "<< yaw );

    loopRate.sleep();
}

    return 0;
}

This is my current code when I run it I can see that the values are being passed to the transformConverter transform that is converting the desired transform from tf::StampedTransform to geometry_msgs::TransformStamped . This way it can be published on the topic /leader/tf. The only thing is I can see the values are passed through ROS_INFO. But they are not being published now on the topic.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2014-09-25 15:42:34 -0500

tfoote gravatar image

What you want is exactly the output from lookupTransform. It provides the transform between the two frames. The position of frameA in frameB is the same as the transform to transform a point from frameB into frameA. If you reverse the order of the frame_ids it will give the transform of the coordinate frame instead of a point. (This will just give you the inverse value.)

edit flag offensive delete link more

Comments

What if I am trying to publish a transform holding that data to a topic?

choog gravatar image choog  ( 2014-09-25 15:49:39 -0500 )edit
tfoote gravatar image tfoote  ( 2014-09-25 16:10:17 -0500 )edit

That was my initial thought but I am getting this error: error: no match for call to ‘(ros::Publisher) (tf::StampedTransform&)’

choog gravatar image choog  ( 2014-09-25 16:13:49 -0500 )edit

With your latest edit. The reason your message is not being sent out is that you're not actually calling publish

tfoote gravatar image tfoote  ( 2014-09-26 15:59:31 -0500 )edit
0

answered 2014-09-24 13:20:40 -0500

bvbdort gravatar image

Frame is not specific data type to read. frame will have just name, no other info.

edit flag offensive delete link more

Comments

So you are saying if I read the frame it will just be the name? Well how do I read the contents of the frame?

choog gravatar image choog  ( 2014-09-24 13:42:59 -0500 )edit

Frame has no info except name. What info you want to read exactly.

bvbdort gravatar image bvbdort  ( 2014-09-24 13:44:53 -0500 )edit

The base_link frame that contains the position of the robot.

choog gravatar image choog  ( 2014-09-24 14:38:15 -0500 )edit

then you need tf between base_link and odom

bvbdort gravatar image bvbdort  ( 2014-09-24 14:42:13 -0500 )edit

I can see that the parent node to base_link is base_footprint. You are saying get a transform of these 2 frames?

choog gravatar image choog  ( 2014-09-24 16:09:51 -0500 )edit

When you say that you want to "read" a frame what information are you looking for? How do you plan to use it after you get the information?

tfoote gravatar image tfoote  ( 2014-09-24 16:20:13 -0500 )edit

@chood what is fixed frame for your environment ? find tf between fixed frame and base frame to know position of robot in environment.

bvbdort gravatar image bvbdort  ( 2014-09-25 03:02:07 -0500 )edit

The information I want to read is the position of the robot. I am using a turtlebot. After I read the information I plan to publish that info to a topic that will be sent to another machine via a foreign relay. Then once the info is there at the other machine. That machine will have it's own

choog gravatar image choog  ( 2014-09-25 13:51:52 -0500 )edit

Question Tools

Stats

Asked: 2014-09-24 12:58:11 -0500

Seen: 3,195 times

Last updated: Sep 25 '14