2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
panel.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <frc/AddressableLED.h>
8
9#include <algorithm>
10#include <vector>
11
12namespace argos_lib {
13 namespace led {
17 template <typename T>
18 class Array2D {
19 public:
23 Array2D() = delete;
31 Array2D(unsigned width, unsigned height, T fillValue = {}) : m_cells(width, std::vector<T>(height, fillValue)) {}
32
43 T& at(unsigned x, unsigned y) { return m_cells.at(x).at(y); }
44
56 const T& at(unsigned x, unsigned y) const { return m_cells.at(x).at(y); }
57
63 unsigned Width() const noexcept { return m_cells.size(); }
64
70 unsigned Height() const noexcept {
71 try {
72 return m_cells.at(0).size();
73 } catch (const std::out_of_range&) {
74 // Handle empty vector even though this shouldn't ever happen with deleted default constructor
75 return 0;
76 }
77 }
78
79 private:
80 std::vector<std::vector<T>>
82 };
83
87
91 using Strip = std::vector<frc::AddressableLED::LEDData>;
92
100
105
110
120 Strip Serialize(const Panel& panel, const PanelScanParams& params);
121
122 } // namespace led
123} // namespace argos_lib
Array2D representation where origin is at bottom left.
Definition panel.h:18
unsigned Height() const noexcept
Cells in vertical dimension.
Definition panel.h:70
std::vector< std::vector< T > > m_cells
2D grid of cells. Kept private in case we actually get an ND-Array that would be better than this vec...
Definition panel.h:81
unsigned Width() const noexcept
Cells in horizontal dimension.
Definition panel.h:63
const T & at(unsigned x, unsigned y) const
Const reference to cell at a given coordinate. Useful to read a value and allowing the compiler to pr...
Definition panel.h:56
T & at(unsigned x, unsigned y)
Get mutable reference to cell at a given coordinate.
Definition panel.h:43
Array2D(unsigned width, unsigned height, T fillValue={})
Construct a new Array2D object.
Definition panel.h:31
Array2D()=delete
Disable default constructor because we need dimensions.
address::comp_bot::led led
Definition addresses.h:74
PrimaryScanDirection
When representing a panel as a strip, sequential addresses are in this direction. Note that the actua...
Definition panel.h:99
Strip Serialize(const Panel &panel, const PanelScanParams &params)
Convert a panel to a 1D vector of pixels in addressing order. This is a helper function because many ...
Definition panel.cpp:7
FirstPixelPosition
When representing a panel as a strip, which pixel is the first address.
Definition panel.h:104
std::vector< frc::AddressableLED::LEDData > Strip
A strip of LEDs.
Definition panel.h:91
Definition swap_controllers_command.h:12
Definition panel.h:106
PrimaryScanDirection scanDirection
Sequential address direction.
Definition panel.h:108
FirstPixelPosition firstPixel
Location of lowest address pixel.
Definition panel.h:107