Arduino multiple callback error

asked 2017-07-29 21:48:28 -0500

renanmb gravatar image

updated 2017-07-30 00:49:33 -0500

Hello everyone, thanks for the attention! I am using Ros Kinetic on Ubuntu Mate as OS, running on a Raspbery Pi 3 I am trying to use an Arduino Mega 2560 to do a few things in my robot. Control my Stepper Motors, publish raw IMU data and publish encoder readings.

The codes can be located here: https://github.com/renanmb/Ros_arduino

The Problem is:

When I use Arduino with only one type of message it works. However, when it runs different callbacks and publishers of different types, for example: Boolean, Int32 and Float 32. It does not work.

I receive the following message on my Terminal:

[ERROR] [ 1433855869.447165] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

In my Github Repository called Ros_arduino:

The codes that do not work

ros_surp.ino (lowercase, the upper case one is missing stuff)

ROS_PWM.ino

The codes that do work

IMU_ROS_test2.ino

chapter7_book.ino

chapter7_book_blink_and ......

I thought it was the following erros:

  • Buffer. Then I modified the buffer size and it keep giving me the same error. I used the following tutorial to change the buffer:
  • Baud rate. then I changed the baud rate using rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0 _baud:=????? and I added Serial.begin() with the desired baud rate in the arduino. It did not work, I kept receiving the same error message.
  • Bad cable

So what should I do to fix it?

I want to know if there is a way to use my Arduino to control multiple actuators and publish IMU and encoder data. If not I want to know if there is any board that I could use for that. I am considering as a last case scenario to use multiple arduinos, because it is an Ugly solution and takes a lot of space.

I am using the Arduino because of the AVR micro controller that is easier and generates a much better PWM signal than ARM based micro controller.

My code: ros_surp.ino

gives me

[ERROR] [ 1433855869.447165] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

#include <Wire.h>
#include <ros.h>

#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303.h>
#include <Adafruit_LSM303_U.h>

#include <std_msgs/Float32.h>
#include <std_msgs/Int32.h>
#include <std_msgs/Bool.h>

#include <Encoder.h> //encoder library - http://www.pjrc.com/teensy/td_libs_Encoder.html

#include <PWM.h> //PWM library for controlling the steppers

/* Assign a unique ID to the sensors */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
//******** add later gyroscope and magnet sensor for more complex positioning


//  Both pins must have interrupt capability
Encoder myEnc(2,3);

//Motor pins
//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
const int step_pin1 = 11;     // the pin that define the steps
const int dir_pin1 = 22;      // the dir pin
const int step_pin2 = 12;     // the pin that define the steps
const int dir_pin2 = 24;
int32_t frequency1 = 0; //frequency (in Hz)
int32_t ...
(more)
edit retag flag offensive close merge delete

Comments

This question would be much more useful if the code that is giving you trouble is posted here instead of somewhere else. External webpages can become inaccessible or dead.

jayess gravatar image jayess  ( 2017-07-30 00:21:20 -0500 )edit

Did you set the proper permissions on the port?

jayess gravatar image jayess  ( 2017-07-30 00:32:28 -0500 )edit

Yes, and it work fine for other codes. Just when I try to run more than one subscriber/publisher , or both that it show me that error message.

renanmb gravatar image renanmb  ( 2017-07-30 00:52:56 -0500 )edit

Why do you use while(true) in your setup function? I don't see how it would work very leave setup

allenh1 gravatar image allenh1  ( 2017-07-30 17:14:54 -0500 )edit

The while(true) is for the PWM library. I possibly can change it, but it worked on the code without ros.

renanmb gravatar image renanmb  ( 2017-07-30 19:27:09 -0500 )edit

While I don't have much experience with Arduino, it would seem that with that loop you will never leave the setup function.

jayess gravatar image jayess  ( 2017-07-30 19:56:20 -0500 )edit

But it leaves, because most of the code for the PWM is working with the registers, not always it is true it turns on and off. I dont know very well how that works too but it works. I have been thinking about using message_filters, I saw good results but I dont know how to use, not many tutorials.

renanmb gravatar image renanmb  ( 2017-07-30 20:01:11 -0500 )edit

Message_filters , may solve the problem if it is merging all the message into just one subscriber. Because when I run just 1 subscriber it works. When I run multiple it does not work.

renanmb gravatar image renanmb  ( 2017-07-30 20:03:01 -0500 )edit