Skip to content

Commit 53b75dc

Browse files
committed
Merge branch 'feat/validate_interloc'
2 parents 5819d12 + 7b8b4f0 commit 53b75dc

5 files changed

Lines changed: 112 additions & 2 deletions

File tree

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ protobuf == 3.17.3
44
tqdm == 4.62.2
55
PyQt5 == 5.15.6
66
pyqtgraph == 0.12.3
7-
PyQt5-stubs == 5.15.2.0
7+
PyQt5-stubs == 5.15.2.0
8+
matplotlib == 3.5.0
9+
numpy

src/analysis/__init__.py

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import csv
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
6+
def analyze_validation(filename):
7+
with open(filename) as file:
8+
reader = csv.DictReader(file)
9+
data = list(reader)
10+
11+
valid_angle_data = list(filter(lambda d: (float(d['Azimuth']) < 9999), data))
12+
13+
calculated_angles = np.array([float(v['Azimuth']) for v in valid_angle_data])
14+
expected_angles = np.array([float(v['angle']) for v in valid_angle_data])
15+
16+
unique_angles = np.unique(expected_angles)
17+
mean_calculated_angles = np.zeros(unique_angles.shape)
18+
19+
for i in range(len(mean_calculated_angles)):
20+
data_points = list(filter(lambda d: (float(d['angle']) == unique_angles[i]), valid_angle_data))
21+
mean_calculated_angles[i] = np.mean([float(v['Azimuth']) for v in data_points])
22+
23+
plt.figure()
24+
plt.title("Sortie du HiveBoard")
25+
plt.xlabel("Angle réel (°)")
26+
plt.ylabel("Angle mesuré (°)")
27+
plt.plot(expected_angles, calculated_angles, '.')
28+
29+
plt.figure()
30+
plt.title("Précision de l'angle mesuré")
31+
plt.xlabel("Angle Réel (°)")
32+
plt.ylabel("Erreur absolue (°)")
33+
plt.plot(unique_angles, np.abs(unique_angles - mean_calculated_angles), '.')
34+
35+
plt.show()
36+
37+
38+
analyze_validation("../data/validation_2021-11-17 15:34:02.556853.20211117_153402.csv")

src/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
data += hb.read_angle_data()
4848

4949
testbench.goToTick(stepSize)
50-
posTick = int(testbench.getPosition())
5150
for frame in data:
5251
frame['Encoder Tick'] = ticks
5352
frame['Angle'] = tickToAngle(ticks)

src/validate_interloc.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import pickle as pkl
2+
from datetime import datetime
3+
from time import sleep, strftime
4+
5+
import pandas
6+
from tqdm import tqdm
7+
8+
from src.hiveboard.HiveBoard import HiveBoard
9+
from src.hiveboard.proto.ethernet_stream import EthernetStream
10+
from src.hiveboard.proto.message_pb2 import STANDBY, OPERATING
11+
from src.hiveboard.usb_stream import UsbStream
12+
13+
# To use ethernet, you must have a static IP of 192.168.1.101 on submask 255.255.255.0
14+
from src.turning_station.TurningStation import tickToAngle, TurningStation
15+
16+
USE_ETHERNET = False
17+
18+
REMOTE_HB_ID = 1
19+
NUM_DATA_POINTS_PER_ANGLE = 20
20+
21+
if not USE_ETHERNET:
22+
hb_stream = UsbStream('/dev/ttyACM0')
23+
else:
24+
hb_stream = EthernetStream(55551)
25+
hb_stream.wait_connection()
26+
27+
hb = HiveBoard(hb_stream, log=True)
28+
testbench = TurningStation('/dev/ttyACM1', 115200)
29+
30+
data = []
31+
32+
hb.greet()
33+
hb.set_interloc_state(STANDBY)
34+
35+
# TODO: Add way to turn until position is 0
36+
sleep(2) # arduino needs to reboot after uart initialisation
37+
testbench.resetPosition()
38+
39+
stepSize = 20
40+
for ticks in tqdm(range(0, 2060, stepSize)):
41+
hb.enable_interloc_dumps(True)
42+
hb.set_interloc_state(OPERATING)
43+
44+
while len(hb.interloc_data.keys()) == 0 or REMOTE_HB_ID not in hb.interloc_data.keys() or len(
45+
hb.interloc_data[REMOTE_HB_ID]) < NUM_DATA_POINTS_PER_ANGLE:
46+
sleep(1)
47+
48+
hb.enable_interloc_dumps(False)
49+
hb.set_interloc_state(STANDBY)
50+
51+
testbench.goToTick(stepSize)
52+
53+
for data_point in hb.interloc_data[REMOTE_HB_ID]:
54+
data_point_copy = data_point.copy()
55+
data_point_copy['ticks'] = ticks
56+
data_point_copy['angle'] = tickToAngle(ticks)
57+
58+
data.append(data_point_copy)
59+
60+
hb.interloc_data[REMOTE_HB_ID] = []
61+
62+
sleep(0.5)
63+
testbench.resetPosition()
64+
65+
dataframe = pandas.DataFrame(data)
66+
dataframe.to_csv(f'data/validation_{datetime.now()}.{strftime("%Y%m%d_%H%M%S")}.csv')
67+
68+
sleep(1)
69+
hb.enable_interloc_dumps(False)
70+
hb.set_interloc_state(OPERATING)
71+
hb.kill_receiver()

0 commit comments

Comments
 (0)