blob: 325db73319a6247366b8a74c6d1de425ad850af2 [file] [log] [blame]
Parker Schuh18dbbb42017-10-18 21:45:33 -07001#include "frc971/codelab/basic.h"
2
3namespace frc971 {
4namespace codelab {
5
Austin Schuh55a13dc2019-01-27 22:39:03 -08006Basic::Basic(::aos::EventLoop *event_loop, const ::std::string &name)
James Kuszmaul61750662021-06-21 21:32:33 -07007 : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
8 name) {}
Parker Schuh18dbbb42017-10-18 21:45:33 -07009
Alex Perrycb7da4b2019-08-28 19:35:56 -070010void Basic::RunIteration(const Goal *goal, const Position *position,
11 aos::Sender<Output>::Builder *output,
12 aos::Sender<Status>::Builder *status) {
Sabina Leaver7d9220d2021-06-30 20:55:15 -070013
14 // FIX HERE: Set the intake_voltage to 12 Volts when
Parker Schuh18dbbb42017-10-18 21:45:33 -070015 // intake is requested (via intake in goal). Make sure not to set
16 // the motor to anything but 0 V when the limit_sensor is pressed.
17
Sabina Leaver7d9220d2021-06-30 20:55:15 -070018 // This line tells the compiler to to ignore the fact that goal and
19 // position are not used in the code. You will need to read these messages
20 // and use their values to determine the necessary output and status.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070021 (void)goal, (void)position;
22
23 if (output) {
24 Output::Builder builder = output->MakeBuilder<Output>();
Sabina Leaver7d9220d2021-06-30 20:55:15 -070025
26 // FIX HERE: As of now, this sets the intake voltage to 0 in
27 // all circumstances. Add to this code to output a different
28 // intake voltage depending on the circumstances to make the
29 // tests pass.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070030 builder.add_intake_voltage(0.0);
31
milind1f1dca32021-07-03 13:50:07 -070032 // Ignore the return value of Send
33 (void)output->Send(builder.Finish());
James Kuszmaul78e29ac2020-07-28 21:07:03 -070034 }
35
36 if (status) {
37 Status::Builder builder = status->MakeBuilder<Status>();
Sabina Leaver7d9220d2021-06-30 20:55:15 -070038 // FIX HERE: Fill out the Status message! In order to fill the
39 // information in the message, use the add_<name of the field>() method
40 // on the builder, just like we do with the Output message above.
41 // Look at the definition of Status in basic_status.fbs to find
42 // the name of the field.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070043
milind1f1dca32021-07-03 13:50:07 -070044 // Ignore the return value of Send
45 (void)status->Send(builder.Finish());
James Kuszmaul78e29ac2020-07-28 21:07:03 -070046 }
Parker Schuh18dbbb42017-10-18 21:45:33 -070047}
48
49} // namespace codelab
50} // namespace frc971