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

How to solve different ros::Time error message

asked 2019-04-30 16:03:02 -0500

RayROS gravatar image

I have a total of N. 7 .csv files. Those files are the result of N.7 sensors mounted on an underwater system. After packing both custom and standard messages according to available documentation and playing them in a test.bag file I am able to see the majority of them being broadcasted. Every file is composed of a different type of column but there is the same column in every file, which is timestamp.

The procedure

I am showing here N.3 print screen to replicate the problem.

The first file is composed of N.4 columns as it is possible to see below:

pressure_temperature_depth_timestamp

The second file is composed of N.3 columns as it is possible to see below: altitude

The third file I am showing is composed of 18 columns but I am showing only the last columns (that has the timestamp) as it is possible to see below:

usbl

The way I am packing all the customized and non-customized ROS messages is shown below, and it is done in the same way for all the N.7 files. So for brevity I am only including one that is related to the first file shown above. Here is the most important part of the code:

keller_reader.h

#include "csv.h"
#include <string>
#include "ros_float/pressure.h"
#include "ros_float/depth.h"
#include "ros_float/temperature.h"
struct KELLER_DATA
{
    unsigned long timestamp;
    double depth;
    double temperature;
    double pressure;
};

class Keller_reader
{
public:
  Keller_reader(std::string filename);
  bool nextLine();
  KELLER_DATA keller_data;
  sensor_msgs::FluidPressure pressureMsg;
  ros_float::pressure pMsg;
  ros_float::temperature tMsg;
  ros_float::depth dMsg;

private:
  io::CSVReader<4> keller_reader;
  unsigned int msgNumKeller;
  void packPressureMsg();
  // Custom Pressure Message
  void packCustom_TemperatureMsg();
  void packCustom_DepthMsg();
};

keller_reader.cpp

#include "keller_reader.h" 
Keller_reader::Keller_reader(std::string filename):
    keller_reader(filename)
{
    msgNumKeller = 0;
    keller_reader.read_header(io::ignore_extra_column,
                              "timestamp", "depth", "temp","pressure");
}

bool Keller_reader::nextLine()
{
    if(keller_reader.read_row(keller_data.timestamp, keller_data.depth,
                              keller_data.temperature, keller_data.pressure))
    {
        packPressureMsg();
        packCustom_TemperatureMsg();
        packCustom_DepthMsg();
        msgNumKeller++;
        return true;
    }
    else
    {
        return false;
    }
}

void Keller_reader::packPressureMsg()
{
    double doubleTime = double(keller_data.timestamp)/1e6;
    ros::Time stamp(doubleTime);
    pMsg.header.stamp = stamp;
    pMsg.header.frame_id = "/pressure";
    pMsg.header.seq = msgNumKeller;
    pMsg.fluid_pressure = keller_data.pressure;
}

void Keller_reader::packCustom_TemperatureMsg()
{
    // same procedure as above
}

void Keller_reader::packCustom_DepthMsg()
{
   // same procedure as above
}

Notice that the timestamp is treated in the same way in all files so that can be brought to a standard readable ROS time:

    double doubleTime = double(keller_data.timestamp)/1e6;
    ros::Time stamp(doubleTime);

Because remember from above that what I have in the .csv file is this:

this

The Problem

This approach works well for all N.6 files. However when I do the same with the last file I have very different errors. The most important part of the code is below:

usbl_reader.h

struct USBL_DATA
{
    int prop_time;
    double accuracy;
    double e;
    unsigned long ctime;
    double h_reader;
    int remote_id;
    int rssi;
    double n;
    double p;
    double depthUSBL;
    double r;
    double u;
    unsigned long mtime;
    double xPosition;
    double yPosition;
    double zPosition;
    int integrity;
    unsigned long timestamp;
};

class USBL_reader
{
public:
  USBL_reader(std::string filename);
  bool nextLine();

  USBL_DATA ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-04-30 22:27:01 -0500

robustify gravatar image

The timestamps in ROS bag files, and by extension your original CSV files, are stored in integer nanoseconds. Therefore, I think your problem is that you are assuming the timestamps are in microseconds when you convert them to a double representation. I think if you divide by 1e9 instead of 1e6 it will fix it.

edit flag offensive delete link more

Comments

@robustify, thank you very much, that was exactly what was happening! :)

RayROS gravatar image RayROS  ( 2019-05-01 11:16:02 -0500 )edit

You're welcome!

robustify gravatar image robustify  ( 2019-05-01 12:24:53 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-30 15:26:36 -0500

Seen: 944 times

Last updated: Apr 30 '19