Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 1 | #ifndef FRC971_CODELAB_BASIC_H_ |
| 2 | #define FRC971_CODELAB_BASIC_H_ |
| 3 | |
James Kuszmaul | 6175066 | 2021-06-21 21:32:33 -0700 | [diff] [blame^] | 4 | #include "frc971/control_loops/control_loop.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 5 | #include "aos/time/time.h" |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 6 | #include "frc971/codelab/basic_goal_generated.h" |
| 7 | #include "frc971/codelab/basic_output_generated.h" |
| 8 | #include "frc971/codelab/basic_position_generated.h" |
| 9 | #include "frc971/codelab/basic_status_generated.h" |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 10 | |
| 11 | namespace frc971 { |
| 12 | namespace codelab { |
| 13 | |
| 14 | // This codelab helps build basic knowledge of how to use 971 control loop |
| 15 | // primatives. |
| 16 | // |
Austin Schuh | 4054640 | 2020-09-23 20:58:09 -0700 | [diff] [blame] | 17 | // For flatbuffers background, we recommend checking out |
| 18 | // https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html |
| 19 | // |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 20 | // The meat of the task is to make the tests pass. |
| 21 | // |
| 22 | // Run the tests with: |
| 23 | // $ bazel run //frc971/codelab:basic_test -- --gtest_color=yes |
| 24 | // |
| 25 | // Control loops all follow the same convention: |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 26 | // There are 4 channels (goal, position, status, output). |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 27 | // |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 28 | // 2 channels are input channels: goal, position. |
| 29 | // 2 channels are output channels: output, status. |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 30 | // |
James Kuszmaul | 6175066 | 2021-06-21 21:32:33 -0700 | [diff] [blame^] | 31 | // ::frc971::controls::ControlLoop is a helper class that takes |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 32 | // all the channel types as template parameters and then calls |
| 33 | // RunIteration() whenever a Position message is received. |
| 34 | // It will pass in the Position message and most recent Goal message |
| 35 | // and provide Builders that the RunIteration method should use to |
| 36 | // construct and send output/status messages. |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 37 | // |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 38 | // The various basic_*.fbs files define the Goal, Position, Status, and Output |
| 39 | // messages. |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 40 | // |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 41 | // In order to get the tests to pass, you'll need to fill out the RunIteration() |
| 42 | // implementation in basic.cc so that it uses the input goal/position to |
| 43 | // meaningfully populate the output/status messages. You can find descriptions |
| 44 | // of exactly what the fields of the messages mean by reading all the *.fbs |
| 45 | // files, and the tests below can be reviewed to help understand exactly what |
| 46 | // behavior is expected. |
| 47 | // |
| 48 | // Once you can get the tests to pass, follow the directions in the |
| 49 | // documentation/tutorials/submitting-code-for-a-review.md file for creating a |
| 50 | // code review of this change. We will not actually *submit* the change (since |
| 51 | // that would remove the challenge for future students), but we will go through |
| 52 | // the code review process. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 53 | class Basic |
James Kuszmaul | 6175066 | 2021-06-21 21:32:33 -0700 | [diff] [blame^] | 54 | : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> { |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 55 | public: |
Austin Schuh | 55a13dc | 2019-01-27 22:39:03 -0800 | [diff] [blame] | 56 | explicit Basic(::aos::EventLoop *event_loop, |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 57 | const ::std::string &name = "/codelab"); |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 58 | |
| 59 | protected: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 60 | void RunIteration(const Goal *goal, const Position *position, |
| 61 | aos::Sender<Output>::Builder *output, |
| 62 | aos::Sender<Status>::Builder *status) override; |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace codelab |
| 66 | } // namespace frc971 |
| 67 | |
| 68 | #endif // FRC971_CODELAB_BASIC_H_ |