
메시지 수신을 늦게 받아도 , 메시지 송신이 모두 끝나도 , Subscriber는 이에 개의치 않코 버퍼에 쌓인 수신 메시지들을 출력해주었다.
Publisher의 rate(100) 설정해도 동일한 결과가 나왔다.
ng 범위를 bucket 리스트에 담아 매번 누락될때 누락된값들을 즉각 출력하고자 했다.
그런데 누락값이 9985 부터여야하는데 9986으로 되있다.

향후 디버깅 예정
하드 디버깅... ( 원인이 뭘까 , 그냥 offset +1 해주어서 해결하긴 했다.)
elif msg.data-1!=old: #elif omission is up to one ( omission cnt > 1)
print "NG {0} ~ {1} ".format(old+1,msg.data-1)
bucket_ng.append(range(old+1,msg.data+1))
data + 1 에서 offset +1 해줌.

receiver_overflow.py
#!/usr/bin/env python
import rospy
from std_msgs.msg import Int32
bucket_ng=[] #this is omission_datas bucket as list
old =0
flag = 0
def callback(msg):
global bucket,flag
global old #old is the purpose to find omission, past data
flag = 0
rospy.sleep(5)
print "============================="
print "resieved : {0} ".format(msg.data)
print "============================="
if msg.data-1!=old and msg.data-1 <old+2:
print "NG {0} ".format(msg.data-1) # if omission is just one. ** NG means omission data range
bucket_ng.append([msg.data-1,msg.data])
elif msg.data-1!=old: #elif omission is up to one ( omission cnt > 1)
print "NG {0} ~ {1} ".format(old+1,msg.data-1)
bucket_ng.append(range(old+1,msg.data+1))
else: # non omission
flag= 1
#print ng_bucket ( print omission datas) , I think this code should annotation(#) cause ommision datas are a lot
"""
if flag == 0:
print "omission datas"
for x in bucket_ng:
for y in x:
print(y)
del bucket_ng[:] # clear bucket
"""
old = msg.data
rospy.init_node("receiver",anonymous=False)
sub = rospy.Subscriber("my_topic",Int32,callback,queue_size=10000)
rospy.spin()
변수 old는 현재값의 이전 값.
이전 값을 통해 누락값 범위 확인가능
단지 하나의 값만 누락한것과 복수의 값 누락한 것들 구분하여 list buket에 넣음
sender_overflow.py
#!/usr/bin/env python
import rospy
from std_msgs.msg import Int32
rospy.init_node("sender",anonymous=False)
pub = rospy.Publisher("my_topic",Int32,queue_size=1000)
cnt = 0
rate = rospy.Rate(1000)
while pub.get_num_connections()==0:
pass
while not rospy.is_shutdown():
cnt+=1
pub.publish(cnt)
rate.sleep()
누락 값 해결법: Subscriber 노드의 큐사이즈를 1에서 충분히 늘린다 (100~)
큐의 버퍼가 1을 넘어서면 Subscriber가 그 이상의 사이즈가 들어올때 받을 수없기때문이다.

'프로그래머스 > ROS' 카테고리의 다른 글
| 과제 5순차적 실행 (0) | 2022.11.12 |
|---|---|
| 파이썬 2.0 에서 한글 사용 (0) | 2022.11.11 |
| 2-3 (2) 전송속도 _ 풀이 (0) | 2022.11.10 |
| ros노드 통신프로그래밍은 이걸로 대체하기 (나만의 메시지 자료구조 ) // 핵심// 이걸로 기록지 만들기 (0) | 2022.11.09 |
| ROS 노드 통신 프로그래밍3(나만의 메시지 정리) (0) | 2022.11.08 |