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

Issues with Arduino: Wrong checksum, Mismatched protocol version

asked 2019-12-25 23:26:40 -0500

parzival gravatar image

I am trying to run base controller on an arduino uno, which will run the motors by subscribing to topics for left and right motor speeds which come through the Twist messages, and also publishes encoder values to topics /lwheel and /rwheel. When I run the arduino rosserial by connecting it to my PC, there is no problem and everything works fine. However, when I connect the uno to my raspberry pi, which is connected to my PC, problems occur. I notice the following messages and errors on my terminal running the command rosrun rosserial_python serial_node.py /dev/ttyACM0 :

[INFO] [1577335551.127150]: Connecting to /dev/ttyACM0 at 57600 baud
[INFO] [1577335553.249219]: Requesting topics...
[INFO] [1577335553.290434]: Note: publish buffer size is 512 bytes
[INFO] [1577335553.298687]: Setup publisher on lwheel [std_msgs/Float32]
[INFO] [1577335553.321495]: Setup publisher on rwheel [std_msgs/Float32]
[INFO] [1577335553.348951]: Note: subscribe buffer size is 512 bytes
[INFO] [1577335553.357481]: Setup subscriber on left_wheel_speed [std_msgs/Float32]
[INFO] [1577335553.386113]: Setup subscriber on right_wheel_speed [std_msgs/Float32]
[INFO] [1577335556.177063]: wrong checksum for topic id and msg
[INFO] [1577335559.040959]: wrong checksum for topic id and msg
[ERROR] [1577335561.888282]: Mismatched protocol version in packet ('\x00'): lost sync or rosserial_python is from different ros release than the rosserial client
[INFO] [1577335561.896526]: Protocol version of client is unrecognized, expected Rev 1 (rosserial 0.5+)
[INFO] [1577335564.716741]: wrong checksum for topic id and msg
[ERROR] [1577335579.781605]: Lost sync with device, restarting...
[INFO] [1577335579.790889]: Requesting topics...
[INFO] [1577335579.826395]: Setup publisher on lwheel [std_msgs/Float32]
[INFO] [1577335579.839117]: Setup publisher on rwheel [std_msgs/Float32]
[INFO] [1577335582.842464]: wrong checksum for msg length, length 4
[INFO] [1577335582.850964]: chk is 0

These messages are repeated over and over. I also notice weird behavior in the robot itself. There is random latency between my key press and actual movement, and the longer I press the key, the longer it continues that movement "after" I release the key.

I thought it might be an issue with the uno's dynamic memory size. So I shifted to arduino mega. It uses 28% of its dynamic memory, but I face the same issue with Arduino Mega. I don't think its an issue with buffer as well, because it works well when connected directly to the PC. I am running Ubuntu 16.04 and ROS Kinetic on PC, and Ubuntu Mate 18.04 and ROS Melodic on Raspberry Pi Model 3 B. Can that be the cause? If yes, then why isn't that causing problems when I have no publishers? (The uno works perfectly well when the code is just subscribing to speed topics and running motors, even when connected to pi).

Arduino Code:

#include <ros.h>
#include <std_msgs/Float32.h>
#include "Arduino.h"

ros::NodeHandle nh;
// Left encoder

int Left_Encoder_PinA = 2;
int Left_Encoder_PinB = 9;

volatile long Left_Encoder_Ticks = 0;

//Variable to read current state of left encoder pin
volatile bool LeftEncoderBSet;

//Right Encoder

int Right_Encoder_PinA = 3;
int Right_Encoder_PinB = 10;
volatile ...
(more)
edit retag flag offensive close merge delete

Comments

I'm not an arduino expert, but you appear to be using Serialandrosserial at the same time, with the same serial port.

That is not supported.

Remove the Serial.begin() and Serial.println(..) calls and try again.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-26 07:28:33 -0500 )edit

Hi @gvdhoorn that wasn't a problem when just running motors. However, I'll try that

parzival gravatar image parzival  ( 2019-12-27 07:31:25 -0500 )edit

@gvdhoorn I tried your suggestion, but still the same problem.

parzival gravatar image parzival  ( 2019-12-27 07:54:26 -0500 )edit

Regardless of whether it solves your problem, you cannot use Serial together with rosserial. Unless you've changed the serial hw rosserial should use (on the Arduino side, not the ROS side).

gvdhoorn gravatar image gvdhoorn  ( 2019-12-27 08:40:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-12-27 15:17:19 -0500

I would try with a larger delay in the main loop - try 100 milliseconds rather than 10 Microseconds and see if that helps

edit flag offensive delete link more

Comments

Thanks @nickw! I changed delay in loop to 10 ms and it works perfectly!

parzival gravatar image parzival  ( 2019-12-28 08:59:39 -0500 )edit

Great - please click on the tick to show that the answer has solved the problem

nickw gravatar image nickw  ( 2019-12-28 09:41:52 -0500 )edit

Sure, can you just help me know why did the delay cause problem in distributed system and not when running arduino directly through pc?

parzival gravatar image parzival  ( 2019-12-28 10:16:43 -0500 )edit
2

Sure.

Sending the message with a delay of 10 microseconds between messages means you were sending very high number of messages/second, roughly a thousand times more than with a 10 millisecond delay (the time spent running other code will have a more significant effect on the very short delay rate, so it would not be exactly a thousand times). Your pc will most likely be a much faster computer than the pi, which means it would be able to process the data that has arrived faster than the raspberry pi could. So it was able to process each message before the next one arrived. The less powerful pi was not. If it is not processing them faster than they arrive then messages accumulate in the buffer at the receiving end, and this very quickly fills up, causing loss of data and errors. In addition to the slower speed the ...(more)

nickw gravatar image nickw  ( 2019-12-28 10:36:55 -0500 )edit
2

As the microcontroller doesn't have an operating system it can perform simple tasks at a much higher and more reliable rate than a computer with an operating system can as it is not constantly switching tasks in the way the operating system is, so it is very easy to accidentally send data at rates that will overwhelm the computer that is receiving them - I have often seen computers brought to a standstill because serial data is being sent to them by a microcontroller with a sensor reading, serial print and no delay in the main loop

nickw gravatar image nickw  ( 2019-12-28 10:39:15 -0500 )edit

That's really helpful. Thanks a lot!

parzival gravatar image parzival  ( 2019-12-29 06:07:39 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-12-25 23:26:40 -0500

Seen: 1,812 times

Last updated: Dec 25 '19