6#include "TinyRobotics/communication/Message.h"
7#include "TinyRobotics/communication/MessageSource.h"
9namespace tinyrobotics {
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
52 CameraEdgeFollower(uint8_t threshold = 20) : _threshold(threshold) {}
54 Result process(
const uint8_t* image, size_t width, size_t height) {
55 if (!image || width < 2 || height == 0) {
60 size_t y = (height * 3) / 4;
65 for (size_t x = 0; x < width - 1; x++) {
66 uint8_t p1 = image[y * width + x];
67 uint8_t p2 = image[y * width + x + 1];
69 int diff = abs((
int)p1 - (
int)p2);
71 if (diff > _threshold && diff > max_edge) {
81 int center = width / 2;
82 int error = best_x - center;
85 Message<
float> msgError(MessageContent::Error, error, Unit::Pixel);
86 msgError.origin = MessageOrigin::Camera;
87 sendMessage(msgError);
89 return {
true, best_x, error};
Simple edge-following algorithm for grayscale camera images.
Definition: CameraEdgeFollower.h:44
Base class for message sources in the TinyRobotics communication framework.
Definition: MessageSource.h:35
Definition: CameraEdgeFollower.h:46
Generic message structure for communication, parameterized by value type.
Definition: Message.h:72