forked from anidev/612-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvision_thread.h
64 lines (58 loc) · 1.36 KB
/
vision_thread.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef VISION_THREAD_H_INC
#define VISION_THREAD_H_INC
#include "vision_alt.h"
#include "612.h"
#include <Vision/AxisCamera.h>
#include <Vision/ColorImage.h>
#include <Vision/HSLImage.h>
#include <Task.h>
#include <vector>
class vision_thread {
public:
typedef void(*vision_processor)(vision_thread&, ColorImage&);
vision_thread(AxisCamera&, vision_processor);
~vision_thread();
void enable();
void disable();
void lock_targets();
void release_targets();
bool lock_targets_nowait(); //do not block
private:
SEM_ID target_lock;
Task thread_obj;
AxisCamera& cam;
vision_processor callback;
HSLImage image;
//no lock (only write from main thread), only atomic
bool enabled;
static int thread_worker(taskarg_t);
void process_loop();
};
//TODO: Use lock objects, RAII, and other nicities
class vision_targets {
public:
vision_targets();
~vision_targets();
#ifdef VISION_ALT_HEURISTIC
target& bottom();
target& top();
target& left();
target& right();
#else
std::vector<target> targets();
#endif
private:
static void update_helper(void*);
void update();
#ifdef VISION_ALT_HEURISTIC
target bottom_t;
target top_t;
target left_t;
target right_t;
#else
std::vector<target> targets_vec;
#endif
};
vision_thread& get_vision_thread();
vision_targets& get_targets();
#endif