Robotics StackExchange | Archived questions

Rosserial: Topic id 125 & creation of publisher failed

Next UPDATE: Upload via Arduino IDE works fine (even if newPing,h is included). Upload with atom and platform.io leads to the described error :( But why???

UPDATE: I reduced the code step by step. I found out that #include is responsible for the error messages posted by rosserial. (just the include leads to the error even if I not create any NewPing object)

Any idea?

BR

Marco

Hi, I created a custom message:

SonarDistances.msg 
uint8 front_middle
uint8 right_front 
uint8 right_middle
uint8 right_rear 
uint8 left_front
uint8 left_middle 
uint8 left_rear
uint8 rear_middle

Catkinmake install and creation of the roslib etc. was done. devel path added to .bashrc.

Baud rate on arduino nano was set.

Serial.begin(57600)

Upload to arduino was fine. Now I start roscore and rosserial

rosrun rosserial_python serial_node.py /dev/ttyUSB0

After this I receive continously the following messages in the terminal:

[ERROR] [1521061577.369482]: Tried to publish before configured, topic id 125
[ERROR] [1521061577.434796]: Creation of publisher failed: need more than 1 value to unpack

(continously because I publish on a regular basis) (if i publish only once i only receive on time the id 125 message - after this a lost sync with device and restart is shown)

If I just use a simple chatter rosserial example with a string message the connection works an the topic is shown with rostopic echo.

Any advise?

BR and thanks in advance, Marco

Update: I just start roscore (no launch file) and rosserial.

roscore
rosrun rosserial_python serial_node.py /dev/ttyUSB0

Following code is used on arduino:

#include <ros.h>
#include <hallrover_robo/SonarDistances.h>
#include <NewPing.h>


//############## Sonar Definitions
#define SONAR_NUM     3 // Number or sensors.
#define SONAR_FM      0
#define SONAR_RF      1
#define SONAR_RR      2


#define SONAR_FM_TRIG_PIN 2 //Front middle
#define SONAR_FM_ECHO_PIN 3 //Front middle
#define SONAR_RF_TRIG_PIN 4 //Right front
#define SONAR_RF_ECHO_PIN 5 //Right front
#define SONAR_RR_TRIG_PIN 6 //Right rear
#define SONAR_RR_ECHO_PIN 7 //Right rear

#define MAX_DISTANCE 200
#define PING_INTERVAL 33 // Milliseconds between pings.

unsigned long pingTimer[SONAR_NUM]; // When each pings.
unsigned int cm[SONAR_NUM]; // Store ping distances.
uint8_t currentSensor = 0; // Which sensor is active.

NewPing sonar[SONAR_NUM] = { // Sensor object array.
  NewPing(SONAR_FM_TRIG_PIN, SONAR_FM_ECHO_PIN, MAX_DISTANCE),
  NewPing(SONAR_RF_TRIG_PIN, SONAR_RF_ECHO_PIN, MAX_DISTANCE),
  NewPing(SONAR_RR_TRIG_PIN, SONAR_RR_ECHO_PIN, MAX_DISTANCE),
};


//############### ROS definitions
ros::NodeHandle  nh;
hallrover_robo::SonarDistances sonarDistances;
int isSonarActive;
ros::Publisher sonarDistances_pub("/sonar_distances", &sonarDistances);



void setup() {
  // put your setup code here, to run once:
  Serial.begin(57600) ;
  nh.initNode();
while(!nh.connected()) {nh.spinOnce();} //wait for connection.


  nh.advertise(sonarDistances_pub);
  if (!nh.getParam("hr_sonar_active",&isSonarActive) ) isSonarActive = 0;
//  if (!nh.getParam("hr_sonar_update_frequence",&loop_time) ) loop_time = 1;

//just test
sonarDistances.right_front = 999;
sonarDistances.right_rear = 999;
sonarDistances.right_middle = 111;
sonarDistances.front_middle = 999;
sonarDistances.left_front = 999;
sonarDistances.left_rear = 999;
sonarDistances.left_middle = 111;
sonarDistances.rear_middle = 999;
  sonarDistances_pub.publish(&sonarDistances);
}

void loop()
{
    unsigned int distance;

    if ( isSonarActive == 1)
    {
      for (uint8_t i = 0; i < SONAR_NUM; i++) {
          if (millis() >= pingTimer[i]) {
            pingTimer[i] += PING_INTERVAL * SONAR_NUM;
            if (i == 0 && currentSensor == SONAR_NUM - 1)
              oneSensorCycle(); // Do something with results.
            sonar[currentSensor].timer_stop();
            currentSensor = i;
            cm[currentSensor] = 0;
            sonar[currentSensor].ping_timer(echoCheck);
          }
        }
    nh.spinOnce();
  }
}


void echoCheck() { // If ping echo, set distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
}

void oneSensorCycle() { // Do something with the results.
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    switch (i) {
      case SONAR_FM: sonarDistances.front_middle = cm[i];
      case SONAR_RF: sonarDistances.right_front = cm[i];
      case SONAR_RR: sonarDistances.right_rear = cm[i];
    }
  }
  sonarDistances_pub.publish(&sonarDistances);

}

Asked by Boregard on 2018-03-14 16:14:40 UTC

Comments

As your question stands, there's not much to go off of (no code, launch files, etc.). Can you please update your question with yourcode?

Asked by jayess on 2018-03-14 16:26:51 UTC

For future reference, please use the preformatted text (101010) button for terminal output, code, etc. and the quotes for actual quotes (documentation, etc.). The preformatted text button makes code/terminal out easier to read than the quotes.

Asked by jayess on 2018-03-14 16:29:54 UTC

Thank you. I added the code.

Asked by Boregard on 2018-03-15 00:11:10 UTC

Answers