Ask Your Question
0

problem with Float32MultiArray in rosserial

asked 2012-11-20 03:44:28 -0600

joseescobar60 gravatar image

updated 2014-01-28 17:14:18 -0600

ngrennan gravatar image

I'm working on my arduino mega 2560 trying to alocate a float values that a flex sensor gives to arduino, but when i try lo read the topic it don't runs, only gives to me this message when i run:

jose@ubuntu:~$ rosrun rosserial_python serial_node.py /dev/ttyACM1
[INFO] [WallTime: 1353426930.914839] ROS Serial Python Node
[INFO] [WallTime: 1353426930.917873] Connected on /dev/ttyACM1 at 57600 baud
[INFO] [WallTime: 1353426933.336893] Setup Publisher on angulos [std_msgs/Float32MultiArray]
[ERROR] [WallTime: 1353426945.920335] Lost sync with device, restarting...
[INFO] [WallTime: 1353426946.190745] Setup Publisher on angulos [std_msgs/Float32MultiArray]
[ERROR] [WallTime: 1353426960.920971] Lost sync with device, restarting...
[INFO] [WallTime: 1353426961.049990] Setup Publisher on angulos [std_msgs/Float32MultiArray]
[ERROR] [WallTime: 1353426975.923001] Lost sync with device, restarting...
[INFO] [WallTime: 1353426976.409013] Setup Publisher on angulos [std_msgs/Float32MultiArray]
[ERROR] [WallTime: 1353426990.927987] Lost sync with device, restarting...
[INFO] [WallTime: 1353426991.268148] Setup Publisher on angulos [std_msgs/Float32MultiArray]
[ERROR] [WallTime: 1353427005.932885] Lost sync with device, restarting...
[INFO] [WallTime: 1353427006.127405] Setup Publisher on angulos [std_msgs/Float32MultiArray]

code in arduino:

    #include <ros.h>
    #include <std_msgs/Float32MultiArray.h>



    ros::NodeHandle nh;

   std_msgs::Float32MultiArray angulos;
   ros::Publisher angulos_pub("angulos", &angulos);

    int findice=1;
    int fcorazon=2;
    int fanular=3;
    int fmenique=4;
    int fpulgar=0;
    int vind = 0;//valor que sensa el flex sensor valor en bits
    int vcor = 0;//valor que sensa el flex sensor valor en bits
    int vanu = 0;//valor que sensa el flex sensor valor en bits
    int vmen = 0;//valor que sensa el flex sensor valor en bits
    int vpul = 0;//valor que sensa el flex sensor valor en bits
    float radind;
    float radcor;
    float radanu;
    float radmen;

      void setup(){
      nh.initNode();

      angulos.layout.dim = (std_msgs::MultiArrayDimension *)
      malloc(sizeof(std_msgs::MultiArrayDimension) * 1);
      angulos.layout.dim[0].label = "angulos";
      angulos.layout.dim[0].size = 4;
      angulos.layout.dim[0].stride = 1*4;
      angulos.layout.dim_length = 1;
      angulos.layout.data_offset = 0;

      angulos.data = (float *)malloc(sizeof(float)*4);
      angulos.data_length = 4;
      nh.advertise(angulos_pub);



    }

    void loop(){

       vind =analogRead(findice);
       vcor =analogRead(fcorazon);
       vanu =analogRead(fanular);
       vmen =analogRead(fmenique);

       radind = ((445-(vind))/(50.7));
       radcor = ((449.85-(vcor))/(55.41));
       radanu = ((479.1-(vanu))/(56.56));
       radmen = ((414.95-(vmen))/(95.76));
       angulos.data[0]= radind;
       angulos.data[1]= radcor;
       angulos.data[2]= radanu;
       angulos.data[3]= radmen;

       angulos_pub.publish(&angulos);
       nh.spinOnce();
       delay(500);

    }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-11-20 04:19:21 -0600

Lorenz gravatar image

Your device is probably segfaulting and keeps rebooting. The reason probably is that you are writing to unallocated memory when accessing the data slot of your message. You need to set the data slot to a pointer to allocated memory before you write the message and publish it. Have a look at this page for more information on how to use arrays in rosserial.

edit flag offensive delete link more

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: 2012-11-20 03:44:28 -0600

Seen: 3,024 times

Last updated: Nov 20 '12