Skip to content

Commit bc2eb6f

Browse files
author
Beagle
committed
New end-end latency tests, arduino code
Final blobdetect
1 parent 478e564 commit bc2eb6f

File tree

3 files changed

+99
-54
lines changed

3 files changed

+99
-54
lines changed

fg_bg_segm/blobdetect.cpp

+15-54
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ int main(int argc, char * argv[])
360360

361361
// Render blobs, and calculate average coordinates for each bucket list
362362
// on every 10th frame
363-
if (ctr == 10) {
363+
if (ctr == 5) {
364364

365365
// Iterate through every bucket
366366
for (it = blob_buckets.begin(); it != blob_buckets.end(); it++) {
@@ -577,7 +577,7 @@ int main(int argc, char * argv[])
577577
uint8_t left_ardu_coords, right_ardu_coords;
578578

579579
// if there are coordinates to send
580-
if (prev_left_valid || prev_right_valid) {
580+
if ((ctr == 0) && (prev_left_valid || prev_right_valid)) {
581581

582582
// compress left coordinates into a byte
583583
if (prev_left_valid) {
@@ -601,94 +601,55 @@ int main(int argc, char * argv[])
601601
right_ardu_coords = ((right_x_ardu & 0xf) << 4) |
602602
(right_y_ardu & 0xf);
603603
}
604-
605-
<<<<<<< HEAD
606-
// SEND FIRST COORDINATE
607-
// if left is valid, send it
608-
if (prev_left_valid) {
609-
// send
610-
ardu << left_ardu_coords;
611-
}
612-
// else, send the right coordinate twice
613-
else {
614-
ardu << right_ardu_coords;
615-
}
616-
617-
cout << "FIRST OUT" << endl;
618-
619-
// TODO wait for 1 byte from arduino
620-
while (ardu.get() != 55) {
621-
// stall
622-
}
623-
624-
// SEND SECOND COORDIANTE
625-
// if right is valid, send it
626-
if (prev_right_valid) {
627-
ardu << right_ardu_coords;
628-
}
629-
// else, send the left coordinate twice
630-
else {
631-
ardu << left_ardu_coords;
632-
}
633604

634-
// cout << "Blob avg coordinates: (" << x_coord << ", " << y_coord << ")" << endl;
635-
=======
636605
// SEND FIRST COORDINATE
637606
// if left is valid, send it
638607
if (prev_left_valid) {
639608
// send
640609
ardu << left_ardu_coords;
641-
printf("sending: (%d, %d), ", left_ardu_coords >> 4,
610+
printf("red: (%d, %d), ", left_ardu_coords >> 4,
642611
left_ardu_coords & 0xf);
643612
}
644613
// else, right coordinate is guaranteed to be valid so
645614
// send the right coordinate twice
646615
else {
647616
ardu << right_ardu_coords;
648-
printf("sending: (%d, %d), ", right_ardu_coords >> 4,
617+
printf("red: (%d, %d), ", right_ardu_coords >> 4,
649618
right_ardu_coords & 0xf);
650619
}
651620

652-
/*
653621
while (ardu.get() != 55) {
654622
// stall and wait on arduino
655623
}
656-
*/
657-
>>>>>>> 2e627b2b7dddee21fee982b7f40c789e1fd77a8f
658-
624+
659625
// SEND SECOND COORDIANTE
660626
// if right is valid, send it
661627
if (prev_right_valid) {
628+
if (prev_left_valid) {
629+
sleep(1);
630+
}
631+
662632
ardu << right_ardu_coords;
663-
printf("(%d, %d)\n", right_ardu_coords >> 4,
633+
printf("green: (%d, %d)\n", right_ardu_coords >> 4,
664634
right_ardu_coords & 0xf);
665635
}
666636
// else, left coordinate is guaranteed to be valid so
667637
// send the left coordinate again
668638
else {
669639
ardu << left_ardu_coords;
670-
printf("(%d, %d)\n", left_ardu_coords >> 4,
640+
printf("green/red: (%d, %d)\n", left_ardu_coords >> 4,
671641
left_ardu_coords & 0xf);
672642
}
673643

674-
<<<<<<< HEAD
675-
cout << "SECOND OUT" << endl;
676-
677-
// TODO wait for 1 byte from arduino
678-
while (ardu.get() != 55) {
679-
// stall
680-
}
681-
=======
682-
/*
683644
while (ardu.get() != 55) {
684-
// stall and wait on arduino
645+
// stall
685646
}
686-
*/
687-
>>>>>>> 2e627b2b7dddee21fee982b7f40c789e1fd77a8f
688-
689647
}
690648

691649
t = (double) cvGetTickCount() - t;
650+
if (ctr==0) {
651+
printf("sending ");
652+
}
692653
printf( "total frame processing time = %g ms\n",
693654
t/((double)cvGetTickFrequency()*1000.));
694655

fg_bg_segm/end-end-lat.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
mkdir -p end-end-lat
4+
for (( w = 1; w <= 10; w += 1 ))
5+
do
6+
mkdir -p end-end-lat/run-$w
7+
./blobdetect | awk '$1=="sending"{print $4,$5,$6,$7,$8}' >> end-end-lat/run-$w/run.txt & sleep 60; pkill blobdetect; sleep 5
8+
# YO KEEYOUNG
9+
# idk why but that sleep 5 at the end fixed things
10+
# runs just fine now, no NaN
11+
awk '{sum+=$4}END{print sum/NR}' end-end-lat/run-$w/run.txt >> end-end-lat/run-$w/avg.txt
12+
done
13+

fg_bg_segm/servo/servo.ino

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <Servo.h>
2+
3+
int STATE;
4+
int READ = 0;
5+
int MOVE = 1;
6+
int WRITE = 2;
7+
8+
Servo servo_h;
9+
Servo servo_v;
10+
int servo_h_pin = 5;
11+
int servo_v_pin = 6;
12+
13+
int x;
14+
int y;
15+
16+
int x_curr;
17+
int y_curr;
18+
int x_next;
19+
int y_next;
20+
21+
void setup()
22+
{
23+
STATE = READ;
24+
x = 0;
25+
y = 0;
26+
servo_h.attach(servo_h_pin);
27+
servo_v.attach(servo_v_pin);
28+
pinMode(servo_h_pin, OUTPUT);
29+
pinMode(servo_v_pin, OUTPUT);
30+
31+
Serial.begin(9600);
32+
}
33+
34+
void loop()
35+
{
36+
if(STATE == READ){
37+
if(Serial.available() > 0){
38+
int inByte = Serial.read();
39+
x = inByte >> 4;
40+
y = inByte & 15;
41+
42+
x_curr = servo_h.read();
43+
y_curr = servo_v.read();
44+
x_next = map(x, 0, 15, 0, 180);
45+
y_next = map(y, 0, 15, 0, 180);
46+
47+
STATE = MOVE;
48+
49+
//servo_h.write(x_pos);
50+
//servo_v.write(y_pos);
51+
//while((servo_h .read() != x_pos) || (servo_v.read() != y_pos)) ;
52+
//Serial.write(55);
53+
}
54+
}
55+
56+
if(STATE == MOVE){
57+
if(x_next < x_curr) x_curr--;
58+
else if(x_next > x_curr) x_curr++;
59+
if(y_next < y_curr) y_curr--;
60+
else if(y_next > y_curr) y_curr++;
61+
servo_h.write(x_curr);
62+
servo_v.write(y_curr);
63+
delay(3);
64+
if((x_curr == x_next) && (y_curr == y_next)) STATE = WRITE;
65+
}
66+
67+
if(STATE == WRITE){
68+
Serial.write(55);
69+
STATE = READ;
70+
}
71+
}

0 commit comments

Comments
 (0)