Rosanswers logo

I'm trying to read human joint angles using tf messages posted by openni_tracker. Tracker posts tf messages and it seems these are normally read with a tf::TransformListener object. I got this part to work, and I am receiving the transforms, but I have a few problems. (Has anyone done this already? Is there a stack/package or code?)

1): The TransformListener.lookupTransform() method takes two strings for the frames to get the transform between. I've been using things like "/right_shoulder_1" to indicate the right shoulder of the first skeleton the tracker sees. The problem is that if the tracker looses the first person, all these frames are deleted and it starts using "/right_shoulder_2" for the next person. How can I just get the transforms for whatever skeleton is currently being tracked?

  1. To get the angle between limbs, I've basically been trying to get the 3D vectors for each joint, compute the vectors between them representing limbs between two joints (taking the difference between joint vectors), and calculating the angle between these limb vectors. Doing this through the TransformListner seems very inefficient - I don;t need any information other than the relative vector positions of the joints. Is there a better way?


Here's the code I have so far for just printing the elbow angle. (Doesn't work, seems to always print the same angle of 1.546 (~88.6 degrees))

#include <ros/ros.h>
#include <actionlib/client/simple_action_client.h>
#include <arm_navigation_msgs/MoveArmAction.h>
#include "std_msgs/String.h"
#include <tf/transform_listener.h>

#define my_pi 3.141592653589793 // Define the PI number for vector calculations

void getTransform(tf::StampedTransform t, tf::TransformListener *l, const std::string &from, const std::string &to){
        (*l).lookupTransform(   from,           //from frame
                                to,     //to frame
                                ros::Time(0),       //latest
                                t);     //object to store result in
    catch (tf::TransformException ex){

void printTransform(tf::StampedTransform t){
    //output angle
    printf("%lf", t.getOrigin().x());
    printf("%lf", t.getOrigin().y());
    printf("%lf", t.getOrigin().z());

int main(int argc, char **argv){

    ros::init(argc, argv, "kinect_control");

    ros::NodeHandle node;

    tf::TransformListener listener;

    double elbowAngle=0.0;
    //main loop
    ros::Rate rate(10.0);
    while (node.ok()){
        tf::StampedTransform rShoulderToRElbow;
        tf::StampedTransform rElbowToRHand;

        printf("%lf", elbowAngle);


    return 0;

Originally posted by DanF on ROS Answers with karma: 1 on 2012-12-30

Post score: 0


1 Answer 1


Rosanswers logo

There are two methods I can think of that you could follow. The first is you modify the Openni_tracker package and output the users presently being published and the second is to use the getstringframes() function from the transform listener class and see which users are being published.

Originally posted by Rookdroid with karma: 76 on 2013-03-19

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by Stephane.M on 2013-03-19:
I agree with both methods, but I would recommend the second one :-)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.