How can I communicate with mbed at high speed(1khz)? [closed]

asked 2018-06-24 05:01:39 -0500

takijo gravatar image

updated 2018-06-24 08:34:14 -0500

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/))

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by takijo
close date 2018-07-12 09:54:49.576375

Comments

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:

  • serial usage (use a logic analyzer to see if the bus is already too busy)
  • rosserial_python efficiency (you can try rosserial_server, written in C++)

[...]

rreignier gravatar image rreignier  ( 2018-07-03 10:02:16 -0500 )edit
  • rosserial_mbed implementation
    • your MCU compute power

The result will be interesting to see what should be improved.

rreignier gravatar image rreignier  ( 2018-07-03 10:04:02 -0500 )edit

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

"[ WARN] : Socket asio error, closing socket: asio.misc:2"
takijo gravatar image takijo  ( 2018-07-11 11:03:14 -0500 )edit

and I cannot communicate.

Do you know the way to solve this error?

takijo gravatar image takijo  ( 2018-07-11 11:06:00 -0500 )edit
1

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.

rreignier gravatar image rreignier  ( 2018-07-12 02:12:56 -0500 )edit

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.

takijo gravatar image takijo  ( 2018-07-12 09:34:56 -0500 )edit