Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "frc/SampleRobot.h" |
| 9 | |
| 10 | #include <hal/DriverStation.h> |
| 11 | #include <hal/FRCUsageReporting.h> |
| 12 | #include <hal/HALBase.h> |
| 13 | #include <networktables/NetworkTable.h> |
| 14 | #include <wpi/raw_ostream.h> |
| 15 | |
| 16 | #include "frc/DriverStation.h" |
| 17 | #include "frc/Timer.h" |
| 18 | #include "frc/livewindow/LiveWindow.h" |
| 19 | |
| 20 | using namespace frc; |
| 21 | |
| 22 | void SampleRobot::StartCompetition() { |
| 23 | LiveWindow* lw = LiveWindow::GetInstance(); |
| 24 | |
| 25 | RobotInit(); |
| 26 | |
| 27 | // Tell the DS that the robot is ready to be enabled |
| 28 | HAL_ObserveUserProgramStarting(); |
| 29 | |
| 30 | RobotMain(); |
| 31 | |
| 32 | if (!m_robotMainOverridden) { |
| 33 | while (true) { |
| 34 | if (IsDisabled()) { |
| 35 | m_ds.InDisabled(true); |
| 36 | Disabled(); |
| 37 | m_ds.InDisabled(false); |
| 38 | while (IsDisabled()) m_ds.WaitForData(); |
| 39 | } else if (IsAutonomous()) { |
| 40 | m_ds.InAutonomous(true); |
| 41 | Autonomous(); |
| 42 | m_ds.InAutonomous(false); |
| 43 | while (IsAutonomous() && IsEnabled()) m_ds.WaitForData(); |
| 44 | } else if (IsTest()) { |
| 45 | lw->SetEnabled(true); |
| 46 | m_ds.InTest(true); |
| 47 | Test(); |
| 48 | m_ds.InTest(false); |
| 49 | while (IsTest() && IsEnabled()) m_ds.WaitForData(); |
| 50 | lw->SetEnabled(false); |
| 51 | } else { |
| 52 | m_ds.InOperatorControl(true); |
| 53 | OperatorControl(); |
| 54 | m_ds.InOperatorControl(false); |
| 55 | while (IsOperatorControl() && IsEnabled()) m_ds.WaitForData(); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void SampleRobot::RobotInit() { |
| 62 | wpi::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n"; |
| 63 | } |
| 64 | |
| 65 | void SampleRobot::Disabled() { |
| 66 | wpi::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n"; |
| 67 | } |
| 68 | |
| 69 | void SampleRobot::Autonomous() { |
| 70 | wpi::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n"; |
| 71 | } |
| 72 | |
| 73 | void SampleRobot::OperatorControl() { |
| 74 | wpi::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n"; |
| 75 | } |
| 76 | |
| 77 | void SampleRobot::Test() { |
| 78 | wpi::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n"; |
| 79 | } |
| 80 | |
| 81 | void SampleRobot::RobotMain() { m_robotMainOverridden = false; } |
| 82 | |
| 83 | SampleRobot::SampleRobot() { |
| 84 | HAL_Report(HALUsageReporting::kResourceType_Framework, |
| 85 | HALUsageReporting::kFramework_Simple); |
| 86 | } |