Rosserial interrupts serial communication of Arduino

Hello,
I have a very specific question regarding the serial connection and rosserial. Hopefully someone here has some experience on this topic. I'm using a Teensy 3.5 and want to communicate with a Raspberry Pi via rosserial. With the Teensy, I'm reading some data from a Xsens Mti-7 IMU and parse them to get all the data I want. This communicates via Serial1. That works fine until I want to publish the data via rosserial in my arduino code. The rosserial communicates via Serial4. After publishing the data I only get around 3-12 Bytes (most of the time its just the preamble, the bus identifier/address and the message identifier).

This is a message I get without publishing via rosserial:
FAFF3639102002DEBB10600402EC250D20300CC1D8B246C056F679C2C3C8A940200CBF12AAA9408CE30EC10AE24880200C3A8802BEBAB99241BB2FE420

These are some messages I get with publishing via rosserial:
FAFF36
FAFF3639FAFF36
FAFF3639102002D9DD10FAFF

It looks like some interrupts while reading the date from Serial1, but I don't know how to fix it. I thought if I do the communication on different Serial-ports
it doesn't affect the other ones.

More information:

  • I'm using ros-melodic on a Raspberry Pi with ubuntu 18.04.
  • The baud-rate of rosserial is 57600.
  • The library for parsing the IMU data is self-made. Here is an example of how I do the reading:
float Mti7::readFloat() {
    union {
        float f;
        uint8_t b[4];
    } u;
    for (int i = 3; i >= 0; i--) {
        while (!_NavigationSerial->available());
        u.b[i] = _NavigationSerial->read();
        _checksum = _checksum + u.b[i];
    }

    _bytesRead += 4;
    return u.f;
}
  • This is a short version of my arduino code with the necessary parts:
// Define for Rosserial to use Serial4
#define USE_TEENSY_HW_SERIAL4

void setup() {
  NavigationUART.begin(115200); //This is Serial1
  Serial.begin(9600);
  
  pinMode(PayloadON_pin, OUTPUT);
  digitalWrite(PayloadON_pin, HIGH);
  delay(200);

  initRos();
}

void loop() {
  xsens.updateMesures();
  publish_ros(); 
}

void initRos(){
  nh.initNode();
  nh.advertise(received_data);
  nh.advertise(gps_data);
  nh.advertise(location_data);
  nh.advertise(pressure_data);
  nh.advertise(temp_data);
  nh.advertise(deph_data);
}

void publish_ros(){
  if (timeAfterBoot > 60000 || enoughTimePassed) {
    enoughTimePassed = true;
    digitalWrite(InternalLED1_pin, Led1State);
    Led1State = !Led1State;
    if(nh.connected()){
      fillRosMsgs();
      publishRosMsgs(); //This is the function which causes the error
    }
    nh.spinOnce();
  }
}

void publishRosMsgs() {
  received_data.publish(&str_RosMsg);
  location_data.publish(&imu_RosMsg);
  pressure_data.publish(&fp_RosMsg);
  gps_data.publish(&gps_RosMsg);
  temp_data.publish(&temp_RosMsg);
  deph_data.publish(&deph_RosMsg);
}

Thanks for any suggestions and your help!

No, the necessary parts are probably not shown. In the majority of cases the error is in that part of the code people are hiding from us.
Is that code excerpt also showing the problem: No, because it doesn't even compile.

Sorry that I didn't provide all the code. That would be too much, especially because of the library. It was more an understanding problem than a code problem, so I thought it would be enough to provide some code for understanding purposes.

I solved the problem by adding a semaphore for the completed reading of the IMU.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.