|
| 1 | +// Copyright (c) FIRST and other WPILib contributors. |
| 2 | +// Open Source Software; you can modify and/or share it under the terms of |
| 3 | +// the WPILib BSD license file in the root directory of this project. |
| 4 | + |
| 5 | +#include "Robot.h" |
| 6 | + |
| 7 | +#include <fmt/core.h> |
| 8 | +#include <frc/livewindow/LiveWindow.h> |
| 9 | +#include <frc/smartdashboard/SmartDashboard.h> |
| 10 | + |
| 11 | +// Run robot periodic() functions for 5 ms, and run controllers every 10 ms |
| 12 | +Robot::Robot() : frc::TimesliceRobot{5_ms, 10_ms} { |
| 13 | + // LiveWindow causes drastic overruns in robot periodic functions that will |
| 14 | + // interfere with controllers |
| 15 | + frc::LiveWindow::DisableAllTelemetry(); |
| 16 | + |
| 17 | + // Runs for 2 ms after robot periodic functions |
| 18 | + Schedule([=] {}, 2_ms); |
| 19 | + |
| 20 | + // Runs for 2 ms after first controller function |
| 21 | + Schedule([=] {}, 2_ms); |
| 22 | + |
| 23 | + // Total usage: |
| 24 | + // 5 ms (robot) + 2 ms (controller 1) + 2 ms (controller 2) = 9 ms |
| 25 | + // 9 ms / 10 ms -> 90% allocated |
| 26 | +} |
| 27 | + |
| 28 | +void Robot::RobotInit() { |
| 29 | + m_chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault); |
| 30 | + m_chooser.AddOption(kAutoNameCustom, kAutoNameCustom); |
| 31 | + frc::SmartDashboard::PutData("Auto Modes", &m_chooser); |
| 32 | +} |
| 33 | + |
| 34 | +/** |
| 35 | + * This function is called every robot packet, no matter the mode. Use |
| 36 | + * this for items like diagnostics that you want ran during disabled, |
| 37 | + * autonomous, teleoperated and test. |
| 38 | + * |
| 39 | + * <p> This runs after the mode specific periodic functions, but before |
| 40 | + * LiveWindow and SmartDashboard integrated updating. |
| 41 | + */ |
| 42 | +void Robot::RobotPeriodic() {} |
| 43 | + |
| 44 | +/** |
| 45 | + * This autonomous (along with the chooser code above) shows how to select |
| 46 | + * between different autonomous modes using the dashboard. The sendable chooser |
| 47 | + * code works with the Java SmartDashboard. If you prefer the LabVIEW Dashboard, |
| 48 | + * remove all of the chooser code and uncomment the GetString line to get the |
| 49 | + * auto name from the text box below the Gyro. |
| 50 | + * |
| 51 | + * You can add additional auto modes by adding additional comparisons to the |
| 52 | + * if-else structure below with additional strings. If using the SendableChooser |
| 53 | + * make sure to add them to the chooser code above as well. |
| 54 | + */ |
| 55 | +void Robot::AutonomousInit() { |
| 56 | + m_autoSelected = m_chooser.GetSelected(); |
| 57 | + // m_autoSelected = SmartDashboard::GetString("Auto Selector", |
| 58 | + // kAutoNameDefault); |
| 59 | + fmt::print("Auto selected: {}\n", m_autoSelected); |
| 60 | + |
| 61 | + if (m_autoSelected == kAutoNameCustom) { |
| 62 | + // Custom Auto goes here |
| 63 | + } else { |
| 64 | + // Default Auto goes here |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +void Robot::AutonomousPeriodic() { |
| 69 | + if (m_autoSelected == kAutoNameCustom) { |
| 70 | + // Custom Auto goes here |
| 71 | + } else { |
| 72 | + // Default Auto goes here |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +void Robot::TeleopInit() {} |
| 77 | + |
| 78 | +void Robot::TeleopPeriodic() {} |
| 79 | + |
| 80 | +void Robot::DisabledInit() {} |
| 81 | + |
| 82 | +void Robot::DisabledPeriodic() {} |
| 83 | + |
| 84 | +void Robot::TestInit() {} |
| 85 | + |
| 86 | +void Robot::TestPeriodic() {} |
| 87 | + |
| 88 | +#ifndef RUNNING_FRC_TESTS |
| 89 | +int main() { |
| 90 | + return frc::StartRobot<Robot>(); |
| 91 | +} |
| 92 | +#endif |
0 commit comments