blob: b75a87fd6b4da2dd75e7f1a7f38dcce080188cf4 [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//
Austin Schuh40546402020-09-23 20:58:09 -070018// For flatbuffers background, we recommend checking out
19// https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html
20//
Parker Schuh18dbbb42017-10-18 21:45:33 -070021// The meat of the task is to make the tests pass.
22//
23// Run the tests with:
24// $ bazel run //frc971/codelab:basic_test -- --gtest_color=yes
25//
26// Control loops all follow the same convention:
James Kuszmaul78e29ac2020-07-28 21:07:03 -070027// There are 4 channels (goal, position, status, output).
Parker Schuh18dbbb42017-10-18 21:45:33 -070028//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070029// 2 channels are input channels: goal, position.
30// 2 channels are output channels: output, status.
Parker Schuh18dbbb42017-10-18 21:45:33 -070031//
32// ::aos::controls::ControlLoop is a helper class that takes
James Kuszmaul78e29ac2020-07-28 21:07:03 -070033// all the channel types as template parameters and then calls
34// RunIteration() whenever a Position message is received.
35// It will pass in the Position message and most recent Goal message
36// and provide Builders that the RunIteration method should use to
37// construct and send output/status messages.
Parker Schuh18dbbb42017-10-18 21:45:33 -070038//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070039// The various basic_*.fbs files define the Goal, Position, Status, and Output
40// messages.
Parker Schuh18dbbb42017-10-18 21:45:33 -070041//
James Kuszmaul78e29ac2020-07-28 21:07:03 -070042// In order to get the tests to pass, you'll need to fill out the RunIteration()
43// implementation in basic.cc so that it uses the input goal/position to
44// meaningfully populate the output/status messages. You can find descriptions
45// of exactly what the fields of the messages mean by reading all the *.fbs
46// files, and the tests below can be reviewed to help understand exactly what
47// behavior is expected.
48//
49// Once you can get the tests to pass, follow the directions in the
50// documentation/tutorials/submitting-code-for-a-review.md file for creating a
51// code review of this change. We will not actually *submit* the change (since
52// that would remove the challenge for future students), but we will go through
53// the code review process.
Alex Perrycb7da4b2019-08-28 19:35:56 -070054class Basic
55 : public ::aos::controls::ControlLoop<Goal, Position, Status, Output> {
Parker Schuh18dbbb42017-10-18 21:45:33 -070056 public:
Austin Schuh55a13dc2019-01-27 22:39:03 -080057 explicit Basic(::aos::EventLoop *event_loop,
Alex Perrycb7da4b2019-08-28 19:35:56 -070058 const ::std::string &name = "/codelab");
Parker Schuh18dbbb42017-10-18 21:45:33 -070059
60 protected:
Alex Perrycb7da4b2019-08-28 19:35:56 -070061 void RunIteration(const Goal *goal, const Position *position,
62 aos::Sender<Output>::Builder *output,
63 aos::Sender<Status>::Builder *status) override;
Parker Schuh18dbbb42017-10-18 21:45:33 -070064};
65
66} // namespace codelab
67} // namespace frc971
68
69#endif // FRC971_CODELAB_BASIC_H_