Robotics StackExchange | Archived questions

rosserial custom message float problem

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

rosrun rosserialarduino makelibrary.py arduinolibrarypath messagepkgname

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

Asked by gurselturkeri on 2022-06-18 16:10:29 UTC

Comments

Answers

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.

Asked by qilin_gundamenjoyer on 2022-06-18 21:17:20 UTC

Comments