[ROS] message의 크기와 전송 속도

happy_quokka·2023년 10월 16일
0

ROS

목록 보기
11/25

1. sender_speed.py

#!/usr/bin/env python

import rospy
from std_msgs.msg import String

name = "sender"
pub_topic = "long_string"

rospy.init_node(name, anonymous=True)
pub = rospy.Publisher(pub_topic, String, queue_size=1)

hello_str = String()
rate = rospy.Rate(1)

pub_size = 10000000 #1M byte
# pub_size = 50000000 #5M byte
# pub_size = 100000000 #10M byte
# pub_size = 200000000 #20M byte
# pub_size = 500000000 #50M byte

my_string = ""
for i in range(pub_size):
    my_string += "#"

while not rospy.is_shutdown():
    hello_str.data = my_string + ":" + str(rospy.get_time())
    pub.publish(hello_str)
    # rospy.loginfo(str(hello_str.data).split(":")[1])
    rate.sleep()

2. receiver_speed.py

#!/usr/bin/env python

import rospy
from std_msgs.msg import String

name = "receiver"
sub_topic = "long_string"

def callback(data):
    current_time = str(rospy.get_time())
    arrival_data = str(data.data).split(":")

    time_diff = float(current_time) - float(arrival_data[1])
    string_size = len(arrival_data[0])
    rospy.loginfo(str(string_size) + "byte: "+str(time_diff) + "second")
    rospy.loginfo("speed: " + str(float(string_size)/time_diff) + "byte/s")

rospy.init_node(name, anonymous=True)
rospy.loginfo("Init")
rospy.Subscriber(sub_topic, String, callback)
rospy.spin()

3. sr_speed.launch

<launch>
    <node pkg="msg_send" type="sender_speed.py" name="sender"/>
    <node pkg="msg_send" type="receiver_speed.py" name="receiver" output="screen"/>
</launch>

4. 실행

$ roslaunch msg_send sr_speed.launch

1M

5M

10M

실행이 안된다ㅠㅠ용량이 크고 느려져서 그런것 같다...아마도...?

0개의 댓글