ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 = 9;
         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.

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 = 9;
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).