ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Rosserial deserialization error when receiving Serial2

asked 2021-10-31 17:17:06 -0600

Wes G gravatar image

I'm very close to getting my robot project working the way I had hope. A summary of the structure is that I have a Raspberry Pi 2 connected to 2 Arduino MEGAs: 1 for motor control and sensor connectivity and another for interfacing with an NMEA0183 marine sensor. I have been able to receive serial data from the sensor separately but when I connect to ROS and rosserial, I get the following error:

Traceback (most recent call last): File "/opt/ros/melodic/lib/rosserial_python/", line 89, in <module>

File "/opt/ros/melodic/lib/python2.7/dist-packages/rosserial_python/", line 540, in run self.callbackstopic_id

File "/opt/ros/melodic/lib/python2.7/dist-packages/rosserial_python/", line 111, in handlePacket m.deserialize(data)

File "/home/ubuntu/ros_ws/devel/lib/python2.7/dist-packages/floatbot_msgs/msg/", line 110, in deserialize genpy.message.DeserializationError: unpack requires a string argument of length 4

[depth_serial_node-3] process has died [pid 4523, exit code 1, cmd /opt/ros/melodic/lib/rosserial_python/ __name:=depth_serial_node __log:=/home/ubuntu/.ros/log/2770e2da-3a91-11ec-9518-0f4138ab90b7/depth_serial_node-3.log]. log file: /home/ubuntu/.ros/log/2770e2da-3a91-11ec-9518-0f4138ab90b7/depth_serial_node-3*.log

Here is the loop() function of my Arduino code:

void loop() {

    if (isConnected && !nh.connected()) {
    } else if (nh.connected()) {

    if (Serial2.available()) {
        parser <<;
   isConnected = nh.connected();

When I remove the parser section (that is read from Serial2), I don't get a crash but of course that means my data is no longer read. The Float64Stamped is a custom message type.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-10-31 18:37:27 -0600

Wes G gravatar image

As usual after spending time working on this and writing a question, I was able to find the right answer and get it working.

In the interest of community knowledge, the problem was that my custom message type used 64 bit data types while the Arduino does not support that. The Raspi decoder was looking for 64 bits but only receiving 32.

I updated the message type to use 32 bit types and the error went away and I was able to load the data I wanted.

edit flag offensive delete link more


Glad you found the solution

osilva gravatar image osilva  ( 2021-10-31 19:28:06 -0600 )edit

Question Tools



Asked: 2021-10-31 17:17:06 -0600

Seen: 149 times

Last updated: Oct 31 '21