blob: 8748bc5a1e78fdaae9ea322c295b96aebd534d32 [file] [log] [blame]
Parker Schuh18dbbb42017-10-18 21:45:33 -07001#ifndef FRC971_CODELAB_BASIC_H_
2#define FRC971_CODELAB_BASIC_H_
3
James Kuszmaul61750662021-06-21 21:32:33 -07004#include "frc971/control_loops/control_loop.h"
John Park33858a32018-09-28 23:05:48 -07005#include "aos/time/time.h"
James Kuszmaul78e29ac2020-07-28 21:07:03 -07006#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 Schuh18dbbb42017-10-18 21:45:33 -070010
11namespace frc971 {
12namespace codelab {
13
14// This codelab helps build basic knowledge of how to use 971 control loop
15// primatives.
16//
Austin Schuh40546402020-09-23 20:58:09 -070017// For flatbuffers background, we recommend checking out
18// https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html
19//
Parker Schuh18dbbb42017-10-18 21:45:33 -070020// 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 Kuszmaul78e29ac2020-07-28 21:07:03 -070026// There are 4 channels (goal, position, status, output).
Parker Schuh18dbbb42017-10-18 21:45:33 -070027//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070028// 2 channels are input channels: goal, position.
29// 2 channels are output channels: output, status.
Parker Schuh18dbbb42017-10-18 21:45:33 -070030//
James Kuszmaul61750662021-06-21 21:32:33 -070031// ::frc971::controls::ControlLoop is a helper class that takes
James Kuszmaul78e29ac2020-07-28 21:07:03 -070032// 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 Schuh18dbbb42017-10-18 21:45:33 -070037//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070038// The various basic_*.fbs files define the Goal, Position, Status, and Output
39// messages.
Parker Schuh18dbbb42017-10-18 21:45:33 -070040//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070041// 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 Perrycb7da4b2019-08-28 19:35:56 -070053class Basic
James Kuszmaul61750662021-06-21 21:32:33 -070054 : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
Parker Schuh18dbbb42017-10-18 21:45:33 -070055 public:
Austin Schuh55a13dc2019-01-27 22:39:03 -080056 explicit Basic(::aos::EventLoop *event_loop,
Alex Perrycb7da4b2019-08-28 19:35:56 -070057 const ::std::string &name = "/codelab");
Parker Schuh18dbbb42017-10-18 21:45:33 -070058
59 protected:
Alex Perrycb7da4b2019-08-28 19:35:56 -070060 void RunIteration(const Goal *goal, const Position *position,
61 aos::Sender<Output>::Builder *output,
62 aos::Sender<Status>::Builder *status) override;
Parker Schuh18dbbb42017-10-18 21:45:33 -070063};
64
65} // namespace codelab
66} // namespace frc971
67
68#endif // FRC971_CODELAB_BASIC_H_