Vision
Target detection
For goal detections, an Open MV H7 camera was used. Using the Open MV IDE, blob color detection was possible using micropyhton scripts. With this, the bounding box was identified and sent to the arduino. This measures were then used by both robots when going towards the goal or estimating the distance to the goal.
UART communication
When sending information to the arduino, we faced several issues as the program would sometimes get stuck. We eventually realized that this was due to the protocol that we were using, as the buffer would sometimes receive an incomplete message and get an error when trying to process it. Therefore, to solve this issue, we changed the way to send and receive messages. In python the message was sent in the following format:
Here, the tag value was either an a or a b according to the color of the goal, then the x and y values were the center of the blob and w and h the width and heigth. this message was then received on the arduino on the Serial 3 port, using the following code:
void updateGoals() {
if (Serial3.available()) {
String input1 = Serial3.readStringUntil('\n');
if (input1[0] == 'a')
yellowGoal.update(input1);
else if (input1[0] == 'b')
blueGoal.update(input1);
}
}
Then, for the object update, the following code was used:
void Goal::update(String str) {
int arr[4];
String data = "";
int index = 0;
for (int i = 2; i < str.length() && index < 4; i++) {
if (!(str[i] == ',')) {
data += str[i];
} else if (str[i] == ',' || i == str.length() - 1) {
arr[index++] = data.toInt();
data = "";
}
x = arr[0];
y = arr[1];
w = arr[2];
h = data.toInt();
area = w * h;
}
}