Rosserial_python died

Hi

I am starting rosserial with rauslaunch and the following configuration (roscore is running separatly):

<launch>
  <node pkg="rosserial_python" type="serial_node.py" name="robby_node">
    <param name="port" value="/dev/serial0" />
    <param name="baud" value="500000" />
  </node>
</launch>

My Core2-ROS (RPi) is running with this setup:

nh.getHardware()->initWithDevice(&RPi);
nh.initNode();

and publishing a joint_state message and subscribing a cmd_vel message.
When I subscribe the joint_state message with rostopic echo joint_state, the process dies after a short while (seuquence counter between 80 and 2000) with this output:

Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/rosserial_python/serial_node.py", line 89, in <module>
    client.run()
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 504, in run
    self.callbacks[topic_id](msg)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 107, in handlePacket
    m.deserialize(data)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/sensor_msgs/msg/_JointState.py", line 199, in deserialize
    raise genpy.DeserializationError(e) #most likely buffer underfill
genpy.message.DeserializationError: unpack requires a string argument of length 5624
[robby_node-1] process has died [pid 3825, exit code 1, cmd /opt/ros/kinetic/lib/rosserial_python/serial_node.py __name:=robby_node __log:=/home/husarion/.ros/log/972ecebc-3454-11e8-932b-b827eb5b9192/robby_node-1.log].
log file: /home/husarion/.ros/log/972ecebc-3454-11e8-932b-b827eb5b9192/robby_node-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr

the mentioned log has this contents:

[rospy.client][INFO] 2018-03-31 14:21:09,648: init_node, name[/robby_node], pid[3825]
[xmlrpc][INFO] 2018-03-31 14:21:09,650: XML-RPC server binding to 0.0.0.0:0
[xmlrpc][INFO] 2018-03-31 14:21:09,653: Started XML-RPC server [http://core2-ros:46525/]
[rospy.init][INFO] 2018-03-31 14:21:09,653: ROS Slave URI: [http://core2-ros:46525/]
[rospy.impl.masterslave][INFO] 2018-03-31 14:21:09,654: _ready: http://core2-ros:46525/
[rospy.registration][INFO] 2018-03-31 14:21:09,660: Registering with master node http://localhost:11311
[xmlrpc][INFO] 2018-03-31 14:21:09,660: xml rpc node: starting XML-RPC server
[rospy.init][INFO] 2018-03-31 14:21:09,755: registered with master
[rospy.rosout][INFO] 2018-03-31 14:21:09,757: initializing /rosout core topic
[rospy.rosout][INFO] 2018-03-31 14:21:09,772: connected to core topic /rosout
[rospy.simtime][INFO] 2018-03-31 14:21:09,782: /use_sim_time is not set, will not subscribe to simulated time [/clock] topic
[rosout][INFO] 2018-03-31 14:21:09,804: ROS Serial Python Node
[rosout][INFO] 2018-03-31 14:21:09,848: Connecting to /dev/serial0 at 500000 baud
[rospy.internal][INFO] 2018-03-31 14:21:10,057: topic[/rosout] adding connection to [/rosout], count 0
[rosout][INFO] 2018-03-31 14:21:12,057: Note: publish buffer size is 512 bytes
[rosout][INFO] 2018-03-31 14:21:12,060: Setup publisher on joint_states [sensor_msgs/JointState]
[rosout][INFO] 2018-03-31 14:21:12,084: Note: subscribe buffer size is 512 bytes
[rosout][INFO] 2018-03-31 14:21:12,087: Setup subscriber on cmd_vel [geometry_msgs/Twist]
[rosout][INFO] 2018-03-31 14:21:51,420: wrong checksum for topic id and msg
[rospy.internal][INFO] 2018-03-31 14:21:53,921: topic[/joint_states] adding connection to [/rostopic_3847_1522498913455], count 0
[rosout][INFO] 2018-03-31 14:21:56,070: wrong checksum for topic id and msg
[rosout][INFO] 2018-03-31 14:21:58,578: wrong checksum for topic id and msg
[rosout][INFO] 2018-03-31 14:22:01,021: wrong checksum for topic id and msg
[rospy.core][INFO] 2018-03-31 14:22:31,389: signal_shutdown [atexit]
[rospy.internal][INFO] 2018-03-31 14:22:31,435: topic[/joint_states] removing connection to /rostopic_3847_1522498913455
[rospy.internal][INFO] 2018-03-31 14:22:31,439: topic[/rosout] removing connection to /rosout
[rospy.impl.masterslave][INFO] 2018-03-31 14:22:31,441: atexit

I have no idea why this happens. May be the baudrate is too high!?
How can I set the baudrate between Core2 and RPi?

Any help is appreciated.

Michael

Does nobody else have the same problem? Or a solution? :wink:

Hi Michael.

I apologize for having to wait for the answer for so long.

I think that you problem is caused by a missing pkg, precisely pyserial. Try to install it using pip:

sudo apt-get install python-pip

You should also upgrade it:

pip install --upgrade pip

and finally install pyserial

pip install pyserial

That should fix your problem :slight_smile:

Regards,
Hubert.

Hi Hubert

thanks for your suggestion. But unfortunately after

pip install pyserial

I get the message:

Requirement already satisfied: pyserial in /usr/lib/python2.7/dist-packages

and after a few seconds the effect is the same as descibed above.
I found some answers about to short messagel length and https://github.com/ros-drivers/rosserial/issues/214 which suggests to check whether ros_serial and ros_serial of the ros_lib are the same.
So the question is with which Version you compile ros_lib for Core2?
Michael

Hi Michael,

If you’re getting the message:

Requirement already satisfied: pyserial in /usr/lib/python2.7/dist-packages

Everything seems to be ok. If you’re talking about [this] (http://wiki.ros.org/roslib) ros_lib for CORE2, we do not use it at all. If you meant some other library please let me know which one.

The default name of CORE2 device connected by rpi connector is /dev/ttyCORE2 so you can try this code to launch it on your CORE2-ROS:

<launch>
  <node pkg="rosserial_python" type="serial_node.py" name="robby_node">
    <param name="port" value="/dev/ttyCORE2" />
    <param name="baud" value="500000" />
  </node>
</launch>

Regards,
Hubert.

Hi Hubert

thanks for your suggestion, but unfortunately it does not work;

PARAMETERS

  • /robby_node/baud: 500000
  • /robby_node/motorLeftFactor: 300
  • /robby_node/motorRightFactor: 300
  • /robby_node/port: /dev/ttyCORE2
  • /rosdistro: kinetic
  • /rosversion: 1.12.13

NODES
/
robby_node (rosserial_python/serial_node.py)

ROS_MASTER_URI=http://localhost:11311

process[robby_node-1]: started with pid [5461]
[ERROR] [1523906098.613524]: Error opening serial: [Errno 2] could not open port /dev/ttyCORE2: [Errno 2] >No such file or directory: ‘/dev/ttyCORE2’
[robby_node-1] process has finished cleanly
log file: /home/husarion/.ros/log/5d22e58e-3f4c-11e8-8b36-b827eb5b9192/robby_node-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor…
… shutting down processing monitor complete
done

My SBC is a RPi.

Michael

Hi Michael.

It looks like you don’t have installed pkg for communication with CORE2. You can check it by typing:

apt-cache policy husarion-sdk

Normally the result should look like this

husarion-sdk:
  Installed: 2017.11.24.1
  Candidate: 2017.11.24.1
  Version table:
 *** 2017.11.24.1 500
        500 https://files.husarion.com/repo xenial/main armhf Packages
        100 /var/lib/dpkg/status
     1.4.3 500
        500 https://files.husarion.com/repo xenial/main armhf Packages

If I’m right you will get:

husarion-sdk:
  Installed: (none)
  Candidate: 2017.11.24.1
  Version table:
     2017.11.24.1 500
        500 https://files.husarion.com/repo xenial/main armhf Packages
     1.4.3 500
        500 https://files.husarion.com/repo xenial/main armhf Packages

Install it typing:

sudo apt-get install husarion-sdk

Now try to run the same launch file as earlier. Let me know if this has fixed your problem :slight_smile:

Regards,
Hubert.

Hi Hubert

unfortunately I get the first output. So it seems that the Husarion SDK is installed.
The install results in “nothing to install”.

Do you have any other ideas :wink: ?

Michael

Hi Michael.

Show me please results of:

ls /dev/tty* -l

Maybe you don’t have ttyCORE2 in your device list.

Yes, I have another way but it’s quite brutal way. You can download new image from our website and try one more time install rosserial_python and pyserial. For now I don’t have any others idea. I will have to investigate it a little bit more.

Regards,
Hubert.

Hi Hubert

there are tty, than tty0 to tty63, ttyAMA0, ttyS0, ttyprintk, but no ttyCORE2.
Is there a way to get ttyCORE2 in my device list?
Downloading and flashing is also an option, but than I have to think about saving my changes and configurations.

But: As I wrote before, the communication in general works. It just dies after a few seconds …

Michael

Hi Michael.

So now we know what the problem is.
As you mentioned, it might have been some changes in configuration that could have caused RPi not seeing CORE2 properly. As we don’t know what exactly caused the issue, please try to complete the confirguration with a fresh image from here. If you don’t want to lose your data, you can use another SD card to check if this works.

Regards,
Hubert.

Hi Hubert
I flashed a new SD card with this image. After that the ttyCORE2 device was available.
Did connect an ethernet cable and than a sudo apt-get update and sudo apt-get dist-upgrade which did a lot of updates.
After that ttyCORE2 was available.
Did “systemctl disable husarion-shield” like mentioned here because I want to work without cloud. But when I try to start “roscore” I get a message something like “Could not connect to master” (I am not in front of my Core2-ROS, so the message is not exact).
What is going wrong now? The Core2 is waiting for connection (bland and yellow leds are blinking).

Michael

Hi Michael.

Now we are sure that lack of the port was caused by some software changes that you implemented.

Message you mentioned probably say:

WARNING: ROS_MASTER_URI [http://master:11311] host is not set to this machine

Normaly it means that your CORE2-ROS is in Husarnet network and you have chosen another device as ROS master, but in this case it’s probably because CORE2-ROS is in the configuration mode. You have to connect it to Husarion Cloud just once with the new SD card. After that you can disable husarion-shield and remove device from Husarion Cloud.

Regards,
Hubert.

Hi Hubert
I made some additional findings.
It seems that /dev/ttyCORE2 is only available in the cloud mode. If I disable the husarion-shield (systemctl disable husarion-shield) ttyCORE2 disappears after a reboot. After enabling it again (systemctl enable husarion-shield)(and a reboot) it appears again.
So it seems ttyCORE2 is only available when I am connected to the cloud. But this is not what I want. If I am working offline (without cloud) I have to obviously use /dev/serial0.

Unfortunately this leads again to my original question:
Why is the communication between Core2 and RPi very instable and what can I do against it?
In the current state the Core2-ROS is not usable!

Michael

Hi Michael

It seems that you have everything configured correctly.
Could you post here your code for CORE2?
Do you have any other nodes or applications running on RPi while the problem occurs?

I could set up the same configuration as yours and try to figure out what causes problem.

Regards,
Łukasz

Hi Łukasz

I tried several progams on Core2. Among others the example from ROS tutorial 3. The effect is always the same. The program on Core2 runs but the ros_serial stops working after a while.
On RPi the desktop is running (remote connection via RDP). Also a Teleop node, of course roscore. I think the problem occurs when I start a "rostopic echo " command. So maybe the problem is in the communication between Core2 and RPi. As mentioned before I am working without cloud.

Michael

Hi Michael,

Code for CORE2 needs a little modifications to work without cloud.
Beginning with code from tutorial 3, I commented out line 2:
//#include "hCloudClient.h"
and lines 88, 89 (begginig of hMain() function):
//platform.begin(&RPi);
//nh.getHardware()->initWithDevice(&platform.LocalSerial);
Then after line 89, I added:
nh.getHardware()->initWithDevice(&RPi);

Without these modifications errors with connection setup will occur.

Then I started serial bridge with command:
/opt/husarion/tools/rpi-linux/ros-core2-client /dev/ttyS1
You may need to use:
/opt/husarion/tools/rpi-linux/ros-core2-client /dev/serial0
The difference is because you are working on Raspberry and I was testing on TinkerBoard.

During my tests I had husarion-shield disabled and uploaded program on CORE2 by VSCode and USB cable.
I was working on fresh image with all updates installed (sudo apt update; sudo apt upgrade). The only modifications are mentioned above.

Regards,
Łukasz

Hi Łukasz
thanks for your answer. I did these changes regarding to a further answer from your collegue in the forum.
The remaining difference is that I started roslaunch with the following node:

 <node pkg="rosserial_python" type="serial_node.py" name="robby_node">
    <param name="port" value="/dev/serial0" />
    <param name="baud" value="500000" />
 </node>

instead of ros-core2-client. I will try this later.
Can I use ros-core2-client also with roslaunch? If yes, how?

Michael

Hi Michael,

You can use ros-core2-client with roslaunch, but it requires a bit of workaround.
Create a bash script containing:

#!/bin/bash
/opt/husarion/tools/rpi-linux/ros-core2-client /dev/ttyS1

Save it as bridge.sh in a new package (eg. serial_bridge) in folder scripts.
Add execution permissions to script:
chmod a+x bridge.sh

Your launch file should be like:

<launch>
        <node pkg="serial_bridge" type="bridge.sh" name="bridge" output="screen"/>
</launch>

Łukasz

This works in general, thanks. But unfortunatly it does not solve my problem. I get the following error messages (after a lot of “wrong checksum for topic id and msg”, “wrong checksum for msg length, length 56” messages.

[INFO] [1525967645.162604]: Protocol version of client is unrecognized, expected Rev 1 (rosserial 0.5+)
[INFO] [1525967645.525580]: wrong checksum for topic id and msg
[ERROR] [1525967645.529966]: Mismatched protocol version in packet: lost sync or rosserial_python is from different ros release than the rosserial client
[INFO] [1525967645.534823]: Protocol version of client is unrecognized, expected Rev 1 (rosserial 0.5+)
Traceback (most recent call last):
  File "/opt/husarion/tools/rpi-linux/ros-core2-client", line 89, in <module>
    client.run()
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 504, in run
    self.callbacks[topic_id](msg)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 107, in handlePacket
    m.deserialize(data)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/geometry_msgs/msg/_PoseStamped.py", line 142, in deserialize
    raise genpy.DeserializationError(e) #most likely buffer underfill
genpy.message.DeserializationError: unpack requires a string argument of length 56

I show the pose message with rostopic echo pose in another terminal window.

After increasing the delay to 50 milliseconds it seems to work better which means it does not stop after ~1000 msgs but after ~10000.

Michael