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/Tutorials/Hello%20World
http://wiki.ros.org/rosserial_arduino/Tutorials/Blink
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
#include
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).
↧