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

sprintf. process has died exit code -11

asked 2016-12-22 00:05:52 -0600

Andrea019 gravatar image

updated 2016-12-23 13:34:27 -0600

I have to get data from a kinect, and to compute some angles.

So, I have this code that worked perfectly in ros Groovy, Ubuntu 12 and now I have to change the machine and work with indigo Ubuntu 14.04. Its the same folder, the same procedure but it crashes when i launch it, and I am not able to find out why this is happening :(

[listener_tf-1] process has died [pid 11824, exit code -11, cmd /home/andrea/catkin_ws/devel/lib/listener_tf/listener_tf __name:=listener_tf __log:=/home/andrea/.ros/log/dcee0976-c7d7-11e6-b6d6-083e8e6b82c1/listener_tf-1.log].log file: /home/andrea/.ros/log/dcee0976-c7d7-11e6-b6d6-083e8e6b82c1/listener_tf-1*.log

There is not a log file in the directory that it says it is, btw :(

I have done the "comment and uncomment stuff" to identify the error, and I know the thing is right in this part of the code (It crashes if either the sprintf line or the listener.lookupTransform line are uncomment):

for (int i=1;i<10;i++)
    {
        int n = sprintf(persona,"%d",i);
        /** itoa convert integer to string (non standard function
         * sprintf(target_string,"%d",source_int) */
        try
        {
            listener.lookupTransform("/openni_depth_frame", "/torso_"+std::string(persona), ros::Time(0), torso);
            break;
        }
        catch (tf::TransformException ex)
        {
        }

Here is the full code, thank you in advance !

#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <std_msgs/Header.h>
#include <tf/transform_listener.h>

void imprime_torso (tf::StampedTransform torso)
{
    float torso_x = torso.getOrigin().x();
    float torso_y = torso.getOrigin().y();
    printf("\n\ntorso.x = %f",torso_x);
    printf("\ntorso.y = %f",torso_y);
}


    void imprime_rodilla (tf::StampedTransform left_knee, tf::StampedTransform right_knee)
    {
        float rod_izq_x = left_knee.getOrigin().x();
        float rod_izq_y = left_knee.getOrigin().y();
        float rod_der_x = right_knee.getOrigin().x();
        float rod_der_y = right_knee.getOrigin().y();
        printf("\n\nrodilla.izq.x = %f",rod_izq_x);
    printf("\nrodilla.izq.y = %f",rod_izq_y);
    printf("\nrodilla.der.x = %f",rod_der_x);
    printf("\nrodilla.der.y = %f",rod_der_y);
}

void imprime_cadera (tf::StampedTransform left_hip, tf::StampedTransform right_hip)
{
    float cad_izq_x = left_hip.getOrigin().x();
    float cad_izq_y = left_hip.getOrigin().y();
    float cad_der_x = right_hip.getOrigin().x();
    float cad_der_y = right_hip.getOrigin().y();
    printf("\n\ncadera.izq.x = %f",cad_izq_x);
    printf("\ncadera.izq.y = %f",cad_izq_y);
    printf("\ncadera.der.x = %f",cad_der_x);
    printf("\ncadera.der.y = %f",cad_der_y);
}

void imprime_pie (tf::StampedTransform left_foot, tf::StampedTransform right_foot)
{
    float pie_izq_x = left_foot.getOrigin().x();
    float pie_izq_y = left_foot.getOrigin().y();
    float pie_der_x = right_foot.getOrigin().x();
    float pie_der_y = right_foot.getOrigin().y();
    printf("\n\npie.izq.x = %f",pie_izq_x);
    printf("\npie.izq.y = %f",pie_izq_y);
    printf("\npie.der.x = %f",pie_der_x);
    printf("\npie.der.y = %f",pie_der_y);
}

int main(int argc, char** argv)
{
    ros::init(argc, argv, "listener_tf");
    ros::NodeHandle node;
    ros::Rate rate(10.0);

    char *persona;
    tf::TransformListener listener;
    //(void)sprintf(persona,"%d",1);

    while (node.ok())
    {
        tf::StampedTransform torso;
        tf::StampedTransform left_hip;
        tf::StampedTransform left_knee;
        tf::StampedTransform left_foot;
        tf::StampedTransform right_hip;
        tf::StampedTransform right_knee;
        tf::StampedTransform right_foot;
       for (int i=1;i<10;i++)
        {
            int n = sprintf(persona,"%d",i);

            try
            {
                listener.lookupTransform("/openni_depth_frame", "/torso_"+std::string(persona), ros::Time(0), torso);
                break;
            }
            catch (tf::TransformException ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2016-12-24 02:43:43 -0600

NEngelhard gravatar image

Check the docu for sprintf: http://www.cplusplus.com/reference/cs... "The buffer should be large enough to contain the resulting string." So initialize 'persona' with a sufficient length. It's also a good practice to use english variable names so that people can understand your code better if you ask for help.

edit flag offensive delete link more

Comments

thank you! I initialize it like char persona[10| instead of char *persona and it worked!

PD: sorry for the spanish

Andrea019 gravatar image Andrea019  ( 2016-12-24 10:58:08 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-12-22 00:05:52 -0600

Seen: 2,274 times

Last updated: Dec 24 '16