Publish protobuf message
Hi Guys,
I am trying to publish custom protobuf message from a ros node.
My protobuffer message format is as given below :
syntax = "proto2";
package proto_tutorial;
message sample {
required string name = 1;
required int32 id = 2;
required double salary = 3;
}
And my talker.py
is as given below:
import rospy
from std_msgs.msg import String
import sys
proto_path = "/home/catkin_ws_proto/test/gen_files/"
sys.path.append(proto_path)
import sample_pb2
from sample_pb2 import sample
def talker():
pub = rospy.Publisher('chatter', sample, queue_size=10) # How to define the message type
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = "hello world %s" % rospy.get_time()
rospy.loginfo(hello_str)
pub.publish(hello_str)
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
But I am not able to define the message type in the pub = rospy.Publisher('chatter', sample, queue_size=10)
, could you please help me in clarifying the below doubts.
- How can I define the custom message type ?
- Is this supported ?
- Is conversion is the only solution ?
Thank you, KK
You cannot publish protobuf messages with the standard ROS infrastructure.
@gvdhoorn Thanks for the confirmation. I will try to convert the proto buffer msg into std msg then from subscriber end I will convert it back to protobuf. I hope from subscriber end I can use the protobuf message types. Correct me if I am wrong.
That depends on what you mean by "use the protobuf message types".
For example as given in the question, the sample protobuf message
You cannot use Protobuf msg types with
rospy
code, or at least not as the type forPublisher
s orSubscriber
s.@gvdhoorn, Thanks again. I will use
roscpp
to capture/subscribe to the serialized data fromrospy
publisher. (rospy
will be sending serialized data).