Rosserial_arduino use on an arduino uno with IMU (I2C/Wire library)
Hey! I have been testing the rosserial_arduino ( http://wiki.ros.org/rosserial ) in order to run a ROS node on arduino. I tested some of the examples and thought I had the hang of it. (In case it's useful: I'm running Ubuntu 14.04 on a macbook pro).
However I'm unable to get the arduino node to publish information from the IMU connected to the arduino UNO. The IMU is the MPU9150 and I'm using an implementation of the I2Cdev library found here: https://github.com/richards-tech/MPU9... (I have tried a different library, in order to understand if the problem was related to this specific library, but ended up with the same problem). If I only use the MPU9150 library, that is, if I don't try to use resserial, I'm able to get the IMU data on the arduino and print it on the serial monitor. However, if I try to use rosserial I'm unable to make the node work.
When I run the serial_node from rosserial I get the following output:
nmirod@nmirod:/$ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM1 _baud:=57600
[INFO] [WallTime: 1422735802.267338] ROS Serial Python Node
[INFO] [WallTime: 1422735802.270908] Connecting to /dev/ttyACM1 at 57600 baud
/home/nmirod/catkin_ws/src/rosserial/rosserial_python/src/rosserial_python/SerialClient.py:336: 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: 1422735819.375623] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
Notice that the SyntaxWarning appears even in the tutorial examples. After some testing it seems that this problem is related to the use of the Wire library. Commenting the functions that perform the initialization and reading of the IMU, I' able to get a msg on the desired topic (although constant). However, if I try to run the node as it is, I get the "Unable to sync with device" error.
Is this problem associated with the "Wire library"/I2C communication? Can you help me out?
EDIT: Is it possible to use Serial.print()'s in combination with rosserial? When I wrote this sketch I had the caution to remove all debug prints, to be sure it wouldn't scramble the communication with ros. However, when I was out of options I decided to try to use some Serial.print()'s for debugging and it seems that using Serial.begin(57600) solved the problem (same baud rate as the node).
Althought the problem seems to be solved I still would like to understand what's going on so that if something similar happens down the road I know what to do.
EDIT2: Here is the code:
#include "ros.h"
#include "rospy_tutorials/Floats.h"
#include "freeram.h"
#include "mpu.h"
#include "I2Cdev.h"
ros::NodeHandle nh;
float aux[] = {9, 9, 9, 9 ...
I've used the i2c library without any isseus. Try publishing slower on the arduino.
Could you check my edit? I still don't understand what's happening.
Can you post your code? Did you try slowing down the publishing rate?
I have added the code, but note that it's the code before adding the subscriber. By slowing down the publishing rate are you talking about the baudrate used on the node? (thanks for helping!)
I meant adding
delay(15);
or publishing at a certain rate. You maybe overfilling the serial buffer.At the time I tried using different delays however it didn't help. With the addition of Serial.begin() it started working, althought I don't know why that would help. However when I try to add a subscriber to the node, the IMU stops responding (I think he fails to initialize).
Try initializing the node before you start the i2c comm. Also, try manually setting the baud
nh.getHardware()->setBaud(BAUD);
before the node initializes.I tried your suggestions and still got the same problem. I made an edit with some new information and the code I'm using right now.