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