blob: 944048f4c2f49b328b0c5ec5ae39f38c6f3fcefb [file] [log] [blame]
Parker Schuh18dbbb42017-10-18 21:45:33 -07001#ifndef FRC971_CODELAB_BASIC_H_
2#define FRC971_CODELAB_BASIC_H_
3
John Park33858a32018-09-28 23:05:48 -07004#include "aos/controls/control_loop.h"
5#include "aos/time/time.h"
Parker Schuh18dbbb42017-10-18 21:45:33 -07006
James Kuszmaul78e29ac2020-07-28 21:07:03 -07007#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 Schuh18dbbb42017-10-18 21:45:33 -070011
12namespace frc971 {
13namespace 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 Kuszmaul78e29ac2020-07-28 21:07:03 -070024// There are 4 channels (goal, position, status, output).
Parker Schuh18dbbb42017-10-18 21:45:33 -070025//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070026// 2 channels are input channels: goal, position.
27// 2 channels are output channels: output, status.
Parker Schuh18dbbb42017-10-18 21:45:33 -070028//
29// ::aos::controls::ControlLoop is a helper class that takes
James Kuszmaul78e29ac2020-07-28 21:07:03 -070030// 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 Schuh18dbbb42017-10-18 21:45:33 -070035//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070036// The various basic_*.fbs files define the Goal, Position, Status, and Output
37// messages.
Parker Schuh18dbbb42017-10-18 21:45:33 -070038//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070039// 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 Perrycb7da4b2019-08-28 19:35:56 -070051class Basic
52 : public ::aos::controls::ControlLoop<Goal, Position, Status, Output> {
Parker Schuh18dbbb42017-10-18 21:45:33 -070053 public:
Austin Schuh55a13dc2019-01-27 22:39:03 -080054 explicit Basic(::aos::EventLoop *event_loop,
Alex Perrycb7da4b2019-08-28 19:35:56 -070055 const ::std::string &name = "/codelab");
Parker Schuh18dbbb42017-10-18 21:45:33 -070056
57 protected:
Alex Perrycb7da4b2019-08-28 19:35:56 -070058 void RunIteration(const Goal *goal, const Position *position,
59 aos::Sender<Output>::Builder *output,
60 aos::Sender<Status>::Builder *status) override;
Parker Schuh18dbbb42017-10-18 21:45:33 -070061};
62
63} // namespace codelab
64} // namespace frc971
65
66#endif // FRC971_CODELAB_BASIC_H_