From e0fcbbfec843dacaecd5bd463d2fc210c4cbfe46 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 24 Feb 2013 17:40:51 -0800 Subject: [PATCH] Updated README file to include instructions on setting permissions on the serial port --- README.md | 45 +++++++++++++++++++++--- ros_arduino_python/src/arduino_driver.py | 9 +++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e7f3dff..f73ae6d 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Official ROS Documentation -------------------------- A standard ROS-style version of this documentation can be found on the ROS wiki at: -http://www.ros.org/wiki/ros_arduino_bridge +http://www.ros.org/wiki/ros\_arduino\_bridge System Requirements @@ -54,13 +54,46 @@ sketchbook/libraries directory. Finally, it is assumed you are using version 1.0 or greater of the Arduino IDE. +Preparing your Serial Port under Linux +-------------------------------------- +Your Arduino will likely connect to your Linux computer as port /dev/ttyACM# or /dev/ttyUSB# where # is a number like 0, 1, 2, etc., depending on how many other devices are connected. The easiest way to make the determination is to unplug all other USB devices, plug in your Arduino, then run the command: -Installation ------------- + $ ls /dev/ttyACM* + +or + + $ ls /dev/ttyUSB* + +Hopefully, one of these two commands will return the result you're looking for (e.g. /dev/ttyACM0) and the other will return the error "No such file or directory". + +Next you need to make sure you have read/write access to the port. Assuming your Arduino is connected on /dev/ttyACM0, run the command: + + $ ls -l /dev/ttyACM0 + +and you should see an output similar to the following: + + crw-rw---- 1 root dialout 166, 0 2013-02-24 08:31 /dev/ttyACM0 + +Note that only root and the "dialout" group have read/write access. Therefore, you need to be a member of the dialout group. You only have to do this once and it should then work for all USB devices you plug in later on. + +To add yourself to the dialout group, run the command: + + $ sudo usermod -a -G dialout your\_user\_name + +where your\_user\_name is your Linux login name. You will likely have to log out of your X-window session then log in again, or simply reboot your machine if you want to be sure. + +When you log back in again, try the command: + + $ groups + +and you should see a list of groups you belong to including dialout. + +Installation of the ros\_arduino\_bridge Stack +---------------------------------------------- $ cd ~/ros_workspace - $ git clone https://github.com/hbrobotics/ros_arduino_bridge.git - $ cd ros_arduino_bridge + $ git clone https://github.com/hbrobotics/ros\_arduino\_bridge.git + $ cd ros\_arduino\_bridge $ rosmake The provided Arduino library is called ROSArduinoBridge and is @@ -122,6 +155,8 @@ Firmware Commands ----------------- The ROSArduinoLibrary accepts single-letter commands over the serial port for polling sensors, controlling servos, driving the robot, and reading encoders. These commands can be sent to the Arduino over any serial interface, including the Serial Monitor in the Arduino IDE. +**NOTE:** Before trying these commands, set the Serial Monitor baudrate to 57600 and the line terminator to "Carriage return" or "Both NL & CR" using the two pulldown menus on the lower right of the Serial Monitor window. + The list of commands can be found in the file commands.h. The current list includes:
diff --git a/ros_arduino_python/src/arduino_driver.py b/ros_arduino_python/src/arduino_driver.py
index c5f0e43..8eedc8c 100755
--- a/ros_arduino_python/src/arduino_driver.py
+++ b/ros_arduino_python/src/arduino_driver.py
@@ -25,7 +25,7 @@ import thread
 from math import pi as PI, degrees, radians
 import os
 import time
-import sys
+import sys, traceback
 from serial.serialutil import SerialException
 from serial import Serial
 
@@ -68,15 +68,18 @@ class Arduino:
             test = self.get_baud()
             if test != self.baudrate:
                 time.sleep(1)
-                test = self.get_baud()
+                test = self.get_baud()   
                 if test != self.baudrate:
                     raise SerialException
             print "Connected at", self.baudrate
             print "Arduino is ready."
 
         except SerialException:
+            print "Serial Exception:"
+            print sys.exc_info()
+            print "Traceback follows:"
+            traceback.print_exc(file=sys.stdout)
             print "Cannot connect to Arduino!"
-            print "Make sure you are plugged in and turned on."
             os._exit(1)
 
     def open(self):