msg file float variable digit problem

asked 2019-12-10 05:47:07 -0600

ermanas gravatar image

updated 2019-12-10 06:59:46 -0600

  • OS: Ubuntu 16.04 LTS with 4.15.0-52-generic kernel
    • ROS version: Kinetic

Hello, I'm writing a node for Pepperl+Fuchs PGV100.

You can check it out on it's github page.

I have a message file like this,


Header header
float32 angle
uint64 x_pos
float32 y_pos
string direction
uint8 color_lane_count
uint8 no_color_lane
uint8 no_pos

The output like this. The angle looks like has a one digit but it is 0 always. But why ROS msg is not publishing this one also with 10 digit accuracy.

angle: 314.0
x_pos: 11
y_pos: -19.6000003815
direction: "Straight ahead"
color_lane_count: 0
no_color_lane: 1
no_pos: 1

I want to publish my float messages with 2 digit after decimal. I'm writing the node in C++ and If it's nothing to do with ROS msg publishing, I'll try to fix the problem on my code.


edit retag flag offensive close merge delete


Can you show us how you are populating the angle field? So: can you show the code that sets its value?

gvdhoorn gravatar image gvdhoorn  ( 2019-12-10 05:54:35 -0600 )edit

I get the data from the Pepperl+Fuchs PGV100 as a string. I convert this string to the decimal with a unsigned long integer variable in the string2decimal function. Then, when I'm populating angle, I converted to degree by dividing to 10.0

  double ang_des = string2decimal(agv_ang_str);
  msg.angle = ang_des/10.0; // degree

y-pos is the same but the values that I got from the device are like this

angle: 3450 - for angle 345 degree y-pos: 72 - for 7.2 mm

When I change the angular resolution to 0.1 degree. It starts to give me with 10 digits like y-pos.

I'll add the code's github page to the question. But it's a quite dirty code with all of the communication settings.

ermanas gravatar image ermanas  ( 2019-12-10 06:41:54 -0600 )edit

what do you think? By the way, the code is pretty straight forward. Because I'm still learning programming.

ermanas gravatar image ermanas  ( 2019-12-11 23:24:18 -0600 )edit