rosserial lost sync error
Hi,
I'm getting this error "Lost sync with device, restarting..." after a few seconds starting rosserial. I'm getting it with this sketch:
#include <ros.h>
#include <geometry_msgs/Vector3.h>
ros::NodeHandle_<ArduinoHardware, 1, 1, 125, 125> nh;
geometry_msgs::Vector3 pub_msg;
ros::Publisher pub("/car/power", &pub_msg);
static int potenza_linear = 0;
static int potenza_angular = 0;
// True if the car is rotating, false if translating
bool rotating = false;
float mapf(const float& x, const float& in_min, const float& in_max, const float& out_min, const float& out_max)
{ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
/* =========== */
/* MPU6050 IMU */
/* =========== */
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
//#include "MPU6050.h" // not necessary if using MotionApps include file
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 mpu;
//MPU6050 mpu(0x69); // <-- use for AD0 high
/* =========================================================================
NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
depends on the MPU-6050's INT pin being connected to the Arduino's
external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is
digital I/O pin 2.
* ========================================================================= */
/* =========================================================================
NOTE: Arduino v1.0.1 with the Leonardo board generates a compile error
when using Serial.write(buf, len). The Teapot output uses this method.
The solution requires a modification to the Arduino USBAPI.h file, which
is fortunately simple, but annoying. This will be fixed in the next IDE
release. For more info, see these links:
http://arduino.cc/forum/index.php/topic,109987.0.html
http://code.google.com/p/arduino/issues/detail?id=958
* ========================================================================= */
// uncomment "OUTPUT_READABLE_QUATERNION" if you want to see the actual
// quaternion components in a [w, x, y, z] format (not best for parsing
// on a remote host such as Processing or something though)
//#define OUTPUT_READABLE_QUATERNION
// uncomment "OUTPUT_READABLE_EULER" if you want to see Euler angles
// (in degrees) calculated from the quaternions coming from the FIFO.
// Note that Euler angles suffer from gimbal lock (for more info, see
// http://en.wikipedia.org/wiki/Gimbal_lock)
//#define OUTPUT_READABLE_EULER
// uncomment "OUTPUT_READABLE_YAWPITCHROLL" if you want to see the yaw/
// pitch/roll angles (in degrees) calculated from the quaternions coming
// from the FIFO. Note this also requires gravity vector calculations.
// Also note that yaw/pitch/roll angles suffer from gimbal lock (for
// more info, see: http://en.wikipedia.org/wiki/Gimbal_lock)
#define OUTPUT_READABLE_YAWPITCHROLL
// uncomment "OUTPUT_READABLE_REALACCEL" if you want to see acceleration
// components with gravity removed. This acceleration reference frame is
// not compensated for orientation, so +X is always +X according to the
// sensor, just without the effects of gravity. If you want acceleration
// compensated for orientation, us OUTPUT_READABLE_WORLDACCEL instead.
//#define OUTPUT_READABLE_REALACCEL
// uncomment "OUTPUT_READABLE_WORLDACCEL" if you want to see acceleration
// components ...
Unless you've changed the serial/usb port
rosserial
is supposed to use on your Arduino, you cannot useSerial.print(..)
orSerial.begin(..)
or anything withSerial
as it will interfere withrosserial
's protocol.Also: please link to any questions you've already found and the solutions you've already tried, so we can avoid suggesting the same things.
Thanks! Everything I've tried so far is in my question at the very end. So i just comment everything out that starts with
serial
Ok I will try!! However today i already tried reinstalling the newest version of the arduino ide, now im getting this rosserial errorsocket.error: [Errno 111] Connection refused
... My bad! did'nt start the ros master ;) Update: I tried commenting everything with serial out, still get the same error.I don't know why, but when I used Float64 with rosserial I always get a lost sync error, however, when changing it to Float32 everything get works. Try to find a message using float32 instead of float64 or create a custom one. I read the documents and there says the float64 message is converted into float32 (rosserial limitations(float64)) but I don't know why with explicit conversion to float32 works.
Had a bad feeling about the IMU. So i commented everything out of the sketch that has something to do with the IMU sensor. Now rosserial works fine. No sync error. Bad thing is, the y value of the vector3 message is empty, can't use that for navigation...
So today i tried a simple sketch just for the imu sensor. I also tried two different IMU sensors. I'm getting
Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
Other sketches without the IMU are working fine, as soon as I add the IMU part i get this error.