Ask Your Question
1

tf Listener for OpenNI Tracker [Solved]

asked 2016-03-28 11:41:53 -0500

PKumars gravatar image

updated 2016-03-31 07:43:52 -0500

Hello all, I want get joint coordinates of skeleton. I understand that I can get this information using tf listener as mentioned here. http://wiki.ros.org/tf/Tutorials/Writ...

But I have problem in understanding how to mention each joint(from pi pose) in this section of code. while (node.ok()) { tf::StampedTransform transform; try{ listener.lookupTransform("/turtle2", "/turtle1", ros::Time(0), transform); }

is it possible for any one to guide me or provide an example code so that I can get all the joint coordinates.

EDIT

int main(int argc, char** argv) { ros::init(argc, argv, "my_tf_listener");

ros::NodeHandle node;

ros::service::waitForService("spawn");
ros::ServiceClient add_turtle = node.serviceClient<turtlesim::Spawn>("spawn");
turtlesim::Spawn srv;
add_turtle.call(srv);

tf::TransformListener listener;

ros::Rate rate(1.0);
while (node.ok())
{
    tf::StampedTransform transform;
    try
    {
        listener.lookupTransform("/head", "/neck","/torso",
                                    "/left_shoulder","/left_elbow","/left_hand",
                                        "/right_shoulder","/right_elbow","/right_hand",
                                            "/left_hip","/left_knee","/left_foot",
                                                "/right_hip","/right_knee","/right_foot",
                                                        ros::Time(0), transform);

    }
        catch (tf::TransformException &ex) 
    {
    ROS_ERROR("%s",ex.what());
    ros::Duration(1.0).sleep();
    continue;
}

rate.sleep();
}
return 0;

};

I'm trying to do this, but I'm getting error during compilation.

error: no matching function for call to ‘tf::TransformListener::lookupTransform(const char [6], const char [6], const char [7], const char [15], const char [12], const char [11], const char [16], const char [13], const char [12], const char [10], const char [11], const char [11], const char [11], const char [12], const char [12], ros::Time, tf::StampedTransform&)’ ros::Time(0), transform); ^

Thanks, Regards, Prasanna

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2016-03-28 12:56:52 -0500

NEngelhard gravatar image

updated 2016-03-28 14:59:24 -0500

The listener only looks up the transformation between two frames. What do you expect your call to provide? You only pass a single transformation, but a huge list of frames. If you want multiple transformations, you have to call lookupTransform several times, each time with a pair of frame-names.

edit flag offensive delete link more

Comments

OK. Thanks a lot for your reply. But if I put "/head" as one transform then what should be the second transform?

PKumars gravatar image PKumars  ( 2016-03-28 13:12:28 -0500 )edit

Sorry for the confusion. I want to get coordinates with respect to kinect frame. so what should I use as a second transform to get position with respect to kinect frame origin? Thanks..

PKumars gravatar image PKumars  ( 2016-03-28 13:18:11 -0500 )edit

I think you should reread the tutorials as you are mixing things. "/head" is no transformation but a frame. A transformation consist of the information of how you transform poses that are given in one frame into another frame.

NEngelhard gravatar image NEngelhard  ( 2016-03-28 14:13:46 -0500 )edit

Thanks for your guidance. I solved the problem. I'm posting it as an Answer. hope you have no objection.

PKumars gravatar image PKumars  ( 2016-03-30 03:18:22 -0500 )edit
0

answered 2016-03-30 03:25:58 -0500

PKumars gravatar image

Here is the Final answer where I'm extracting all the joint coordinates and then publishing them in each topic.

#include <ros ros.h=""> #include <tf transform_listener.h=""> #include <geometry_msgs twist.h="">

int main(int argc, char** argv) { ros::init(argc, argv, "my_skeleton_tf_listener");

ros::NodeHandle node;

// publisher declaration
ros::Publisher neck_joint = node.advertise<geometry_msgs::Point>("neck_joint", 1);
ros::Publisher head_joint = node.advertise<geometry_msgs::Point>("head_joint", 1);
ros::Publisher torso_joint = node.advertise<geometry_msgs::Point>("torso_joint", 1);
ros::Publisher left_shoulder_joint = node.advertise<geometry_msgs::Point>("left_shoulder_joint", 1);
ros::Publisher left_elbow_joint = node.advertise<geometry_msgs::Point>("left_elbow_joint", 1);
ros::Publisher left_hand_joint = node.advertise<geometry_msgs::Point>("left_hand_joint", 1);
ros::Publisher right_shoulder_joint = node.advertise<geometry_msgs::Point>("right_shoulder_joint", 1);
ros::Publisher right_elbow_joint = node.advertise<geometry_msgs::Point>("right_elbow_joint", 1);
ros::Publisher right_hand_joint = node.advertise<geometry_msgs::Point>("right_hand_joint", 1);
ros::Publisher left_hip_joint = node.advertise<geometry_msgs::Point>("left_hip_joint", 1);
ros::Publisher left_knee_joint = node.advertise<geometry_msgs::Point>("left_knee_joint", 1);
ros::Publisher left_foot_joint = node.advertise<geometry_msgs::Point>("left_foot_joint", 1);
ros::Publisher right_hip_joint = node.advertise<geometry_msgs::Point>("right_hip_joint", 1);
ros::Publisher right_knee_joint = node.advertise<geometry_msgs::Point>("right_knee_joint", 1);
ros::Publisher right_foot_joint = node.advertise<geometry_msgs::Point>("right_foot_joint", 1);

// listener 
tf::TransformListener listener;

ros::Rate rate(50.0); // frequency of operation

while (node.ok())
{
    // Transforms declared for each joint
    tf::StampedTransform transform_neck, transform_head, transform_torso, 
                            transform_left_shoulder, transform_left_elbow, transform_left_hand, 
                                transform_right_shoulder, transform_right_elbow, transform_right_hand, 
                                    transform_left_hip, transform_left_knee, transform_left_foot,
                                        transform_right_hip, transform_right_knee, transform_right_foot;
    try
    {
        // each joint frame to reference frame transforms 
        listener.lookupTransform("/neck_1", "/openni_depth_frame",ros::Time(0), transform_neck);
        listener.lookupTransform("/head_1", "/openni_depth_frame",ros::Time(0), transform_head);
        listener.lookupTransform("/torso_1", "/openni_depth_frame",ros::Time(0), transform_torso);
        listener.lookupTransform("/left_shoulder_1", "/openni_depth_frame",ros::Time(0), transform_left_shoulder);
        listener.lookupTransform("/left_elbow_1", "/openni_depth_frame",ros::Time(0), transform_left_elbow);
        listener.lookupTransform("/left_hand_1", "/openni_depth_frame",ros::Time(0), transform_left_hand);
        listener.lookupTransform("/right_shoulder_1", "/openni_depth_frame",ros::Time(0), transform_right_shoulder);
        listener.lookupTransform("/right_elbow_1", "/openni_depth_frame",ros::Time(0), transform_right_elbow);
        listener.lookupTransform("/right_hand_1", "/openni_depth_frame",ros::Time(0), transform_right_hand);
        listener.lookupTransform("/left_hip_1", "/openni_depth_frame",ros::Time(0), transform_left_hip);
        listener.lookupTransform("/left_knee_1", "/openni_depth_frame",ros::Time(0), transform_left_knee);
        listener.lookupTransform("/left_foot_1", "/openni_depth_frame",ros::Time(0), transform_left_foot);
        listener.lookupTransform("/right_hip_1", "/openni_depth_frame",ros::Time(0), transform_right_hip);
        listener.lookupTransform("/right_knee_1", "/openni_depth_frame",ros::Time(0), transform_right_knee);
        listener.lookupTransform("/right_foot_1", "/openni_depth_frame",ros::Time(0), transform_right_foot);

    }
        catch (tf::TransformException &ex) 
    {
        ROS_ERROR("%s",ex.what());
        ros::Duration(0.10).sleep();
        continue;
    }

    // geometry points declaration for storing 3D coordinates of joints and then published later 
    geometry_msgs::Point neck_pose, head_pose, torso_pose, 
                            left_shoulder_pose, left_elbow_pose, left_hand_pose,
                                right_shoulder_pose, right_elbow_pose, right_hand_pose, 
                                    left_hip_pose, left_knee_pose, left_foot_pose, 
                                        right_hip_pose, right_knee_pose, right_foot_pose;

    // joint position extraction and store
    // neck joint                                   
    neck_pose.x = transform_neck.getOrigin().x();
    neck_pose.y = transform_neck.getOrigin().y();
    neck_pose.z = transform_neck.getOrigin().z();
    // head joint
    head_pose.x = transform_head.getOrigin().x();
    head_pose.y = transform_head.getOrigin().y();
    head_pose.z = transform_head.getOrigin().z();
    // torso joint
    torso_pose.x = transform_torso.getOrigin().x();
    torso_pose.y = transform_torso.getOrigin().y();
    torso_pose.z = transform_torso.getOrigin().z();
    // left shoulder joint 
    left_shoulder_pose.x = transform_left_shoulder.getOrigin().x();
    left_shoulder_pose.y = transform_left_shoulder.getOrigin().y();
    left_shoulder_pose.z = transform_left_shoulder.getOrigin().z();
    // left elbow joint
    left_elbow_pose.x = transform_left_elbow.getOrigin().x();
    left_elbow_pose.y = transform_left_elbow.getOrigin().y();
    left_elbow_pose.z = transform_left_elbow.getOrigin().z();
    // left hand joint
    left_hand_pose.x = transform_left_hand.getOrigin().x();
    left_hand_pose.y = transform_left_hand.getOrigin().y();
    left_hand_pose.z = transform_left_hand ...
(more)
edit flag offensive delete link more

Comments

Hi good sir, while running your package, I encountered an error:

[ERROR] [1474942654.544272399]: "neck_1" passed to lookupTransform argument target_frame does not exist. Do you know why does the above occurred? Hope you can enlighten me as this package is important. Thanks for your input!

kentlo963 gravatar image kentlo963  ( 2016-09-26 21:44:07 -0500 )edit

Hello, this should work perfectly. There are several other things that you must take care during execution of this program. there should exist two frames("/neck_1", "/openni_depth_frame"), then you can get transform using TF listener. My suggestion is that you should first check it in RViz

PKumars gravatar image PKumars  ( 2016-09-27 03:43:12 -0500 )edit

@PKumars Sorry I am new to new to ROS can you please tell me how to run the program on the terminal.

fundamentals gravatar image fundamentals  ( 2017-02-07 08:59:57 -0500 )edit
1

you can run that node typing the command in terminal. rosrun package_name node_name but you must run kinect node first like: roslaunch openni_..... check the cmakelists.txt and compile the package before running the program node. if you have any doubt in running program then please see ROS Tutorial.

PKumars gravatar image PKumars  ( 2017-02-07 09:50:58 -0500 )edit

@PKumars Thank you for the answer. I also want to ask the name of the node is skelcord.cpp right?

fundamentals gravatar image fundamentals  ( 2017-02-08 07:23:17 -0500 )edit

yes. skelCord.cpp

PKumars gravatar image PKumars  ( 2017-02-08 07:40:17 -0500 )edit

Hi. When I tried to use your listener.cpp I'm facing problems with my torso and elbow positions. The most critical problem is with my elbow joint. While i move my hand from -Y to Y with my elbow steady (kinect coordinate), the Y coordinate of elbow joint also increase/decrease. How can I fix that?

Quartz gravatar image Quartz  ( 2018-04-16 13:41:20 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-03-28 11:41:53 -0500

Seen: 1,136 times

Last updated: Mar 31 '16