Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 1 | #include "frc971/codelab/basic.h" |
| 2 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 3 | namespace frc971::codelab { |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 4 | |
Austin Schuh | 55a13dc | 2019-01-27 22:39:03 -0800 | [diff] [blame] | 5 | Basic::Basic(::aos::EventLoop *event_loop, const ::std::string &name) |
James Kuszmaul | 6175066 | 2021-06-21 21:32:33 -0700 | [diff] [blame] | 6 | : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop, |
| 7 | name) {} |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 8 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 9 | void Basic::RunIteration(const Goal *goal, const Position *position, |
| 10 | aos::Sender<Output>::Builder *output, |
| 11 | aos::Sender<Status>::Builder *status) { |
Sabina Leaver | 7d9220d | 2021-06-30 20:55:15 -0700 | [diff] [blame] | 12 | // FIX HERE: Set the intake_voltage to 12 Volts when |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 13 | // 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 Ostrowski | e1db69f | 2022-07-02 15:49:43 -0700 | [diff] [blame] | 16 | // This line tells the compiler to ignore the fact that goal and |
Sabina Leaver | 7d9220d | 2021-06-30 20:55:15 -0700 | [diff] [blame] | 17 | // 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 Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 19 | (void)goal, (void)position; |
| 20 | |
Jim Ostrowski | e1db69f | 2022-07-02 15:49:43 -0700 | [diff] [blame] | 21 | if (output != nullptr) { |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 22 | Output::Builder builder = output->MakeBuilder<Output>(); |
Sabina Leaver | 7d9220d | 2021-06-30 20:55:15 -0700 | [diff] [blame] | 23 | |
| 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 Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 28 | builder.add_intake_voltage(0.0); |
| 29 | |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 30 | // Ignore the return value of Send |
| 31 | (void)output->Send(builder.Finish()); |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Jim Ostrowski | e1db69f | 2022-07-02 15:49:43 -0700 | [diff] [blame] | 34 | if (status != nullptr) { |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 35 | Status::Builder builder = status->MakeBuilder<Status>(); |
Sabina Leaver | 7d9220d | 2021-06-30 20:55:15 -0700 | [diff] [blame] | 36 | // 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 Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 41 | |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 42 | // Ignore the return value of Send |
| 43 | (void)status->Send(builder.Finish()); |
James Kuszmaul | 78e29ac | 2020-07-28 21:07:03 -0700 | [diff] [blame] | 44 | } |
Parker Schuh | 18dbbb4 | 2017-10-18 21:45:33 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 47 | } // namespace frc971::codelab |