0
$\begingroup$

Rosanswers logo

#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!


Originally posted by 流水疾翔 on ROS Answers with karma: 5 on 2020-02-28

Post score: 0


Original comments

Comment by jarvisschultz on 2020-02-28:
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

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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:


Originally posted by jarvisschultz with karma: 9031 on 2020-02-28

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.