blob: d2ab3e559d2d891d8acf6c27f1b4dc72072a25ab [file] [log] [blame]
Brian Silverman1c0612e2019-01-26 17:26:08 -08001#ifndef Y2019_JEVOIS_STRUCTURES_H_
2#define Y2019_JEVOIS_STRUCTURES_H_
3
4#include <stdint.h>
5
6#include <array>
7#include <bitset>
8#include <chrono>
9
10#include "Eigen/Dense"
11
12#include "aos/containers/sized_array.h"
13
14namespace frc971 {
15namespace jevois {
16
17// The overall flow to get data to the roboRIO consists of:
18// 1. Camera captures a frame and grabs an absolute timestamp.
19// 2. Camera processes the frame.
20// 3. Camera grabs another absolute timestamp and subtracts to get a
21// camera_duration.
22// 4. Camera sends the frame via UART to the Teensy.
23// 5. Teensy grabs an absolute timestamp for the first character received.
24// 6. Teensy buffers at most one frame from each camera.
25// 7. roboRIO toggles the CS line.
26// 8. Teensy grabs an absolute timestamp for CS being asserted.
27// 9. Teensy pulls together up to three frames and adds the time each one
28// spent in its queue to the timestamps, and queues them in its SPI
29// peripheral. This all happens before the roboRIO has enough time to start
30// actually moving data.
31// 10. roboRIO transfers the frames, and sends back light/status commands.
32
33using camera_duration = std::chrono::duration<uint8_t, std::milli>;
34
35// This file declares the shared datastructures for the JeVois-based image
36// system.
37//
38// Note that floating-point numbers are represented with floats. This is because
39// a float has more bits than we need for anything, and the Teensy can't handle
40// doubles very quickly. It would probably be quick enough, but it's easier to
41// just use floats and not worry about it.
42
43struct Target {
44 // Distance to the target in meters. Specifically, the distance from the
45 // center of the camera's image plane to the center of the target.
46 float distance;
47
48 // Height of the target in meters. Specifically, the distance from the floor
49 // to the center of the target.
50 float height;
51
52 // Heading of the center of the target in radians. Zero is straight out
53 // perpendicular to the camera's image plane. Images to the left (looking at a
54 // camera image) are at a positive angle.
55 float heading;
56
57 // The angle between the target and the camera's image plane. This is
58 // projected so both are assumed to be perpendicular to the floor. Parallel
59 // targets have a skew of zero. Targets rotated such that their left edge
60 // (looking at a camera image) is closer are at a positive angle.
61 float skew;
62};
63
64// The information extracted from a single camera frame.
65//
66// This is all the information sent from each camera to the Teensy.
67struct Frame {
68 // The top most interesting targets found in this frame.
69 aos::SizedArray<Target, 3> targets;
70
71 // How long ago from the current time this frame was captured.
72 camera_duration age;
73};
74
75// This is all the information sent from the Teensy to each camera.
76struct CameraCalibration {
77 // The calibration matrix. This defines where the camera is pointing.
78 //
79 // TODO(Parker): What are the details on how this is defined.
80 Eigen::Matrix<float, 3, 4> calibration;
81};
82
83// This is all the information the Teensy sends to the RoboRIO.
84struct TeensyToRoborio {
85 // The newest frames received from up to three cameras. These will be the
86 // three earliest-received of all buffered frames.
87 aos::SizedArray<Frame, 3> frames;
88};
89
90// This is all the information the RoboRIO sends to the Teensy.
91struct RoborioToTeensy {
92 // Brightnesses for each of the beacon light channels. 0 is off, 255 is fully
93 // on.
94 std::array<uint8_t, 3> beacon_brightness;
95
96 // Whether the light ring for each camera should be on.
97 std::bitset<5> light_rings;
98};
99
100} // namespace jevois
101} // namespace frc971
102
103#endif // Y2019_JEVOIS_STRUCTURES_H_