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

Rosserial arduino, unpack requires a string arguement of length 4

asked 2013-09-19 23:37:56 -0500

theplague gravatar image

updated 2013-11-18 19:23:38 -0500

tfoote gravatar image

EDIT: The exact cause of the issue is coming from my message having some odd bits of data in it.

str is
}chatterstd_msgs/String 992ce8a1687cec8c8bd883ec73ca41d1
str is 
toggle_ledtdstd_msgs/String 92992ce8a1687cec8c8bd883ec73ca41d1

The first string is used to create the publisher and the second is used to create the subscriber, the second has some extra characters (which is throwing the length error and I can't figure out why.

---Original Question---

Okay so I'm following the rosserial arduino tutorials, having just installed hydro. I'm using ubuntu 12.04 and currently attempting to run roslib pubsub, the source code is below. However I am receiving this error:

[INFO] [WallTime: 1379669386.460493] ROS Serial Python Node
[INFO] [WallTime: 1379669386.472761] Connecting to /dev/ttyACM2 at 57600 baud
[INFO] [WallTime: 1379669389.183587] Note: publish buffer size is 280 bytes
[INFO] [WallTime: 1379669389.183904] Setup publisher on chatter [std_msgs/String]
[ERROR] [WallTime: 1379669389.185947] Creation of subscriber failed: unpack requires a string argument of length 4

So yeah, I've seen multiple other quesitons with the same error however no solution appears to be working for me.

I have ran

catkin_make install
source ws/install/setup.bash

this is after having cloned the repo with git. Any help would be appreciated thanks.

The source code is:

* rosserial PubSub Example
* Prints "hello world!" and toggles led

#include <ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Empty.h>

ros::NodeHandle  nh;

void messageCb( const std_msgs::Empty& toggle_msg){
  digitalWrite(13, HIGH-digitalRead(13));   // blink the led

ros::Subscriber<std_msgs::Empty> sub("toggle_led", messageCb );
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);

char hello[13] = "hello world!";

void setup()
  pinMode(13, OUTPUT);

void loop()
{ = hello;
  chatter.publish( &str_msg );

I first compile and run on the arduino then i use

rosrun rosserial_python /dev/ttyACM0

Which then throws the above error.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-09-21 02:57:48 -0500

theplague gravatar image

updated 2013-09-21 02:59:57 -0500

Okay I've found a "solution", the line:

ros::Subscriber<std_msgs::String> sub("toggle_led", &messageCb );


toggle_ledtdstd_msgs/String 92992ce8a1687cec8c8bd883ec73ca41d1

Which is the incorrect length, or something. Thus by shortening the topic to be between 6 or 7 characters the error does not occur. E.g.

ros::Subscriber<std_msgs::String> sub("toggle", &messageCb );

I get:

dtogglestd_msgs/String 992ce8a1687cec8c8bd883ec73ca41d1

Which fits the length and works, i'm not sure if this is problem with rosserial.

edit flag offensive delete link more


Hi, i have the same problem, but mine can't be solved as yours...i dont know why...!!!I tried ros hello world example and it works fine but when i try an example with a subscriber, whatever topic name is, i get : (from pubsub ros example) [INFO] [WallTime: 1380287883.995053] ROS Serial Python Node [INFO] [WallTime: 1380287884.001497] Connecting to /dev/ttyACM0 at 57600 baud [INFO] [WallTime: 1380287886.607383] Note: publish buffer size is 512 bytes [INFO] [WallTime: 1380287886.607882] Setup publisher on chatter [std_msgs/String] [ERROR] [WallTime: 1380287886.609524] Creation of subscriber failed: unpack requires a string argument of length 4 I use hydro on ubuntu 12.04 64bit.Is there a way to solve it?I'm stuck here...!Someone can help me? thank!

GioRos gravatar image GioRos  ( 2013-09-27 03:38:11 -0500 )edit

answered 2013-09-20 01:02:42 -0500

Chrimo gravatar image

Hi, are you sure, that you use a ros example and not the arduino example ? Try samples from MockBot for simple tests...

TODO: untar the ros_lib.hydro.tgz to your Arduino libraries directory load, compile and upload MockBotSerialServoADC.ino

This works fine at my MockBot :-)

edit flag offensive delete link more


I've now posted the source which shows that it is a Ros example :|

theplague gravatar image theplague  ( 2013-09-20 01:46:32 -0500 )edit

Question Tools



Asked: 2013-09-19 23:37:56 -0500

Seen: 1,413 times

Last updated: Sep 21 '13