ROS消息阻塞,命令行同一行打印多个相同的数据

1. 问题描述

如下图所示,数据的传输通过TCP-IP通信,客户端接收到消息以后用rostopic 发布出去,rosinfo打印消息,原本一行出现一个数据(在服务器这端是这样),但是图中一行出现了两个甚至多个,RR,RP
在这里插入图片描述

2. 解决方法:

产生这个问题的原因是接收端(客户端)接收了以后,rostopic发布出去的频率不够,导致消息阻塞,发布在了同一行。也就是rate = rospy.Rate(50) # 10hz这一行代码,决定了ros发布的频率,原先设置的是10HZ,但是服务器发过来的数据大于10HZ,所以就阻塞了,有些数据发在了同一行

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import roslib
import rospy
#import tf
#import math
#import numpy as np
#from tf import transformations
from std_msgs.msg import Float32
from std_msgs.msg import String

import socket
#import json
#import time
# import sys

# def get_tf():

# rospy.init_node('talker', anonymous=True)
# pub = rospy.Publisher('gesture', String, queue_size=10)


# s = socket.socket()
# IP = "192.168.103.13"
# port = 12345
# # address = ('192.168.103.13', 12345)
# # readdress = ('192.168.103.26', 12345)
# # host = socket.gethostname()
# # port = 60000
#
#
#
# # s.connect(address)
#
#
# s.connect((IP, port))


# hand_msg = s.recv(1024)
# print(hand_msg)
#     print (s.recv(1024).decode())

    # gesture_flag = s.recv(1024).decode()
    # rospy.loginfo(gesture_flag)
    # print(gesture_flag)
    # pub.publish(gesture_flag)

# s.close()


if __name__ == '__main__':
    s = socket.socket()
    IP = "192.168.103.13"
    port = 12345
    s.connect((IP, port))
    #gesture_flag = s.recv(1024).decode()

    rospy.init_node('talker', anonymous=True)
    #pub = rospy.Publisher('gesture', String, queue_size=10)
    #gesture_flag = s.recv(1024).decode()
    #rospy.init_node('talker', anonymous=True)

    rate = rospy.Rate(50) # 10hz
    while not rospy.is_shutdown():
        gesture_flag = s.recv(1024).decode()
        #pub = rospy.Publisher('gesture', String, queue_size=10)
        pub = rospy.Publisher('gesture', String)
             # hello_str = "hello world %s" % rospy.get_time()
        #rospy.loginfo(gesture_flag)
        print (gesture_flag)
        pub.publish(gesture_flag)

        rate.sleep()
        #rospy.spin()





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值