blob: 66f08f9046cfadfb47485bf63d44c45d2af2262e [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 // FIX HERE: Set the intake_voltage to 12 Volts when
Parker Schuh18dbbb42017-10-18 21:45:33 -070014 // intake is requested (via intake in goal). Make sure not to set
15 // the motor to anything but 0 V when the limit_sensor is pressed.
16
Jim Ostrowskie1db69f2022-07-02 15:49:43 -070017 // This line tells the compiler to ignore the fact that goal and
Sabina Leaver7d9220d2021-06-30 20:55:15 -070018 // position are not used in the code. You will need to read these messages
19 // and use their values to determine the necessary output and status.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070020 (void)goal, (void)position;
21
Jim Ostrowskie1db69f2022-07-02 15:49:43 -070022 if (output != nullptr) {
James Kuszmaul78e29ac2020-07-28 21:07:03 -070023 Output::Builder builder = output->MakeBuilder<Output>();
Sabina Leaver7d9220d2021-06-30 20:55:15 -070024
25 // FIX HERE: As of now, this sets the intake voltage to 0 in
26 // all circumstances. Add to this code to output a different
27 // intake voltage depending on the circumstances to make the
28 // tests pass.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070029 builder.add_intake_voltage(0.0);
30
milind1f1dca32021-07-03 13:50:07 -070031 // Ignore the return value of Send
32 (void)output->Send(builder.Finish());
James Kuszmaul78e29ac2020-07-28 21:07:03 -070033 }
34
Jim Ostrowskie1db69f2022-07-02 15:49:43 -070035 if (status != nullptr) {
James Kuszmaul78e29ac2020-07-28 21:07:03 -070036 Status::Builder builder = status->MakeBuilder<Status>();
Sabina Leaver7d9220d2021-06-30 20:55:15 -070037 // FIX HERE: Fill out the Status message! In order to fill the
38 // information in the message, use the add_<name of the field>() method
39 // on the builder, just like we do with the Output message above.
40 // Look at the definition of Status in basic_status.fbs to find
41 // the name of the field.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070042
milind1f1dca32021-07-03 13:50:07 -070043 // Ignore the return value of Send
44 (void)status->Send(builder.Finish());
James Kuszmaul78e29ac2020-07-28 21:07:03 -070045 }
Parker Schuh18dbbb42017-10-18 21:45:33 -070046}
47
48} // namespace codelab
49} // namespace frc971