How can I communicate with mbed at high speed(1khz)? [closed]
Hi,
I want to commicate mbed LPC1768 mbed at high speed(1khz) by rosserial.
So,I test the simple program to measure communication speed.
This is the mbed program
/*
* rosserial Publisher Example
* Prints "hello world!"
*/
#include"mbed.h"
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
Ticker flipper;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
char hello[13] = "hello world!";
void flip(){
str_msg.data = hello;
chatter.publish( &str_msg );
nh.spinOnce();
}
int main() {
nh.getHardware()->setBaud(921600);
nh.initNode();
nh.advertise(chatter);
flipper.attach_us(&flip,2000);//500hz
while (1) {
}
}
I use rosserial_python.
$ rosrun rosserial_python serial_node.py /dev/ttyACM0 _baud:=921600
I use rostopic hz to measure the communication speed.
$ rostopic hz chatter
subscribed to [/chatter]
average rate: 500.280
min: 0.001s max: 0.004s std dev: 0.00055s window: 499
average rate: 500.137
min: 0.001s max: 0.004s std dev: 0.00054s window: 999
average rate: 499.996
min: 0.001s max: 0.006s std dev: 0.00056s window: 1500
I can communicate at 500hz.But, I change
flipper.attach_us(&flip,1000);//1khz
$ rosrun rosserial_python serial_node.py /dev/ttyACM0 _baud:=921600
[INFO] [1529843960.239399]: ROS Serial Python Node
[INFO] [1529843960.246924]: Connecting to /dev/ttyACM0 at 921600 baud
[INFO] [1529843962.352072]: Requesting topics...
[INFO] [1529843962.363132]: Note: publish buffer size is 512 bytes
[INFO] [1529843962.364404]: Setup publisher on chatter [std_msgs/String]
[INFO] [1529843963.201945]: wrong checksum for topic id and msg
[INFO] [1529843963.836671]: wrong checksum for topic id and msg
[INFO] [1529843964.422006]: wrong checksum for topic id and msg
I get the message "wrong checksum for topic id and msg" and
$ rostopic hz chatter
subscribed to [/chatter]
average rate: 685.848
min: 0.001s max: 0.004s std dev: 0.00022s window: 682
average rate: 653.469
min: 0.001s max: 0.004s std dev: 0.00022s window: 1304
average rate: 643.762
min: 0.001s max: 0.004s std dev: 0.00022s window: 1930
I can't communicate at 1khz.
So,can I communicate with mbed at high speed(1khz)?
(I use Ubuntu16.04LTS,kinetic,ros_lib?kinetic(https://os.mbed.com/users/garyservin/code/ros_lib_kinetic/))
rosserial was not made to handle very high frequency topics but you can try to investigate what is the bottleneck. I think it can be:
[...]
The result will be interesting to see what should be improved.
Thank you for your advises.
I can communicate at 750hz by using indigo version rosserial_python(more simple code than kinetic). So, I think bottleneck is python efficiency.
I try rosserial_server ,but I get the message
and I cannot communicate.
Do you know the way to solve this error?
Argh, this error is known but unresolved: https://github.com/ros-drivers/rosser... Usually, I reboot the computer and do not use rosserial_python before to avoid any conflict in the serial port communication.
I reboot the PC,I can use rosserial_server.And I can communicate at 1000hz(1khz)!(I need to change "ros_spin_interval" from milliseconds(10) to milliseconds(1) in "session.h") Thank you for your help.