Ask Your Question
0

Trouble logging uint8 message fields

asked 2020-02-28 10:13:08 -0500

流水疾翔 gravatar image

updated 2020-02-28 11:04:34 -0500

#include <ros/ros.h>
#include "turtlesim/Color.h"
#include <iomanip>
void apple(const turtlesim::Color& msg)
{
    ROS_INFO_STREAM(std::setprecision ( 0 )
<< " color=(" << msg.r << " , " << msg.b << " , " << msg.g << " ) ");
    }
    int main(int argc, char **argv)
    {
        ros::init(argc, argv, "pose_subscriber");
        ros::NodeHandle n;
        ros::Subscriber pose_sub = n.subscribe("/turtle1/color_sensor", 10, &apple);
    ros::spin();
    return 0;
}

why do my output so strange? my output is like a lot of this:

[ INFO] [1582904454.849200284]:  color=(E , ? , V )

can someone tell me where do i did wrong?thanks very much!

edit retag flag offensive close merge delete

Comments

I provided an answer, but I also re-tagged and edited your question title. The original title was not descriptive enough. In the future, please try to follow the Support guidelines to get the best possible help: http://wiki.ros.org/Support

jarvisschultz gravatar image jarvisschultz  ( 2020-02-28 11:07:14 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2020-02-28 11:00:50 -0500

updated 2020-02-28 11:05:20 -0500

The issue is that the three fields you are trying to print are defined as uint8 in the message. In C++, those are of type uint8_t, and the output operator (<<) is treating this type like a char.

Does the following fix your issue?

ROS_INFO_STREAM(std::setprecision ( 0 ) << " color=(" << +msg.r << " , " << +msg.b << " , " << +msg.g << " ) ");

Read more here:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-02-28 10:13:08 -0500

Seen: 12 times

Last updated: Feb 28