I have a ROS node which manipulates a serial frame, the frame contains ultrasonic measurements, I have to extract this measurement and publish it as sensor_msgs/Range Message, and I am using the following code:

ros::Rate loop_rate(5);

        if(ser.available())//serial::Serial ser;
            std::string stringRange = ser.read(ser.available());
            //ROS_INFO_STREAM("Read: " << result.data);
            sonar_msg.range = ::atof(stringRange.c_str());
            sonar_msg.header.stamp = ros::Time::now();

When I try to build using catkin, the terminal fails and give me an error message:

error: request for member ‘serialize’ in ‘t’, which is of pointer type
               {aka sensor_msgs::Range_<std::allocator<void>>* const}’
 (maybe you meant to use ‘->’ ?)
     t.serialize(stream.getData(), 0);

I thing the problem in converting to float data.

How can I solve this?


1 Answer 1


First of all, You must completely consider all of the parameters in your topic. For example in your case by a simple search, you will find the parameters in sensor_msgs/Range. As you can see it comprise of different parameters like min_range, max_range and so on which is depend on your sensor. Maybe these parameters do not have any important for you but surely it is important when you are using others packages. fill all the parameters step by step.

About your code, please show us a more complete part of the code, how did you define sonar_msg?


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.