Ask Your Question

Issue with Rosserial Custom Message

asked 2018-07-10 09:43:32 -0600

nprof50 gravatar image

I am using ROS Kinetic on Ubuntu 16.04. I've been trying to get a custom message type to work over rosserial_arduino for some time now. I have properly generated the C++ message headers in the package. For reference, here is the custom message type I am planning on using:

# MotorEncoder.msg
int32 leftValue
int32 rightValue
time leftTime
time rightTime

After running catkin_make on the project workspace, I run the source devel/setup.bash command to let ROS know I have messages that need to have generated Arduino-based headers. Then I run the command

rosrun rosserial_client make_libraries ~/Arduino/libraries

This generates the Arduino-based headers which I am able to properly compile and run using this Arduino script:

#include <ros.h>
#include <rover_core/MotorEncoder.h>

ros::NodeHandle nh;
rover_core::MotorEncoder msg;
ros::Publisher pub("/test", &msg);

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:

I ran the rosserial node after deploying it to the arduino:

 rosrun rosserial_python /dev/ttyUSB0

And I get the output:

[INFO] [1531232541.250369]: ROS Serial Python Node
[INFO] [1531232541.262715]: Connecting to /dev/ttyUSB0 at 57600 baud
[ERROR] [1531232543.413050]: Creation of publisher failed: too many values to unpack

I've tried a bunch of different solutions, but nothing seems to be fixing the problem. I've tried differently structured message types as well. Is something wrong with the process I'm using to generate these? Any help would be greatly appreciated. I'd be more than happy to provide an additional information as well.

edit retag flag offensive close merge delete


Did you do this step "To add new messages to the library you have to delete (if already created) the whole ros_lib folder in your arduino libraries subpath and..." from . Just double checking!

josephcoombe gravatar image josephcoombe  ( 2018-07-10 14:16:52 -0600 )edit

Yes, but my libraries folder is not ~/sketchbook/libraries. It's ~/Arduino/libraries. Furthermore the IDE complains about the ros_lib folder, saying it's not a valid library. I can internally download a library, but the folder is not named ros_lib. So I just move my headers over. Compiles fine

nprof50 gravatar image nprof50  ( 2018-07-10 16:26:46 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-07-24 14:16:46 -0600

nprof50 gravatar image

For anyone else experiencing this issue, I fixed it by adding a delay (of about 50-250) in the main loop after "nh.spinOnce()". Without the delay, it seems the serial buffer is overwritten or messed up before ROS can interpret the values properly.

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


Asked: 2018-07-10 09:43:32 -0600

Seen: 923 times

Last updated: Jul 24 '18