Ask Your Question
0

publish error

asked 2014-04-21 22:16:21 -0600

noel gravatar image

updated 2014-07-25 10:14:09 -0600

gvdhoorn gravatar image

i am doing a project of robot dicking station. This program is for three infrared receivers and three infrared emitters, i don't know why it happened. Could anybody help me ?

#include <IRremote.h>
#include <IRremoteInt.h>

#include <ros.h>
#include <std_msgs/String.h>


ros::NodeHandle  nh;

std_msgs::String str_msg;
ros::Publisher st("state", &str_msg);


char state[10] = "cent-left";
char state_1[11] = "cent-right";
char state_2[10] = "cent-cent";
char state_3[11] = "right-left";
char state_4[12] = "right-right";
char state_5[11] = "right-cent";
char state_6[10] = "left-left";
char state_7[11] = "left-right";
char state_8[10] = "left-cent";


int RECV_PIN = 11;
int RECV_PIN_2= 9;
int RECV_PIN_1= 13;

IRrecv irrecv(RECV_PIN);
IRrecv irrecv1(RECV_PIN_1);
IRrecv irrecv2(RECV_PIN_2);

decode_results results;

void setup()
{
   irrecv.enableIRIn();
  irrecv1.enableIRIn();
  irrecv2.enableIRIn();
  nh.initNode();
  nh.advertise(st);




}

void loop()
{ 
  long Right=0xEF1F1509;
  long left=0xCC36FF5E;

  if (irrecv.decode(&results)) 
  { 
  long val2= results.value;  
     if(val2==0xEF1F1509)
    { 
       str_msg.data = state;
    } else if(val2==0xCC36FF5E)
    {
       str_msg.data = state_1;
    }
     else {
         str_msg.data = state_2;
         }       
       st.publish( &str_msg );

  }
  if (irrecv1.decode(&results))
  {
    long val=results.value;
    if (val==0xEF1F1509)
    {
    str_msg.data=state_3;
    } else
    if (val==0xCC36FF5E)
    {
    str_msg.data=state_4;
    }else
    {
      str_msg.data=state_5;
    }
    st.publish(&str_msg);
  }
    if (irrecv2.decode(&results))
  {
    long val1=results.value;
    if (val1==0xEF1F1509)
    {
    str_msg.data=state_6;
    } else
    if (val1==0xCC36FF5E)
    {
    str_msg.data=state_7;
    }else
    {
      str_msg.data=state_8;
    }
    st.publish(&str_msg);
  }
  nh.spinOnce();
  delay(1500);
}

Console:

[INFO] [WallTime: 1398132348.674181] ROS Serial Python Node
[INFO] [WallTime: 1398132348.682297] Connecting to /dev/ttyACM0 at 57600 baud
[ERROR] [WallTime: 1398132365.792995] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-07-25 09:54:06 -0600

Not sure but documentation says to include ros.h as first:

In order to use the rosserial libraries in your own code, you must first put include ros.h prior to including any other header files, e.g.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2014-04-21 22:16:21 -0600

Seen: 176 times

Last updated: Jul 25 '14