Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarpdataplayer timestamp gets rounded because of Ubuntu regional format #2558

Closed
aikolina opened this issue Apr 27, 2021 · 3 comments · Fixed by #2560
Closed

yarpdataplayer timestamp gets rounded because of Ubuntu regional format #2558

aikolina opened this issue Apr 27, 2021 · 3 comments · Fixed by #2560
Assignees

Comments

@aikolina
Copy link
Collaborator

Describe the bug
When checking the envelope of the data coming out of yarpdataplayer, the timestamp gets rounded to an integer.

To Reproduce

  1. Ubuntu regional format should be Italian (or any other language using , instead of . for decimals).
  2. Load some data in the yarpdataplayer and enable the Strict option.
  3. Read the yarpdataplayer port from the command line using yarp read ... /port_name envelope.
  4. Check the timestamp format.

Expected behavior
For example, if the considered input data is:

1 0.003000 AE (37499 1651768 ...

Then, the output of yarp read ... /port_name envelope should be:

1 0.00300000000000000006245 AE (37499 1651768 ...

Instead, I was getting:

1 0 AE (37499 1651768 ...

Configuration:

  • OS: Ubuntu 18.04.5 LTS
  • yarp version: 3.4.3+38-20210330.6+gitf7f000f39
  • compiler: not relevant

Solution
It was a problem of the regional format in Ubuntu: yarpdataplayer interpreted the timestamp correctly after I changed from Italian to English (United States) and restarted my laptop.

English_US

@drdanz
Copy link
Member

drdanz commented Apr 28, 2021

yarp::conf::{from_string,to_string} and yarp::os::NetType::{fromString,toString} are supposed to take care of that, see

// If locale is set, the locale version of the decimal point is used.
// In this case we change it to the standard "."
// If there is no decimal point, and it is not being used the exponential
// notation (i.e. the number is in integer form, for example 100000 and not
// 1e5) we add ".0" to ensure that it will be interpreted as a double.
struct lconv* lc = localeconv();
size_t offset = str.find(lc->decimal_point);
if (offset != std::string::npos) {
str[offset] = '.';
} else if (str.find('e') == std::string::npos && str != "inf" && str != "-inf" && str != "nan") {
str += ".0";
}
return str;

// Need to deal with alternate versions of the decimal point.
// We need a copy of the string where the decimal point can be replaced.
std::string src_c = src;
size_t offset = src.find('.');
if (offset != std::string::npos) {
struct lconv* lc = localeconv();
src_c[offset] = lc->decimal_point[0];
}

I believe that there might be some place in yarpdataplayer where these functions are not used, and the data is read "raw"...

@drdanz
Copy link
Member

drdanz commented Apr 28, 2021

CC @vtikha @vvasco

@vvasco
Copy link

vvasco commented Apr 29, 2021

A PR has been opened here to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants