-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.py
36 lines (33 loc) · 1.12 KB
/
receiver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import rospy
import json
import time
from std_msgs.msg import String
def receiver(sent_msg):
global direction_save
data = json.loads(sent_msg.data)
if data["Comment"] == "Flag : You achieved to spy ROS communication!":
with open('log/test.log', 'a') as file:
file.write('Message received - Acceleration : ' + str(data["Acceleration"]) + " - Direction : " + str(data["Direction"]) + " - Global Direction : " + str(direction_save) + "\n")
direction_save = direction_save + data["Direction"]
rospy.loginfo("Received")
else:
error.append(sent_msg)
with open('log/test.log', 'a') as file:
file.write('Message received == Error!! ==> ' + sent_msg)
time.sleep(3)
if __name__ == '__main__':
global direction_save
global error
error = []
rospy.init_node("receiver", anonymous=True)
rate = rospy.Rate(2)
direction_save = 0
subscribed = rospy.Subscriber(
"sender",
String,
receiver,
queue_size=1,
)
while not rospy.is_shutdown():
rate.sleep()