Skip to content

Commit f9e7cc6

Browse files
committed
RFID tag list
1 parent 27def10 commit f9e7cc6

File tree

7 files changed

+131
-10
lines changed

7 files changed

+131
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
robot/log/
22
robot/build/
33
robot/install
4+
.venv/

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
"imgmsg",
66
"irobot",
77
"linalg",
8+
"mqtt",
89
"nanosec",
910
"odometry",
11+
"paho",
1012
"proto",
1113
"rclpy",
14+
"rfid",
1215
"robo",
1316
"turtlebot"
1417
],

game-engine/esp32-rfid/esp32-rfid.ino

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ MFRC522 mfrc522{driver}; // Create MFRC522 instance.
1313

1414
uint32_t chipId = 0;
1515
EspMQTTClient client(
16-
"DigitalAGclub", // WiFi SSID at the maker space
16+
"DigitalAGClub", // WiFi SSID at the maker space
1717
"username", // WiFi password
18-
"192.168.0.100" // MQTT Broker server IP
18+
"192.168.1.100" // MQTT Broker server IP
1919
);
2020

2121
void onConnectionEstablished()
@@ -68,10 +68,12 @@ void loop() {
6868
* Helper routine to dump a byte array as hex values to Serial.
6969
*/
7070
void dump_byte_array(byte *buffer, byte bufferSize) {
71+
char payload[bufferSize];
7172
for (byte i = 0; i < bufferSize; i++) {
7273
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
7374
Serial.print(buffer[i], HEX);
75+
payload[i] = buffer[i];
7476
}
75-
76-
client.publish("purdue-dac/carrot", "Hello", false);
77+
78+
client.publish("purdue-dac/carrot", payload, false);
7779
}

game-engine/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
paho-mqtt==2.1.*

game-engine/rfid.json

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"82BC1BD5": 1,
3+
"92BC1BD5": 1,
4+
"E2C21BD5": 1,
5+
"F2C21BD5": 1,
6+
"D2BC1BD5": 1,
7+
"62BC1BD5": 1,
8+
"72BC1BD5": 1,
9+
"12EE17D6": 1,
10+
"22EE17D6": 1,
11+
"32EE17D6": 1,
12+
"D2ED17D6": 1,
13+
"E2ED17D6": 1,
14+
"F2ED17D6": 1,
15+
"02EE17D6": 1,
16+
"22C31BD5": 2,
17+
"12C31BD5": 2,
18+
"02C31BD5": 2,
19+
"72F717D6": 2,
20+
"62F717D6": 2,
21+
"52F717D6": 2,
22+
"32F717D6": 2,
23+
"32C31BD5": 2,
24+
"42C31BD5": 2,
25+
"02F717D6": 2,
26+
"22F717D6": 2,
27+
"42F717D6": 2,
28+
"12F717D6": 2,
29+
"82FB17D6": 2,
30+
"62FF17D6": 3,
31+
"52C31BD5": 3,
32+
"62C31BD5": 3,
33+
"32FF17D6": 3,
34+
"820318D6": 3,
35+
"42FF17D6": 3,
36+
"52FF17D6": 3,
37+
"72C31BD5": 3,
38+
"82C31BD5": 3,
39+
"F2F617D6": 3,
40+
"E2F617D6": 3,
41+
"D2F617D6": 3,
42+
"12FF17D6": 3,
43+
"22FF17D6": 3,
44+
"A2F617D6": 4,
45+
"32F617D6": 4,
46+
"42F617D6": 4,
47+
"82F617D6": 4,
48+
"92F617D6": 4,
49+
"A2BC1BD5": 4,
50+
"92C31BD5": 4,
51+
"52F617D6": 4,
52+
"72F617D6": 4,
53+
"C2F617D6": 4,
54+
"12F617D6": 4,
55+
"22F617D6": 4,
56+
"B2BC1BD5": 4,
57+
"02F617D6": 4,
58+
"C2C31BD5": 5,
59+
"F2F517D6": 5,
60+
"E2F517D6": 5,
61+
"D2F517D6": 5,
62+
"C2F517D6": 5,
63+
"A2F517D6": 5,
64+
"B2C31BD5": 5,
65+
"A2C31BD5": 5,
66+
"72FF17D6": 5,
67+
"A2ED17D6": 5,
68+
"B2ED17D6": 5,
69+
"C2ED17D6": 5,
70+
"82F317D6": 5,
71+
"C2BC1BD5": 5
72+
}

game-engine/score_tracking.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import json
2+
import paho.mqtt.client as mqtt
3+
from datetime import datetime, timedelta
4+
5+
6+
def on_connect(client, user_data, flags, reason_code, properties):
7+
print(f"Connected with result code {reason_code}")
8+
# Subscribing in on_connect() means that if we lose the connection and
9+
# reconnect then subscriptions will be renewed.
10+
client.subscribe("purdue-dac/carrot")
11+
12+
13+
# The callback for when a PUBLISH message is received from the server.
14+
def on_message(client, user_data, msg):
15+
uid = msg.payload.hex().upper()
16+
with open("rfid.json", "r") as fp:
17+
tags = json.load(fp)
18+
tags[uid] = 5
19+
with open("rfid.json", "w") as fp:
20+
json.dump(tags, fp)
21+
print(uid)
22+
global last_time # Bad practice. Only use in emergency
23+
if last_time is None:
24+
last_time = datetime.now()
25+
if (datetime.now() - last_time) < timedelta(seconds=4, microseconds=500):
26+
client.publish("purdue-dac/sound", "1")
27+
elif (datetime.now() - last_time) > timedelta(seconds=7):
28+
last_time = None
29+
else:
30+
client.publish("purdue-dac/sound", "2")
31+
last_time = None
32+
33+
34+
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
35+
client.on_connect = on_connect
36+
client.on_message = on_message
37+
last_time = None
38+
39+
client.connect("localhost", 1883, 60)
40+
41+
# Blocking call that processes network traffic, dispatches callbacks and
42+
# handles reconnecting.
43+
# Other loop*() functions are available that give a threaded interface and a
44+
# manual interface.
45+
client.loop_forever()

robot/src/robo_rabbit_run/robo_rabbit_run/detector.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def detect_rabbit(self):
140140
)
141141

142142
contours = [ # only keep contours that fit our criteria
143-
cnt for cnt in contours if cv.contourArea(cnt) > 20
143+
cnt for cnt in contours if cv.contourArea(cnt) > 40
144144
]
145145
self.locate_rabbit(contours)
146146

@@ -158,12 +158,9 @@ def detect_scarecrow(self):
158158
)
159159

160160
contours = [ # only keep contours that fit our criteria
161-
cnt for cnt in contours if cv.contourArea(cnt) > 5
161+
cnt for cnt in contours if cv.contourArea(cnt) > 15
162162
]
163-
if len(contours) > 0:
164-
self.locate_scarecrow(contours)
165-
else:
166-
print("No scarecrow detected")
163+
self.locate_scarecrow(contours)
167164

168165
def locate_scarecrow(self, contours: list):
169166
"""extract moment on each contour and then average"""

0 commit comments

Comments
 (0)