blob: acaec0c61c9b313488f0d59a0fd0ec254eaf7089 [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
Alex Perrycb7da4b2019-08-28 19:35:56 -07007#include "frc971/codelab/basic_generated.h"
Parker Schuh18dbbb42017-10-18 21:45:33 -07008
9namespace frc971 {
10namespace codelab {
11
12// This codelab helps build basic knowledge of how to use 971 control loop
13// primatives.
14//
15// The meat of the task is to make the tests pass.
16//
17// Run the tests with:
18// $ bazel run //frc971/codelab:basic_test -- --gtest_color=yes
19//
20// Control loops all follow the same convention:
21// There are 4 queues (goal, position, status, output).
22//
23// 2 queues are input queues: goal, position.
24// 2 queues are output queues: output, status.
25//
26// ::aos::controls::ControlLoop is a helper class that takes
27// a queue_group type from a .h file, and organizes to call
28// RunIteration() at a consistent interval. It will fetch from
29// goal and position messages from the goal and position queue,
30// and publish an output and status result to the output and status
31// queues.
32//
33// The basic.q file will construct boilerplate c++ code for the
34// Goal, Position, Status, Message
35// types, and construct static variables for fetching these named queues.
36// Inquisitive souls can check out:
37// $ bazel build //frc971/codelab:basic_queue
38// $ vim bazel-genfiles/frc971/codelab/basic.q.{cc,h} -o
39// from the 971-Robot-Code directory.
40//
41// Order of approaching this should be:
42// - Read the BUILD file and learn about what code is being generated.
43// - Read basic.q, and familiarize yourself on the inputs and types involved.
Alex Perrycb7da4b2019-08-28 19:35:56 -070044class Basic
45 : public ::aos::controls::ControlLoop<Goal, Position, Status, Output> {
Parker Schuh18dbbb42017-10-18 21:45:33 -070046 public:
Austin Schuh55a13dc2019-01-27 22:39:03 -080047 explicit Basic(::aos::EventLoop *event_loop,
Alex Perrycb7da4b2019-08-28 19:35:56 -070048 const ::std::string &name = "/codelab");
Parker Schuh18dbbb42017-10-18 21:45:33 -070049
50 protected:
Alex Perrycb7da4b2019-08-28 19:35:56 -070051 void RunIteration(const Goal *goal, const Position *position,
52 aos::Sender<Output>::Builder *output,
53 aos::Sender<Status>::Builder *status) override;
Parker Schuh18dbbb42017-10-18 21:45:33 -070054};
55
56} // namespace codelab
57} // namespace frc971
58
59#endif // FRC971_CODELAB_BASIC_H_