Ask Your Question
0

rosserial not working with Bluetooth and custom msg

asked 2016-05-02 06:45:06 -0600

thepirate16 gravatar image

updated 2016-05-03 17:26:18 -0600

Hi guys,

I am currently running an Arduino MEGA ADK robot which is sending me data from its motors via bluetooth through an HC-05 device. This HC-05 is coupled with another HC-05 connected to an Arduino UNO, and it is THAT Arduino that sends me the data via rosserial.

The connection works normally in a normal ROS node run in the Arduino, the topic gets published efficiently.

The problem is, when I enable (by code) my arduino to receive the bluetooth data from the other arduino, the rosserial connection doesn't work. I get this error message:

dani@ROS:~/catkin_ws$ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0
[INFO] [WallTime: 1462188244.111483] ROS Serial Python Node
    [INFO] [WallTime: 1462188244.122188] Connecting to /dev/ttyACM0 at 57600 baud
    [ERROR] [WallTime: 1462188261.230066] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

Things:

  • Changing the Baud rate inside ArduinoHardware.h to 9600 as @PaulBouchier suggested in another question. doesn't work

  • Is not a problem of the connection between both HC-05, because if I make the data to be printed in the Serial Monitor of the Arduino IDE, the data appears correctly. So now the problem should be between the conection of the UNO and the Master via rosserial.

  • I am using a custom message for the things said, as appears in the #includes:

    Header header

    uint8 obstacle

    uint8 state_m1

    uint8 state_m2

    uint8 state_m3

    uint8 state_m4

    uint8 d_left

    uint8 d_right

    uint8 d_center

I post the code below: (forget about the names of topics, i just recycled the Ultrasound ros example):

#include <SoftwareSerial.h>
#include <ros.h>
#include <ros/time.h>
//#include <sensor_msgs/Range.h>
#include <pkg_2/msg_2.h>

//variables globales
char Buffer[11];
int SoF=0x01; 
int Eof=0x04;
int i=0;
int trama_ok=0;
//declaracion objetos
SoftwareSerial BT(10,11);      //Rx,Tx: pins 7,8 de la placa OBJETO BLUETOOTH

ros::NodeHandle  nh;

pkg_2::msg_2 range_msg;
ros::Publisher pub_range( "/ultrasound", &range_msg);



void setup()
{
  Serial.begin(9600);
  BT.begin(9600);
  delay(1);
  nh.initNode();
  nh.advertise(pub_range);
  delay(1);

}

void loop()
{
     if (BT.available())
  {
    int a=BT.read();
    Buffer[i]=a;
    i++;
    if (i==8) {trama_ok=1;}
    else {trama_ok=0;}

  }

  if(trama_ok==1){
         range_msg.obstacle = Buffer[1];
         range_msg.state_m1 = Buffer[2];
         range_msg.state_m2 = Buffer[3];
         range_msg.state_m3 = Buffer[4];
         range_msg.state_m4 = Buffer[5];
         range_msg.d_left = Buffer[6];
         range_msg.d_right = Buffer[7];
         range_msg.d_center = Buffer[8];
    pub_range.publish(&range_msg);
          nh.spinOnce();
  }
}

I thought that could be that rosserial doesn't work properly when also working with bluetooth...

Any thoughts?, I really need this working.

Thanks a lot.

EDIT 1: I've tried with: $ roslaunch rosserial_server serial.launch and the conection reaches the Arduino (at least the Rx led of the arduino is blinking) but anyway the topic /Ultrasound is not published.

This works succcesfully when using normal ROS sketches (NON-CUSTOM message sketches). Could be that the SoftwareSerial initialized was causing a mess? Same for the Serial.begin(9600), could that be messing with ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-05-03 18:24:17 -0600

thepirate16 gravatar image

updated 2016-05-03 18:27:51 -0600

Solved!! At the end I found that the error was in the code. In the following line:

 if (i==8) {trama_ok=1;}
    else {trama_ok=0;}

  }

  if(trama_ok==1){ //filling of fields here

Also the variable wasn't being reassigned to 0. Maybe this was part of the problem.

Seemed like it wasn't filling the fields of the message after them, I don't know why yet. I removed the variable trama_ok so the fields of the message were filled directly:

    if (BT.available())
  {
    int a=BT.read();
    Buffer[i]=a;
    i++;
    if (i==11){
               range_msg.obstacle = Buffer[1];
         range_msg.state_m1 = Buffer[2];
         range_msg.state_m2 = Buffer[3];
         range_msg.state_m3 = Buffer[4];
         range_msg.state_m4 = Buffer[5];
         range_msg.d_left = Buffer[6];
         range_msg.d_right = Buffer[7];
         range_msg.d_center = Buffer[8];
    pub_range.publish(&range_msg);
          nh.spinOnce();
   i=0;
   delay(1000);
  }

Anyway, seems to my by now that using $ rosrun rosserial_python serial_node.py /dev/ttyACM0 has its limitations.

Using $ roslaunch rosserial_server serial.launch has worked so well. Info is now being published smoothly.

Thanks everyone who at least looked at the question, I agree this was a bit awkward in its entireness, we see at the end that everything got its solution. I will open a new question about it as soon as I can.

If anyone could explain why rosserial_server works and why rosserial_python doesn't in this situation, that could be fantastic. (I will post another question for that).

edit flag offensive delete link more

Comments

This is the link to the new question about the above said:

http://answers.ros.org/question/23356...

thepirate16 gravatar imagethepirate16 ( 2016-05-03 18:41:12 -0600 )edit

hI, @thepirate16, I need help on the work you have shown in this query. How can I seek help from you in this regard?

Thank you.

Ayush Sharma gravatar imageAyush Sharma ( 2017-06-21 05:48:59 -0600 )edit

hello @Ayush Sharma, what do you need exactly?

thepirate16 gravatar imagethepirate16 ( 2017-06-25 10:46:13 -0600 )edit

Respected @thepirate, Kindly refer this.

I feel my code is wrong and i also feel that i am not able to write the code at this moment. Kindly respond on this. Regards

Ayush Sharma gravatar imageAyush Sharma ( 2017-06-25 12:55:22 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-05-02 06:45:06 -0600

Seen: 615 times

Last updated: May 03 '16