[SOLVED] Serial Port read returned short error with arduino uno via bluetootle with rosserial
Hi all!
I'm working with arduino car under directly ROS topic command. I have a arduino uno board with Arduino Sensor Shield v5.0 installed. I'm running the basic publish and subscribe tutorial from rosserial:
http://wiki.ros.org/rosserial_arduino...
http://wiki.ros.org/rosserial_arduino...
When using USB shown as dev/ttyACM0, things are doing well.
Then, I'm trying to connect with HC-05 bluetooth module. First I connect it with command:
sudo rfcomm connect /dev/rfcomm0 00:06:71:00:3E:87 1
And the
Then launching rosserial as before with additional argument :
rosrun rosserial_python serial_node.py _port:=/dev/rfcomm0 _baud:=9600
With the tutorial code on the car:
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
char hello[13] = "hello world!";
void setup()
{
nh.getHardware()->setBaud(9600);
nh.initNode();
nh.advertise(chatter);
}
void loop()
{
str_msg.data = hello;
chatter.publish( &str_msg );
nh.spinOnce();
delay(1000);
}
The terminal become a waterfall of running warning:
[INFO] [WallTime: 1410329846.797489] ROS Serial Python Node
[INFO] [WallTime: 1410329846.814548] Connecting to /dev/rfcomm0 at 9600 baud
[WARN] [WallTime: 1410329849.792440] Serial Port read returned short (expected 72 bytes, received 8 instead).
[WARN] [WallTime: 1410329849.793548] Serial Port read failure:
[INFO] [WallTime: 1410329849.794408] Packet Failed : Failed to read msg data
[INFO] [WallTime: 1410329849.795036] msg len is 8
[WARN] [WallTime: 1410329850.814268] Serial Port read returned short (expected 16 bytes, received 13 instead).
[WARN] [WallTime: 1410329850.815325] Serial Port read failure:
[INFO] [WallTime: 1410329850.816327] Packet Failed : Failed to read msg data
[INFO] [WallTime: 1410329850.816984] msg len is 8
For most of the time its complaining about expected 72 bytes.
And thetopic,
rostopic info chatter
will return result (hello world!) quite randomly (it correctly shows with 1 Hz when using USB)
I've done another experiment on subscribe function. Arduino Car subscribe to std_msgs/Empty and topic is published by
rostopic pub toggle_led std_msgs/Empty --rate=1
The result is similar: some of the command can arrived (by moving the sonar servo) but quite randomly, and sometimes move more then 1 time in 1 second (published in 1Hz).
I've tried to read the source but still couldn't locate the problem.
Any help or suggestion are very welcome, thanks.
edit: It truns out it is the problem of baudrate of my bluetooth module! The chip (YFRobot) is a china made cheap one and not is a real HC-06 or any official supported chip. The common method of setting baudrate in a console just won't work. There is something like a single post in some unkown chinese forum that provides the datasheet (Luckily I can read simplified Chinese ^^). After a weird setup process, it's fine now, except that the module just won't work beyond exceed certain rate (57600 I think).
ahendrix hello. I've never set the baud rate other then nh.getHardware()->setBaud() in bluetooth module. But if the baud rate is wrong, shouldn't it be completely unable to communicate? Using Arduino IDE with it's serial monitor and function like Serial.begin/Serial.write have no problem at all.
Most bluetooth modules have a UART buad rate that cannot be set through normal software. They usually have some sort of AT command set for modifying the baud rate.
Since the arduino serial console and Serial.write work over bluetooth, that means that the baud rate setting you're using matches the bluetooth module's setting, and it means that the problem is elsewhere.
Mmmmm ahendrix thank you. hope this can be fix. I'll keep trying.
@EwingKang I suggest you re-post the solution as an answer and select it as the right-answer so that others can tell this question has an answer.
@130s OK, I see. I'm not sure whether if it is okay to do so here at ros answers. Some of the Q&A site forbid self-answering the question. Anyway, thanks.
edit: I see the line " you are encourage to answer you own...." when I editing my answer ^_^