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

rosserial custom message float problem

asked 2022-06-18 16:10:29 -0600

gurselturkeri gravatar image

I created message file in catkin_ws/msg. Then i add this in arduino with:

rosrun rosserial_arduino make_library.py arduino_library_path message_pkg_name

When I publish float value from python to arduino but between in these values "0" show up. How can I change this? image description

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-06-18 21:17:20 -0600

qilin_gundamenjoyer gravatar image

The value, 0.00, will always show up since it's data type is still a float. Notice the trailing zeros to two decimal points, the zeroes after the decimal point. Instead, what you could do is for the ROS Publisher script, add a conditional statement to only print the float value if it's not zero.

In between the curly brackets of void loop(), a few lines of code like if ( [publish_value_variable] > 0) { pub.publish(&msg) } or if ( [publisher_value_variable] != 0) { pub.publish(&msg) should suffice your needs. Replace [publisher_value_variable] with the name of the variable that stores the current value of the publisher.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-06-18 16:10:29 -0600

Seen: 151 times

Last updated: Jun 18 '22