Yesterday I’ve had to learn something the hard way. Please have a look at the following code of the rosserial “hello world” arduino example:
/* * rosserial Publisher Example * Prints "hello world!" */ #include <ros.h> #include <std_msgs/String.h> ros::NodeHandle nh; std_msgs::String str_msg; ros::Publisher chatter("chatter", &str_msg); char hello[13] = "hello world!"; void setup() { nh.initNode(); nh.advertise(chatter); } void loop() { str_msg.data = hello; chatter.publish( &str_msg ); nh.spinOnce(); delay(1000); }
Nothing special, right? So compiling it – uploading everything on the arduino works like a charm.
But starting it rosrun rosserial_python serial_node.py /dev/ttyACM0 crashes with:
rosrun rosserial_python serial_node.py /dev/ttyACM0 [INFO] [WallTime: 1400737593.278250] ROS Serial Python Node [INFO] [WallTime: 1400737595.610358] Connecting to /dev/ttyACM0 at 57600 baud /home/yourUser/catkin_ws/src/rosserial/rosserial_python/src/rosserial_python/SerialClient.py:317: SyntaxWarning: The publisher should be created with an explicit keyword argument 'queue_size'. Please see http://wiki.ros.org/rospy/Overview/Publishers%20and%20Subscribers for more information. self.pub_diagnostics = rospy.Publisher('/diagnostics', diagnostic_msgs.msg.DiagnosticArray) [ERROR] [WallTime: 1400737595.826375] Error opening serial: could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0'
which can be easily explained by normal users missing permission to access the /dev/ttyACM0. So I advice running it as root, which leads you to customize roots .bashrc including the source /home/yourUser/yourWorkspacePath/devel/setup.bash and the environment variables like ROS_HOSTNAME and ROS_MASTER.
So after that, running it again with root permissions, you’ll get another error message:
[INFO] [WallTime: 1400737809.741920] ROS Serial Python Node [INFO] [WallTime: 1400737810.415142] Connecting to /dev/ttyACM0 at 57600 baud /home/yourUser/catkin_ws/src/rosserial/rosserial_python/src/rosserial_python/SerialClient.py:317: SyntaxWarning: The publisher should be created with an explicit keyword argument 'queue_size'. Please see http://wiki.ros.org/rospy/Overview/Publishers%20and%20Subscribers for more information. self.pub_diagnostics = rospy.Publisher('/diagnostics', diagnostic_msgs.msg.DiagnosticArray) [ERROR] [WallTime: 1400737827.716961] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
So – rosserial tries to connect to your /dev/ttyACM0 using 57600 baud and fails. The error message is kind of misleading – of course there is some syncing issue, and it has nothing to do with your ROS version… …but with your arduino!
Since the arduino micro / leonardo uses USB for and its build in serial-controller both for programming and communicating, rosserial needs the information to access the device not in the for arduino usual serial way but with USB. So simply adding
#define USE_USBCON
before the rest of the code, will tell ROS to do so.