blob: a78da41302d9dccae5b880da601cb7350ea213ac [file] [log] [blame]
Parker Schuh18dbbb42017-10-18 21:45:33 -07001#include "frc971/codelab/basic.h"
2
Stephan Pleinesf63bde82024-01-13 15:59:33 -08003namespace frc971::codelab {
Parker Schuh18dbbb42017-10-18 21:45:33 -07004
Austin Schuh55a13dc2019-01-27 22:39:03 -08005Basic::Basic(::aos::EventLoop *event_loop, const ::std::string &name)
James Kuszmaul61750662021-06-21 21:32:33 -07006 : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
7 name) {}
Parker Schuh18dbbb42017-10-18 21:45:33 -07008
Alex Perrycb7da4b2019-08-28 19:35:56 -07009void Basic::RunIteration(const Goal *goal, const Position *position,
10 aos::Sender<Output>::Builder *output,
11 aos::Sender<Status>::Builder *status) {
Sabina Leaver7d9220d2021-06-30 20:55:15 -070012 // FIX HERE: Set the intake_voltage to 12 Volts when
Parker Schuh18dbbb42017-10-18 21:45:33 -070013 // intake is requested (via intake in goal). Make sure not to set
14 // the motor to anything but 0 V when the limit_sensor is pressed.
15
Jim Ostrowskie1db69f2022-07-02 15:49:43 -070016 // This line tells the compiler to ignore the fact that goal and
Sabina Leaver7d9220d2021-06-30 20:55:15 -070017 // position are not used in the code. You will need to read these messages
18 // and use their values to determine the necessary output and status.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070019 (void)goal, (void)position;
20
Jim Ostrowskie1db69f2022-07-02 15:49:43 -070021 if (output != nullptr) {
James Kuszmaul78e29ac2020-07-28 21:07:03 -070022 Output::Builder builder = output->MakeBuilder<Output>();
Sabina Leaver7d9220d2021-06-30 20:55:15 -070023
24 // FIX HERE: As of now, this sets the intake voltage to 0 in
25 // all circumstances. Add to this code to output a different
26 // intake voltage depending on the circumstances to make the
27 // tests pass.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070028 builder.add_intake_voltage(0.0);
29
milind1f1dca32021-07-03 13:50:07 -070030 // Ignore the return value of Send
31 (void)output->Send(builder.Finish());
James Kuszmaul78e29ac2020-07-28 21:07:03 -070032 }
33
Jim Ostrowskie1db69f2022-07-02 15:49:43 -070034 if (status != nullptr) {
James Kuszmaul78e29ac2020-07-28 21:07:03 -070035 Status::Builder builder = status->MakeBuilder<Status>();
Sabina Leaver7d9220d2021-06-30 20:55:15 -070036 // FIX HERE: Fill out the Status message! In order to fill the
37 // information in the message, use the add_<name of the field>() method
38 // on the builder, just like we do with the Output message above.
39 // Look at the definition of Status in basic_status.fbs to find
40 // the name of the field.
James Kuszmaul78e29ac2020-07-28 21:07:03 -070041
milind1f1dca32021-07-03 13:50:07 -070042 // Ignore the return value of Send
43 (void)status->Send(builder.Finish());
James Kuszmaul78e29ac2020-07-28 21:07:03 -070044 }
Parker Schuh18dbbb42017-10-18 21:45:33 -070045}
46
Stephan Pleinesf63bde82024-01-13 15:59:33 -080047} // namespace frc971::codelab