Connecting ROS to Arduino Serial Port
Hi,
I'm using ROS-Indigo on Ubuntu 14.04. I have ROS properly installed, sourced and dependencies configured properly (wiki.ros.org/indigo/Installation/Ubuntu). I have arduino installed and ROS libraries setup perfectly ( https://www.arduino.cc/en/Guide/Linux ) (wiki.ros.org/rosserial_arduino/Tutorials/Arduino%20IDE%20Setup) (wiki.ros.org/rosserial_arduino/Tutorials).
Now, my arduino stand-alone works perfectly, I tested that with a servo motor.
I did the following steps:
- Dumped the example servo motor program into arduino without any changes.
- Started roscore.
When I tried connecting ROS with arduino using this command:
rosrun rosserial_python serial_node.py /dev/ttyUSB0
I get this error:
[INFO] [WallTime: 1528924023.535404] ROS Serial Python Node
[INFO] [WallTime: 1528924023.543175] Connecting to /dev/ttyUSB0 at 9600 baud
Traceback (most recent call last):
File "/home/prasanth/catkin_ws/src/rosserial/rosserial_python/nodes/serial_node.py", line 88, in <module>
client = SerialClient(port_name, baud, fix_pyserial_for_test=fix_pyserial_for_test)
File "/home/prasanth/catkin_ws/src/rosserial/rosserial_python/src/rosserial_python/SerialClient.py", line 358, in __init__
self.port = Serial(port, baud, timeout=self.timeout, write_timeout=10)
TypeError: __init__() got an unexpected keyword argument 'write_timeout'
I tried using this alternate command:
rosrun rosserial_python serial_node.py /dev/ttyACM0
and adding different baud rates to the end like:
rosrun rosserial_python serial_node.py /dev/ttyACM0 _baud:=38400
I couldn't find any help for this problem online. Without crossing this step, I cannot progress to
rostopic pub servo std_msgs/UInt16 <angle>
I'm following this tutorial for the steps: http://wiki.ros.org/rosserial_arduino...
Kindly help, Prasanth.S.S
Could you show the setup part of your code, I had a similar issue due to a bad configuration of the serial communication(s). Also you can try
rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0
to launch the node.Hi Ric,
Assuming you mean the setup of the arduino code, I'm using the exact sample code that is in the library:
void setup(){ pinMode(13, OUTPUT);
nh.initNode(); nh.subscribe(sub);
servo.attach(9); //attach it to pin 9 }
Try adding
This should open the serial connection with the Arduino.
Hi Ric, I tried that, it didn't make any difference, so just for debugging sakes, I tried commenting out the line that was mentioned in the error above and now I get this: self.port.flushInput() AttributeError: 'SerialClient' object has no attribute 'port'; Does any of this mean anything to you?
Regarding what you've done, it's normal. Line 358 of SerialClient.py goes:
If you comment it, the class SerialClient has no more
port
data defined, hence the error.I'm still looking at your issue.
This same line in my SerialClient.py is:
self.port = Serial(port, baud, timeout=self.timeout*0.5)
Be aware that I'm using lunar and 16.04, but that might be related to your issue.
try changing write_timeout to writeTimeout. I am not sure about this but you can try. From what I read its different for py2.7 and py3.0. Try it and let me know.
I shall try that asap and get back to you, thanks.