mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Remove SampleRobot (#1658)
SampleRobot provides no benefits over RobotBase to advanced teams and TimedRobot is recommended for everyone else. A skeleton template for RobotBase was added.
This commit is contained in:
committed by
Peter Johnson
parent
62be0392b6
commit
73ec940786
@@ -0,0 +1,66 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "Robot.h"
|
||||
|
||||
#include <hal/DriverStation.h>
|
||||
|
||||
#include <frc/DriverStation.h>
|
||||
#include <frc/livewindow/LiveWindow.h>
|
||||
#include <frc/shuffleboard/Shuffleboard.h>
|
||||
#include <networktables/NetworkTable.h>
|
||||
|
||||
void Robot::RobotInit() {}
|
||||
|
||||
void Robot::Disabled() {}
|
||||
|
||||
void Robot::Autonomous() {}
|
||||
|
||||
void Robot::Teleop() {}
|
||||
|
||||
void Robot::Test() {}
|
||||
|
||||
void Robot::StartCompetition() {
|
||||
auto& lw = *frc::LiveWindow::GetInstance();
|
||||
|
||||
RobotInit();
|
||||
|
||||
// Tell the DS that the robot is ready to be enabled
|
||||
HAL_ObserveUserProgramStarting();
|
||||
|
||||
while (true) {
|
||||
if (IsDisabled()) {
|
||||
m_ds.InDisabled(true);
|
||||
Disabled();
|
||||
m_ds.InDisabled(false);
|
||||
while (IsDisabled()) m_ds.WaitForData();
|
||||
} else if (IsAutonomous()) {
|
||||
m_ds.InAutonomous(true);
|
||||
Autonomous();
|
||||
m_ds.InAutonomous(false);
|
||||
while (IsAutonomous() && IsEnabled()) m_ds.WaitForData();
|
||||
} else if (IsTest()) {
|
||||
lw.SetEnabled(true);
|
||||
frc::Shuffleboard::EnableActuatorWidgets();
|
||||
m_ds.InTest(true);
|
||||
Test();
|
||||
m_ds.InTest(false);
|
||||
while (IsTest() && IsEnabled()) m_ds.WaitForData();
|
||||
lw.SetEnabled(false);
|
||||
frc::Shuffleboard::DisableActuatorWidgets();
|
||||
} else {
|
||||
m_ds.InOperatorControl(true);
|
||||
Teleop();
|
||||
m_ds.InOperatorControl(false);
|
||||
while (IsOperatorControl() && IsEnabled()) m_ds.WaitForData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
int main() { return frc::StartRobot<Robot>(); }
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/RobotBase.h>
|
||||
|
||||
class Robot : public frc::RobotBase {
|
||||
public:
|
||||
void RobotInit();
|
||||
void Disabled();
|
||||
void Autonomous();
|
||||
void Teleop();
|
||||
void Test();
|
||||
|
||||
void StartCompetition() override;
|
||||
};
|
||||
@@ -1,92 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "Robot.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <frc/Timer.h>
|
||||
#include <frc/smartdashboard/SmartDashboard.h>
|
||||
|
||||
Robot::Robot() {
|
||||
// Note SmartDashboard is not initialized here, wait until RobotInit() to make
|
||||
// SmartDashboard calls
|
||||
m_robotDrive.SetExpiration(0.1);
|
||||
}
|
||||
|
||||
void Robot::RobotInit() {
|
||||
m_chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault);
|
||||
m_chooser.AddOption(kAutoNameCustom, kAutoNameCustom);
|
||||
frc::SmartDashboard::PutData("Auto Modes", &m_chooser);
|
||||
}
|
||||
|
||||
/**
|
||||
* This autonomous (along with the chooser code above) shows how to select
|
||||
* between different autonomous modes using the dashboard. The sendable chooser
|
||||
* code works with the Java SmartDashboard. If you prefer the LabVIEW Dashboard,
|
||||
* remove all of the chooser code and uncomment the GetString line to get the
|
||||
* auto name from the text box below the Gyro.
|
||||
*
|
||||
* You can add additional auto modes by adding additional comparisons to the
|
||||
* if-else structure below with additional strings. If using the SendableChooser
|
||||
* make sure to add them to the chooser code above as well.
|
||||
*/
|
||||
void Robot::Autonomous() {
|
||||
std::string autoSelected = m_chooser.GetSelected();
|
||||
// std::string autoSelected = frc::SmartDashboard::GetString(
|
||||
// "Auto Selector", kAutoNameDefault);
|
||||
std::cout << "Auto selected: " << autoSelected << std::endl;
|
||||
|
||||
// MotorSafety improves safety when motors are updated in loops but is
|
||||
// disabled here because motor updates are not looped in this autonomous mode.
|
||||
m_robotDrive.SetSafetyEnabled(false);
|
||||
|
||||
if (autoSelected == kAutoNameCustom) {
|
||||
// Custom Auto goes here
|
||||
std::cout << "Running custom Autonomous" << std::endl;
|
||||
|
||||
// Spin at half speed for two seconds
|
||||
m_robotDrive.ArcadeDrive(0.0, 0.5);
|
||||
frc::Wait(2.0);
|
||||
|
||||
// Stop robot
|
||||
m_robotDrive.ArcadeDrive(0.0, 0.0);
|
||||
} else {
|
||||
// Default Auto goes here
|
||||
std::cout << "Running default Autonomous" << std::endl;
|
||||
|
||||
// Drive forwards at half speed for two seconds
|
||||
m_robotDrive.ArcadeDrive(-0.5, 0.0);
|
||||
frc::Wait(2.0);
|
||||
|
||||
// Stop robot
|
||||
m_robotDrive.ArcadeDrive(0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the motors with arcade steering.
|
||||
*/
|
||||
void Robot::OperatorControl() {
|
||||
m_robotDrive.SetSafetyEnabled(true);
|
||||
while (IsOperatorControl() && IsEnabled()) {
|
||||
// Drive with arcade style (use right stick)
|
||||
m_robotDrive.ArcadeDrive(-m_stick.GetY(), m_stick.GetX());
|
||||
|
||||
// The motors will be updated every 5ms
|
||||
frc::Wait(0.005);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs during test mode
|
||||
*/
|
||||
void Robot::Test() {}
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
int main() { return frc::StartRobot<Robot>(); }
|
||||
#endif
|
||||
@@ -1,49 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <frc/Joystick.h>
|
||||
#include <frc/PWMVictorSPX.h>
|
||||
#include <frc/SampleRobot.h>
|
||||
#include <frc/drive/DifferentialDrive.h>
|
||||
#include <frc/smartdashboard/SendableChooser.h>
|
||||
|
||||
/**
|
||||
* This is a demo program showing the use of the DifferentialDrive class. The
|
||||
* SampleRobot class is the base of a robot application that will automatically
|
||||
* call your Autonomous and OperatorControl methods at the right time as
|
||||
* controlled by the switches on the driver station or the field controls.
|
||||
*
|
||||
* WARNING: While it may look like a good choice to use for your code if you're
|
||||
* inexperienced, don't. Unless you know what you are doing, complex code will
|
||||
* be much more difficult under this system. Use TimedRobot or Command-Based
|
||||
* instead if you're new.
|
||||
*/
|
||||
class Robot : public frc::SampleRobot {
|
||||
public:
|
||||
Robot();
|
||||
|
||||
void RobotInit() override;
|
||||
void Autonomous() override;
|
||||
void OperatorControl() override;
|
||||
void Test() override;
|
||||
|
||||
private:
|
||||
// Robot drive system
|
||||
frc::PWMVictorSPX m_leftMotor{0};
|
||||
frc::PWMVictorSPX m_rightMotor{1};
|
||||
frc::DifferentialDrive m_robotDrive{m_leftMotor, m_rightMotor};
|
||||
|
||||
frc::Joystick m_stick{0};
|
||||
|
||||
frc::SendableChooser<std::string> m_chooser;
|
||||
const std::string kAutoNameDefault = "Default";
|
||||
const std::string kAutoNameCustom = "My Auto";
|
||||
};
|
||||
@@ -26,6 +26,15 @@
|
||||
"foldername": "timedskeleton",
|
||||
"gradlebase": "cpp"
|
||||
},
|
||||
{
|
||||
"name": "RobotBase Skeleton (Advanced)",
|
||||
"description": "Skeleton (stub) code for RobotBase",
|
||||
"tags": [
|
||||
"RobotBase", "Skeleton"
|
||||
],
|
||||
"foldername": "robotbaseskeleton",
|
||||
"gradlebase": "cpp"
|
||||
},
|
||||
{
|
||||
"name": "Command Robot",
|
||||
"description": "Command style",
|
||||
@@ -34,14 +43,5 @@
|
||||
],
|
||||
"foldername": "commandbased",
|
||||
"gradlebase": "cpp"
|
||||
},
|
||||
{
|
||||
"name": "Sample Robot",
|
||||
"description": "Sample style",
|
||||
"tags": [
|
||||
"Sample"
|
||||
],
|
||||
"foldername": "sample",
|
||||
"gradlebase": "cpp"
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user