mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Add cpp examples (#659)
* Added C++ robot project examples and set up sub .clang-format for them * Ran formatter
This commit is contained in:
committed by
Peter Johnson
parent
66002d6cac
commit
0291a95f68
@@ -3,7 +3,7 @@ include 'ni-libraries'
|
||||
include 'hal'
|
||||
include 'wpilibc'
|
||||
include 'wpilibcIntegrationTests'
|
||||
include 'wpilibc-examples'
|
||||
include 'wpilibcExamples'
|
||||
include 'wpilibj'
|
||||
include 'wpilibjIntegrationTests'
|
||||
include 'wpilibjExamples'
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
import org.gradle.language.base.internal.ProjectLayout
|
||||
|
||||
if (!project.hasProperty('skipAthena')) {
|
||||
apply plugin: 'cpp'
|
||||
apply plugin: 'visual-studio'
|
||||
apply plugin: 'edu.wpi.first.NativeUtils'
|
||||
|
||||
apply from: '../config.gradle'
|
||||
|
||||
ext.examplesMap = [:]
|
||||
|
||||
def tree = file("$projectDir/src")
|
||||
tree.list().each {
|
||||
examplesMap.put(it, [])
|
||||
}
|
||||
|
||||
model {
|
||||
dependencyConfigs {
|
||||
wpiutil(DependencyConfig) {
|
||||
groupId = 'edu.wpi.first.wpiutil'
|
||||
artifactId = 'wpiutil-cpp'
|
||||
headerClassifier = 'headers'
|
||||
ext = 'zip'
|
||||
version = '3.+'
|
||||
sharedConfigs = examplesMap
|
||||
}
|
||||
ntcore(DependencyConfig) {
|
||||
groupId = 'edu.wpi.first.ntcore'
|
||||
artifactId = 'ntcore-cpp'
|
||||
headerClassifier = 'headers'
|
||||
ext = 'zip'
|
||||
version = '4.+'
|
||||
sharedConfigs = examplesMap
|
||||
}
|
||||
opencv(DependencyConfig) {
|
||||
groupId = 'org.opencv'
|
||||
artifactId = 'opencv-cpp'
|
||||
headerClassifier = 'headers'
|
||||
ext = 'zip'
|
||||
version = '3.2.0'
|
||||
sharedConfigs = examplesMap
|
||||
}
|
||||
cscore(DependencyConfig) {
|
||||
groupId = 'edu.wpi.first.cscore'
|
||||
artifactId = 'cscore-cpp'
|
||||
headerClassifier = 'headers'
|
||||
ext = 'zip'
|
||||
version = '1.+'
|
||||
sharedConfigs = examplesMap
|
||||
}
|
||||
}
|
||||
|
||||
components {
|
||||
examplesMap.each {
|
||||
"${it.key}"(NativeLibrarySpec) {
|
||||
binaries.all { binary->
|
||||
if (binary.targetPlatform.architecture.name == 'athena') {
|
||||
project(':ni-libraries').addNiLibrariesToLinker(binary)
|
||||
binary.lib project: ':hal', library: 'halAthena', linkage: 'shared'
|
||||
binary.lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
|
||||
} else {
|
||||
binary.buildable = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
76
wpilibcExamples/.clang-format
Normal file
76
wpilibcExamples/.clang-format
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -8
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlinesLeft: true
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping: {AfterClass: false, AfterControlStatement: false, AfterEnum: false,
|
||||
AfterFunction: true, AfterNamespace: false, AfterObjCDeclaration: false, AfterStruct: false,
|
||||
AfterUnion: false, BeforeCatch: false, BeforeElse: false, IndentBraces: false}
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakConstructorInitializersBeforeComma: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 16
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: true
|
||||
ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
|
||||
IncludeCategories:
|
||||
- {Priority: 2, Regex: ^"(llvm|llvm-c|clang|clang-c)/}
|
||||
- {Priority: 3, Regex: ^(<|"(gtest|isl|json)/)}
|
||||
- {Priority: 1, Regex: .*}
|
||||
IndentCaseLabels: true
|
||||
IndentWidth: 8
|
||||
IndentWrappedFunctionNames: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: Inner
|
||||
ObjCBlockIndentWidth: 0
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 345
|
||||
PenaltyBreakFirstLessLess: 150
|
||||
PenaltyBreakString: 618
|
||||
PenaltyExcessCharacter: 977572
|
||||
PenaltyReturnTypeOnItsOwnLine: 41
|
||||
PointerAlignment: Left
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: true
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 8
|
||||
UseTab: Always
|
||||
...
|
||||
45
wpilibcExamples/.styleguide
Normal file
45
wpilibcExamples/.styleguide
Normal file
@@ -0,0 +1,45 @@
|
||||
cppHeaderFileInclude {
|
||||
\.h$
|
||||
\.hpp$
|
||||
\.inc$
|
||||
}
|
||||
|
||||
cppSrcFileInclude {
|
||||
\.cpp$
|
||||
}
|
||||
|
||||
generatedFileExclude {
|
||||
gmock/
|
||||
ni-libraries/include/
|
||||
ni-libraries/lib/
|
||||
hal/src/main/native/athena/ctre/
|
||||
hal/src/main/native/athena/frccansae/
|
||||
hal/src/main/native/athena/visa/
|
||||
hal/src/main/native/include/ctre/
|
||||
UsageReporting\.h$
|
||||
}
|
||||
|
||||
modifiableFileExclude {
|
||||
wpilibj/src/arm-linux-jni/
|
||||
wpilibj/src/main/native/cpp/
|
||||
\.patch$
|
||||
\.png$
|
||||
\.py$
|
||||
\.so$
|
||||
}
|
||||
|
||||
includeGuardRoots {
|
||||
wpilibcExamples/src/main/cpp/examples/
|
||||
wpilibcExamples/src/main/cpp/templates/
|
||||
}
|
||||
|
||||
includeOtherLibs {
|
||||
^HAL/
|
||||
^llvm/
|
||||
^opencv2/
|
||||
^support/
|
||||
}
|
||||
|
||||
includeProject {
|
||||
^ctre/
|
||||
}
|
||||
113
wpilibcExamples/build.gradle
Normal file
113
wpilibcExamples/build.gradle
Normal file
@@ -0,0 +1,113 @@
|
||||
import org.gradle.language.base.internal.ProjectLayout
|
||||
|
||||
if (!project.hasProperty('skipAthena')) {
|
||||
apply plugin: 'cpp'
|
||||
apply plugin: 'visual-studio'
|
||||
apply plugin: 'edu.wpi.first.NativeUtils'
|
||||
|
||||
apply from: '../config.gradle'
|
||||
|
||||
ext.examplesMap = [:]
|
||||
ext.templatesMap = [:]
|
||||
|
||||
File examplesTree = file("$projectDir/src/main/cpp/examples")
|
||||
examplesTree.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File current, String name) {
|
||||
return new File(current, name).isDirectory();
|
||||
}
|
||||
}).each {
|
||||
examplesMap.put(it, [])
|
||||
}
|
||||
File templatesTree = file("$projectDir/src/main/cpp/templates")
|
||||
templatesTree.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File current, String name) {
|
||||
return new File(current, name).isDirectory();
|
||||
}
|
||||
}).each {
|
||||
templatesMap.put(it, [])
|
||||
}
|
||||
|
||||
model {
|
||||
dependencyConfigs {
|
||||
wpiutil(DependencyConfig) {
|
||||
groupId = 'edu.wpi.first.wpiutil'
|
||||
artifactId = 'wpiutil-cpp'
|
||||
headerClassifier = 'headers'
|
||||
ext = 'zip'
|
||||
version = '3.+'
|
||||
sharedConfigs = examplesMap + templatesMap
|
||||
}
|
||||
ntcore(DependencyConfig) {
|
||||
groupId = 'edu.wpi.first.ntcore'
|
||||
artifactId = 'ntcore-cpp'
|
||||
headerClassifier = 'headers'
|
||||
ext = 'zip'
|
||||
version = '4.+'
|
||||
sharedConfigs = examplesMap + templatesMap
|
||||
}
|
||||
opencv(DependencyConfig) {
|
||||
groupId = 'org.opencv'
|
||||
artifactId = 'opencv-cpp'
|
||||
headerClassifier = 'headers'
|
||||
ext = 'zip'
|
||||
version = '3.2.0'
|
||||
sharedConfigs = examplesMap + templatesMap
|
||||
}
|
||||
cscore(DependencyConfig) {
|
||||
groupId = 'edu.wpi.first.cscore'
|
||||
artifactId = 'cscore-cpp'
|
||||
headerClassifier = 'headers'
|
||||
ext = 'zip'
|
||||
version = '1.+'
|
||||
sharedConfigs = examplesMap + templatesMap
|
||||
}
|
||||
}
|
||||
|
||||
components {
|
||||
examplesMap.each { key, value->
|
||||
"${key}"(NativeExecutableSpec) {
|
||||
binaries.all { binary->
|
||||
if (binary.targetPlatform.architecture.name == 'athena') {
|
||||
project(':ni-libraries').addNiLibrariesToLinker(binary)
|
||||
project(':hal').addHalToLinker(binary)
|
||||
project(':wpilibc').addWpilibCToLinker(binary)
|
||||
} else {
|
||||
binary.buildable = false
|
||||
}
|
||||
}
|
||||
sources {
|
||||
cpp {
|
||||
source {
|
||||
srcDirs 'src/main/cpp/examples/' + "${key}"
|
||||
include '**/*.cpp'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
templatesMap.each { key, value->
|
||||
"${key}"(NativeExecutableSpec) {
|
||||
binaries.all { binary->
|
||||
if (binary.targetPlatform.architecture.name == 'athena') {
|
||||
project(':ni-libraries').addNiLibrariesToLinker(binary)
|
||||
project(':hal').addHalToLinker(binary)
|
||||
project(':wpilibc').addWpilibCToLinker(binary)
|
||||
} else {
|
||||
binary.buildable = false
|
||||
}
|
||||
}
|
||||
sources {
|
||||
cpp {
|
||||
source {
|
||||
srcDirs 'src/main/cpp/templates/' + "${key}"
|
||||
include '**/*.cpp'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <WPILib.h>
|
||||
|
||||
/**
|
||||
* This is a demo program showing the use of the RobotDrive class.
|
||||
* Runs the motors with arcade steering.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
frc::RobotDrive myRobot{0, 1};
|
||||
frc::Joystick stick{0};
|
||||
|
||||
public:
|
||||
void TeleopPeriodic() {
|
||||
myRobot.ArcadeDrive(stick); // drive with arcade style
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,68 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <CameraServer.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/core/types.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
/**
|
||||
* This is a demo program showing the use of OpenCV to do vision processing. The
|
||||
* image is acquired from the Axis camera, then a rectangle is put on the image
|
||||
* and
|
||||
* sent to the dashboard. OpenCV has many methods for different types of
|
||||
* processing.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
private:
|
||||
static void VisionThread() {
|
||||
// Get the Axis camera from CameraServer
|
||||
cs::AxisCamera camera =
|
||||
CameraServer::GetInstance()->AddAxisCamera(
|
||||
"axis-camera.local");
|
||||
// Set the resolution
|
||||
camera.SetResolution(640, 480);
|
||||
|
||||
// Get a CvSink. This will capture Mats from the Camera
|
||||
cs::CvSink cvSink = CameraServer::GetInstance()->GetVideo();
|
||||
// Setup a CvSource. This will send images back to the Dashboard
|
||||
cs::CvSource outputStream =
|
||||
CameraServer::GetInstance()->PutVideo(
|
||||
"Rectangle", 640, 480);
|
||||
|
||||
// Mats are very memory expensive. Lets reuse this Mat.
|
||||
cv::Mat mat;
|
||||
|
||||
while (true) {
|
||||
// Tell the CvSink to grab a frame from the camera and
|
||||
// put it
|
||||
// in the source mat. If there is an error notify the
|
||||
// output.
|
||||
if (cvSink.GrabFrame(mat) == 0) {
|
||||
// Send the output the error.
|
||||
outputStream.NotifyError(cvSink.GetError());
|
||||
// skip the rest of the current iteration
|
||||
continue;
|
||||
}
|
||||
// Put a rectangle on the image
|
||||
rectangle(mat, cv::Point(100, 100), cv::Point(400, 400),
|
||||
cv::Scalar(255, 255, 255), 5);
|
||||
// Give the output stream a new image to display
|
||||
outputStream.PutFrame(mat);
|
||||
}
|
||||
}
|
||||
|
||||
void RobotInit() {
|
||||
// We need to run our vision program in a separate Thread.
|
||||
// If not, our robot program will not run
|
||||
std::thread visionThread(VisionThread);
|
||||
visionThread.detach();
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
43
wpilibcExamples/src/main/cpp/examples/CANPDP/src/Robot.cpp
Normal file
43
wpilibcExamples/src/main/cpp/examples/CANPDP/src/Robot.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <IterativeRobot.h>
|
||||
#include <PowerDistributionPanel.h>
|
||||
#include <SmartDashboard/SmartDashboard.h>
|
||||
|
||||
/**
|
||||
* This is a sample program showing how to retrieve information from the Power
|
||||
* Distribution Panel via CAN. The information will be displayed under variables
|
||||
* through the SmartDashboard.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void TeleopPeriodic() override {
|
||||
/* Get the current going through channel 7, in Amperes. The PDP
|
||||
* returns the current in increments of 0.125A. At low currents
|
||||
* the
|
||||
* current readings tend to be less accurate.
|
||||
*/
|
||||
frc::SmartDashboard::PutNumber(
|
||||
"Current Channel 7", m_pdp.GetCurrent(7));
|
||||
|
||||
/* Get the voltage going into the PDP, in Volts.
|
||||
* The PDP returns the voltage in increments of 0.05 Volts.
|
||||
*/
|
||||
frc::SmartDashboard::PutNumber("Voltage", m_pdp.GetVoltage());
|
||||
|
||||
// Retrieves the temperature of the PDP, in degrees Celsius.
|
||||
frc::SmartDashboard::PutNumber(
|
||||
"Temperature", m_pdp.GetTemperature());
|
||||
}
|
||||
|
||||
private:
|
||||
// Object for dealing with the Power Distribution Panel (PDP).
|
||||
frc::PowerDistributionPanel m_pdp;
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
93
wpilibcExamples/src/main/cpp/examples/Encoder/src/Robot.cpp
Normal file
93
wpilibcExamples/src/main/cpp/examples/Encoder/src/Robot.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Encoder.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <SmartDashboard/SmartDashboard.h>
|
||||
|
||||
/**
|
||||
* Sample program displaying the value of a quadrature encoder on the
|
||||
* SmartDashboard.
|
||||
* Quadrature Encoders are digital sensors which can detect the amount the
|
||||
* encoder has rotated since starting as well as the direction in which the
|
||||
* encoder shaft is rotating. However, encoders can not tell you the absolute
|
||||
* position of the encoder shaft (ie, it considers where it starts to be the
|
||||
* zero position, no matter where it starts), and so can only tell you how
|
||||
* much the encoder has rotated since starting.
|
||||
* Depending on the precision of an encoder, it will have fewer or greater
|
||||
* ticks per revolution; the number of ticks per revolution will affect the
|
||||
* conversion between ticks and distance, as specified by DistancePerPulse.
|
||||
* One of the most common uses of encoders is in the drivetrain, so that the
|
||||
* distance that the robot drives can be precisely controlled during the
|
||||
* autonomous mode.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
/**
|
||||
* The Encoder object is constructed with 4 parameters, the last two
|
||||
* being
|
||||
* optional.
|
||||
* The first two parameters (1, 2 in this case) refer to the ports on
|
||||
* the
|
||||
* roboRIO which the encoder uses. Because a quadrature encoder has
|
||||
* two signal wires, the signal from two DIO ports on the roboRIO are
|
||||
* used.
|
||||
* The third (optional) parameter is a boolean which defaults to false.
|
||||
* If you set this parameter to true, the direction of the encoder
|
||||
* will
|
||||
* be reversed, in case it makes more sense mechanically.
|
||||
* The final (optional) parameter specifies encoding rate (k1X, k2X, or
|
||||
* k4X)
|
||||
* and defaults to k4X. Faster (k4X) encoding gives greater positional
|
||||
* precision but more noise in the rate.
|
||||
*/
|
||||
frc::Encoder m_encoder{1, 2, false, Encoder::k4X};
|
||||
|
||||
public:
|
||||
Robot() {
|
||||
/* Defines the number of samples to average when determining the
|
||||
* rate.
|
||||
* On a quadrature encoder, values range from 1-255; larger
|
||||
* values
|
||||
* result in smoother but potentially less accurate rates than
|
||||
* lower
|
||||
* values.
|
||||
*/
|
||||
m_encoder.SetSamplesToAverage(5);
|
||||
|
||||
/* Defines how far the mechanism attached to the encoder moves
|
||||
* per pulse.
|
||||
* In this case, we assume that a 360 count encoder is directly
|
||||
* attached
|
||||
* to a 3 inch diameter (1.5inch radius) wheel, and that we want
|
||||
* to
|
||||
* measure distance in inches.
|
||||
*/
|
||||
m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * 3.1415 * 1.5);
|
||||
|
||||
/* Defines the lowest rate at which the encoder will not be
|
||||
* considered
|
||||
* stopped, for the purposes of the GetStopped() method.
|
||||
* Units are in distance / second, where distance refers to the
|
||||
* units
|
||||
* of distance that you are using, in this case inches.
|
||||
*/
|
||||
m_encoder.SetMinRate(1.0);
|
||||
}
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
// Retrieve the net displacement of the Encoder since the last
|
||||
// Reset.
|
||||
frc::SmartDashboard::PutNumber(
|
||||
"Encoder Distance", m_encoder.GetDistance());
|
||||
|
||||
// Retrieve the current rate of the encoder.
|
||||
frc::SmartDashboard::PutNumber(
|
||||
"Encoder Rate", m_encoder.GetRate());
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,33 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Autonomous.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "CloseClaw.h"
|
||||
#include "DriveStraight.h"
|
||||
#include "Pickup.h"
|
||||
#include "Place.h"
|
||||
#include "PrepareToPickup.h"
|
||||
#include "SetDistanceToBox.h"
|
||||
#include "SetWristSetpoint.h"
|
||||
|
||||
Autonomous::Autonomous()
|
||||
: frc::CommandGroup("Autonomous") {
|
||||
AddSequential(new PrepareToPickup());
|
||||
AddSequential(new Pickup());
|
||||
AddSequential(new SetDistanceToBox(0.10));
|
||||
// AddSequential(new DriveStraight(4)); // Use Encoders if ultrasonic
|
||||
// is broken
|
||||
AddSequential(new Place());
|
||||
AddSequential(new SetDistanceToBox(0.60));
|
||||
// AddSequential(new DriveStraight(-2)); // Use Encoders if ultrasonic
|
||||
// is broken
|
||||
AddParallel(new SetWristSetpoint(-45));
|
||||
AddSequential(new CloseClaw());
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* The main autonomous command to pickup and deliver the soda to the box.
|
||||
*/
|
||||
class Autonomous : public frc::CommandGroup {
|
||||
public:
|
||||
Autonomous();
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "CloseClaw.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
CloseClaw::CloseClaw()
|
||||
: frc::Command("CloseClaw") {
|
||||
Requires(Robot::claw.get());
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void CloseClaw::Initialize() {
|
||||
Robot::claw->Close();
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool CloseClaw::IsFinished() {
|
||||
return Robot::claw->IsGripping();
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
void CloseClaw::End() {
|
||||
// NOTE: Doesn't stop in simulation due to lower friction causing the can to
|
||||
// fall out
|
||||
// + there is no need to worry about stalling the motor or crushing the can.
|
||||
#ifndef SIMULATION
|
||||
Robot::claw->Stop();
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Opens the claw for one second. Real robots should use sensors, stalling
|
||||
* motors is BAD!
|
||||
*/
|
||||
class CloseClaw : public frc::Command {
|
||||
public:
|
||||
CloseClaw();
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "DriveStraight.h"
|
||||
|
||||
#include <PIDController.h>
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
DriveStraight::DriveStraight(double distance) {
|
||||
Requires(Robot::drivetrain.get());
|
||||
pid = new frc::PIDController(4, 0, 0, new DriveStraightPIDSource(),
|
||||
new DriveStraightPIDOutput());
|
||||
pid->SetAbsoluteTolerance(0.01);
|
||||
pid->SetSetpoint(distance);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void DriveStraight::Initialize() {
|
||||
// Get everything in a safe starting state.
|
||||
Robot::drivetrain->Reset();
|
||||
pid->Reset();
|
||||
pid->Enable();
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool DriveStraight::IsFinished() {
|
||||
return pid->OnTarget();
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
void DriveStraight::End() {
|
||||
// Stop PID and the wheels
|
||||
pid->Disable();
|
||||
Robot::drivetrain->Drive(0, 0);
|
||||
}
|
||||
|
||||
double DriveStraightPIDSource::PIDGet() {
|
||||
return Robot::drivetrain->GetDistance();
|
||||
}
|
||||
|
||||
void DriveStraightPIDOutput::PIDWrite(double d) {
|
||||
Robot::drivetrain->Drive(d, d);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
#include <PIDOutput.h>
|
||||
#include <PIDSource.h>
|
||||
|
||||
namespace frc {
|
||||
class PIDController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drive the given distance straight (negative values go backwards).
|
||||
* Uses a local PID controller to run a simple PID loop that is only
|
||||
* enabled while this command is running. The input is the averaged
|
||||
* values of the left and right encoders.
|
||||
*/
|
||||
class DriveStraight : public frc::Command {
|
||||
public:
|
||||
explicit DriveStraight(double distance);
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
|
||||
private:
|
||||
frc::PIDController* pid;
|
||||
};
|
||||
|
||||
class DriveStraightPIDSource : public PIDSource {
|
||||
public:
|
||||
virtual ~DriveStraightPIDSource() = default;
|
||||
double PIDGet() override;
|
||||
};
|
||||
|
||||
class DriveStraightPIDOutput : public PIDOutput {
|
||||
public:
|
||||
virtual ~DriveStraightPIDOutput() = default;
|
||||
void PIDWrite(double d) override;
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "OpenClaw.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
OpenClaw::OpenClaw()
|
||||
: frc::Command("OpenClaw") {
|
||||
Requires(Robot::claw.get());
|
||||
SetTimeout(1);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void OpenClaw::Initialize() {
|
||||
Robot::claw->Open();
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool OpenClaw::IsFinished() {
|
||||
return IsTimedOut();
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
void OpenClaw::End() {
|
||||
Robot::claw->Stop();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Opens the claw for one second. Real robots should use sensors, stalling
|
||||
* motors is BAD!
|
||||
*/
|
||||
class OpenClaw : public frc::Command {
|
||||
public:
|
||||
OpenClaw();
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Pickup.h"
|
||||
|
||||
#include "CloseClaw.h"
|
||||
#include "SetElevatorSetpoint.h"
|
||||
#include "SetWristSetpoint.h"
|
||||
|
||||
Pickup::Pickup()
|
||||
: frc::CommandGroup("Pickup") {
|
||||
AddSequential(new CloseClaw());
|
||||
AddParallel(new SetWristSetpoint(-45));
|
||||
AddSequential(new SetElevatorSetpoint(0.25));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Pickup a soda can (if one is between the open claws) and
|
||||
* get it in a safe state to drive around.
|
||||
*/
|
||||
class Pickup : public frc::CommandGroup {
|
||||
public:
|
||||
Pickup();
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Place.h"
|
||||
|
||||
#include "OpenClaw.h"
|
||||
#include "SetElevatorSetpoint.h"
|
||||
#include "SetWristSetpoint.h"
|
||||
|
||||
Place::Place()
|
||||
: frc::CommandGroup("Place") {
|
||||
AddSequential(new SetElevatorSetpoint(0.25));
|
||||
AddSequential(new SetWristSetpoint(0));
|
||||
AddSequential(new OpenClaw());
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Place a held soda can onto the platform.
|
||||
*/
|
||||
class Place : public frc::CommandGroup {
|
||||
public:
|
||||
Place();
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "PrepareToPickup.h"
|
||||
|
||||
#include "OpenClaw.h"
|
||||
#include "SetElevatorSetpoint.h"
|
||||
#include "SetWristSetpoint.h"
|
||||
|
||||
PrepareToPickup::PrepareToPickup()
|
||||
: frc::CommandGroup("PrepareToPickup") {
|
||||
AddParallel(new OpenClaw());
|
||||
AddParallel(new SetWristSetpoint(0));
|
||||
AddSequential(new SetElevatorSetpoint(0));
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Make sure the robot is in a state to pickup soda cans.
|
||||
*/
|
||||
class PrepareToPickup : public frc::CommandGroup {
|
||||
public:
|
||||
PrepareToPickup();
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "SetDistanceToBox.h"
|
||||
|
||||
#include <PIDController.h>
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
SetDistanceToBox::SetDistanceToBox(double distance) {
|
||||
Requires(Robot::drivetrain.get());
|
||||
pid = new frc::PIDController(-2, 0, 0, new SetDistanceToBoxPIDSource(),
|
||||
new SetDistanceToBoxPIDOutput());
|
||||
pid->SetAbsoluteTolerance(0.01);
|
||||
pid->SetSetpoint(distance);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void SetDistanceToBox::Initialize() {
|
||||
// Get everything in a safe starting state.
|
||||
Robot::drivetrain->Reset();
|
||||
pid->Reset();
|
||||
pid->Enable();
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool SetDistanceToBox::IsFinished() {
|
||||
return pid->OnTarget();
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
void SetDistanceToBox::End() {
|
||||
// Stop PID and the wheels
|
||||
pid->Disable();
|
||||
Robot::drivetrain->Drive(0, 0);
|
||||
}
|
||||
|
||||
double SetDistanceToBoxPIDSource::PIDGet() {
|
||||
return Robot::drivetrain->GetDistanceToObstacle();
|
||||
}
|
||||
|
||||
void SetDistanceToBoxPIDOutput::PIDWrite(double d) {
|
||||
Robot::drivetrain->Drive(d, d);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
#include <PIDOutput.h>
|
||||
#include <PIDSource.h>
|
||||
|
||||
namespace frc {
|
||||
class PIDController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drive until the robot is the given distance away from the box. Uses a local
|
||||
* PID controller to run a simple PID loop that is only enabled while this
|
||||
* command is running. The input is the averaged values of the left and right
|
||||
* encoders.
|
||||
*/
|
||||
class SetDistanceToBox : public frc::Command {
|
||||
public:
|
||||
explicit SetDistanceToBox(double distance);
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
|
||||
private:
|
||||
frc::PIDController* pid;
|
||||
};
|
||||
|
||||
class SetDistanceToBoxPIDSource : public frc::PIDSource {
|
||||
public:
|
||||
virtual ~SetDistanceToBoxPIDSource() = default;
|
||||
double PIDGet() override;
|
||||
};
|
||||
|
||||
class SetDistanceToBoxPIDOutput : public frc::PIDOutput {
|
||||
public:
|
||||
virtual ~SetDistanceToBoxPIDOutput() = default;
|
||||
void PIDWrite(double d) override;
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "SetElevatorSetpoint.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
SetElevatorSetpoint::SetElevatorSetpoint(double setpoint)
|
||||
: frc::Command("SetElevatorSetpoint") {
|
||||
this->setpoint = setpoint;
|
||||
Requires(Robot::elevator.get());
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void SetElevatorSetpoint::Initialize() {
|
||||
Robot::elevator->SetSetpoint(setpoint);
|
||||
Robot::elevator->Enable();
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool SetElevatorSetpoint::IsFinished() {
|
||||
return Robot::elevator->OnTarget();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Move the elevator to a given location. This command finishes when it is
|
||||
* within
|
||||
* the tolerance, but leaves the PID loop running to maintain the position.
|
||||
* Other
|
||||
* commands using the elevator should make sure they disable PID!
|
||||
*/
|
||||
class SetElevatorSetpoint : public frc::Command {
|
||||
public:
|
||||
explicit SetElevatorSetpoint(double setpoint);
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
|
||||
private:
|
||||
double setpoint;
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "SetWristSetpoint.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
SetWristSetpoint::SetWristSetpoint(double setpoint)
|
||||
: frc::Command("SetWristSetpoint") {
|
||||
this->setpoint = setpoint;
|
||||
Requires(Robot::wrist.get());
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void SetWristSetpoint::Initialize() {
|
||||
Robot::wrist->SetSetpoint(setpoint);
|
||||
Robot::wrist->Enable();
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool SetWristSetpoint::IsFinished() {
|
||||
return Robot::wrist->OnTarget();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Move the wrist to a given angle. This command finishes when it is within
|
||||
* the tolerance, but leaves the PID loop running to maintain the position.
|
||||
* Other commands using the wrist should make sure they disable PID!
|
||||
*/
|
||||
class SetWristSetpoint : public frc::Command {
|
||||
public:
|
||||
explicit SetWristSetpoint(double setpoint);
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
|
||||
private:
|
||||
double setpoint;
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "TankDriveWithJoystick.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
TankDriveWithJoystick::TankDriveWithJoystick()
|
||||
: frc::Command("TankDriveWithJoystick") {
|
||||
Requires(Robot::drivetrain.get());
|
||||
}
|
||||
|
||||
// Called repeatedly when this Command is scheduled to run
|
||||
void TankDriveWithJoystick::Execute() {
|
||||
Robot::drivetrain->Drive(Robot::oi->GetJoystick());
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool TankDriveWithJoystick::IsFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
void TankDriveWithJoystick::End() {
|
||||
Robot::drivetrain->Drive(0, 0);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Have the robot drive tank style using the PS3 Joystick until interrupted.
|
||||
*/
|
||||
class TankDriveWithJoystick : public frc::Command {
|
||||
public:
|
||||
TankDriveWithJoystick();
|
||||
void Execute() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
};
|
||||
38
wpilibcExamples/src/main/cpp/examples/GearsBot/src/OI.cpp
Normal file
38
wpilibcExamples/src/main/cpp/examples/GearsBot/src/OI.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "OI.h"
|
||||
|
||||
#include <SmartDashboard/SmartDashboard.h>
|
||||
|
||||
#include "Commands/Autonomous.h"
|
||||
#include "Commands/CloseClaw.h"
|
||||
#include "Commands/OpenClaw.h"
|
||||
#include "Commands/Pickup.h"
|
||||
#include "Commands/Place.h"
|
||||
#include "Commands/PrepareToPickup.h"
|
||||
#include "Commands/SetElevatorSetpoint.h"
|
||||
|
||||
OI::OI() {
|
||||
frc::SmartDashboard::PutData("Open Claw", new OpenClaw());
|
||||
frc::SmartDashboard::PutData("Close Claw", new CloseClaw());
|
||||
|
||||
// Connect the buttons to commands
|
||||
d_up.WhenPressed(new SetElevatorSetpoint(0.2));
|
||||
d_down.WhenPressed(new SetElevatorSetpoint(-0.2));
|
||||
d_right.WhenPressed(new CloseClaw());
|
||||
d_left.WhenPressed(new OpenClaw());
|
||||
|
||||
r1.WhenPressed(new PrepareToPickup());
|
||||
r2.WhenPressed(new Pickup());
|
||||
l1.WhenPressed(new Place());
|
||||
l2.WhenPressed(new Autonomous());
|
||||
}
|
||||
|
||||
frc::Joystick* OI::GetJoystick() {
|
||||
return &joy;
|
||||
}
|
||||
30
wpilibcExamples/src/main/cpp/examples/GearsBot/src/OI.h
Normal file
30
wpilibcExamples/src/main/cpp/examples/GearsBot/src/OI.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Buttons/JoystickButton.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
class OI {
|
||||
public:
|
||||
OI();
|
||||
frc::Joystick* GetJoystick();
|
||||
|
||||
private:
|
||||
frc::Joystick joy{0};
|
||||
|
||||
// Create some buttons
|
||||
frc::JoystickButton d_up{&joy, 5};
|
||||
frc::JoystickButton d_right{&joy, 6};
|
||||
frc::JoystickButton d_down{&joy, 7};
|
||||
frc::JoystickButton d_left{&joy, 8};
|
||||
frc::JoystickButton l2{&joy, 9};
|
||||
frc::JoystickButton r2{&joy, 10};
|
||||
frc::JoystickButton l1{&joy, 11};
|
||||
frc::JoystickButton r1{&joy, 12};
|
||||
};
|
||||
52
wpilibcExamples/src/main/cpp/examples/GearsBot/src/Robot.cpp
Normal file
52
wpilibcExamples/src/main/cpp/examples/GearsBot/src/Robot.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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>
|
||||
|
||||
std::shared_ptr<DriveTrain> Robot::drivetrain = std::make_shared<DriveTrain>();
|
||||
std::shared_ptr<Elevator> Robot::elevator = std::make_shared<Elevator>();
|
||||
std::shared_ptr<Wrist> Robot::wrist = std::make_shared<Wrist>();
|
||||
std::shared_ptr<Claw> Robot::claw = std::make_shared<Claw>();
|
||||
std::unique_ptr<OI> Robot::oi = std::make_unique<OI>();
|
||||
|
||||
void Robot::RobotInit() {
|
||||
// Show what command your subsystem is running on the SmartDashboard
|
||||
frc::SmartDashboard::PutData(drivetrain.get());
|
||||
frc::SmartDashboard::PutData(elevator.get());
|
||||
frc::SmartDashboard::PutData(wrist.get());
|
||||
frc::SmartDashboard::PutData(claw.get());
|
||||
}
|
||||
|
||||
void Robot::AutonomousInit() {
|
||||
autonomousCommand.Start();
|
||||
std::cout << "Starting Auto" << std::endl;
|
||||
}
|
||||
|
||||
void Robot::AutonomousPeriodic() {
|
||||
frc::Scheduler::GetInstance()->Run();
|
||||
}
|
||||
|
||||
void Robot::TeleopInit() {
|
||||
// This makes sure that the autonomous stops running when
|
||||
// teleop starts running. If you want the autonomous to
|
||||
// continue until interrupted by another command, remove
|
||||
// this line or comment it out.
|
||||
autonomousCommand.Cancel();
|
||||
std::cout << "Starting Teleop" << std::endl;
|
||||
}
|
||||
|
||||
void Robot::TeleopPeriodic() {
|
||||
frc::Scheduler::GetInstance()->Run();
|
||||
}
|
||||
|
||||
void Robot::TestPeriodic() {
|
||||
lw->Run();
|
||||
}
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
41
wpilibcExamples/src/main/cpp/examples/GearsBot/src/Robot.h
Normal file
41
wpilibcExamples/src/main/cpp/examples/GearsBot/src/Robot.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <memory>
|
||||
|
||||
#include <Commands/Command.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
|
||||
#include "Commands/Autonomous.h"
|
||||
#include "OI.h"
|
||||
#include "Subsystems/Claw.h"
|
||||
#include "Subsystems/DriveTrain.h"
|
||||
#include "Subsystems/Elevator.h"
|
||||
#include "Subsystems/Wrist.h"
|
||||
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
static std::shared_ptr<DriveTrain> drivetrain;
|
||||
static std::shared_ptr<Elevator> elevator;
|
||||
static std::shared_ptr<Wrist> wrist;
|
||||
static std::shared_ptr<Claw> claw;
|
||||
static std::unique_ptr<OI> oi;
|
||||
|
||||
private:
|
||||
Autonomous autonomousCommand;
|
||||
frc::LiveWindow* lw = frc::LiveWindow::GetInstance();
|
||||
|
||||
void RobotInit() override;
|
||||
void AutonomousInit() override;
|
||||
void AutonomousPeriodic() override;
|
||||
void TeleopInit() override;
|
||||
void TeleopPeriodic() override;
|
||||
void TestPeriodic() override;
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Claw.h"
|
||||
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
|
||||
Claw::Claw()
|
||||
: frc::Subsystem("Claw") {
|
||||
// Let's show everything on the LiveWindow
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("Claw", "Motor", &motor);
|
||||
}
|
||||
|
||||
void Claw::InitDefaultCommand() {}
|
||||
|
||||
void Claw::Open() {
|
||||
motor.Set(-1);
|
||||
}
|
||||
|
||||
void Claw::Close() {
|
||||
motor.Set(1);
|
||||
}
|
||||
|
||||
void Claw::Stop() {
|
||||
motor.Set(0);
|
||||
}
|
||||
|
||||
bool Claw::IsGripping() {
|
||||
return contact.Get();
|
||||
}
|
||||
|
||||
void Claw::Log() {}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Subsystem.h>
|
||||
#include <DigitalInput.h>
|
||||
#include <Victor.h>
|
||||
|
||||
/**
|
||||
* The claw subsystem is a simple system with a motor for opening and closing.
|
||||
* If using stronger motors, you should probably use a sensor so that the
|
||||
* motors don't stall.
|
||||
*/
|
||||
class Claw : public frc::Subsystem {
|
||||
public:
|
||||
Claw();
|
||||
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
/**
|
||||
* Set the claw motor to move in the open direction.
|
||||
*/
|
||||
void Open();
|
||||
|
||||
/**
|
||||
* Set the claw motor to move in the close direction.
|
||||
*/
|
||||
void Close();
|
||||
|
||||
/**
|
||||
* Stops the claw motor from moving.
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* Return true when the robot is grabbing an object hard enough
|
||||
* to trigger the limit switch.
|
||||
*/
|
||||
bool IsGripping();
|
||||
|
||||
void Log();
|
||||
|
||||
private:
|
||||
frc::Victor motor{7};
|
||||
frc::DigitalInput contact{5};
|
||||
};
|
||||
@@ -0,0 +1,101 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "DriveTrain.h"
|
||||
|
||||
#include <Joystick.h>
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
|
||||
#include "../Commands/TankDriveWithJoystick.h"
|
||||
|
||||
DriveTrain::DriveTrain()
|
||||
: frc::Subsystem("DriveTrain") {
|
||||
// Encoders may measure differently in the real world and in
|
||||
// simulation. In this example the robot moves 0.042 barleycorns
|
||||
// per tick in the real world, but the simulated encoders
|
||||
// simulate 360 tick encoders. This if statement allows for the
|
||||
// real robot to handle this difference in devices.
|
||||
#ifndef SIMULATION
|
||||
leftEncoder.SetDistancePerPulse(0.042);
|
||||
rightEncoder.SetDistancePerPulse(0.042);
|
||||
#else
|
||||
// Circumference in ft = 4in/12(in/ft)*PI
|
||||
leftEncoder.SetDistancePerPulse(
|
||||
static_cast<double>(4.0 / 12.0 * M_PI) / 360.0);
|
||||
rightEncoder.SetDistancePerPulse(
|
||||
static_cast<double>(4.0 / 12.0 * M_PI) / 360.0);
|
||||
#endif
|
||||
|
||||
// Let's show everything on the LiveWindow
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("Drive Train",
|
||||
// "Front_Left Motor", &frontLeft);
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("Drive Train",
|
||||
// "Rear Left Motor", &rearLeft);
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("Drive Train",
|
||||
// "Front Right Motor", &frontRight);
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("Drive Train",
|
||||
// "Rear Right Motor", &rearRight);
|
||||
// frc::LiveWindow::GetInstance()->AddSensor("Drive Train", "Left
|
||||
// Encoder",
|
||||
// &leftEncoder);
|
||||
// frc::LiveWindow::GetInstance()->AddSensor("Drive Train", "Right
|
||||
// Encoder",
|
||||
// &rightEncoder);
|
||||
// frc::LiveWindow::GetInstance()->AddSensor("Drive Train",
|
||||
// "Rangefinder",
|
||||
// &rangefinder);
|
||||
// frc::LiveWindow::GetInstance()->AddSensor("Drive Train", "Gyro",
|
||||
// &gyro);
|
||||
}
|
||||
|
||||
/**
|
||||
* When no other command is running let the operator drive around
|
||||
* using the PS3 joystick.
|
||||
*/
|
||||
void DriveTrain::InitDefaultCommand() {
|
||||
SetDefaultCommand(new TankDriveWithJoystick());
|
||||
}
|
||||
|
||||
/**
|
||||
* The log method puts interesting information to the SmartDashboard.
|
||||
*/
|
||||
void DriveTrain::Log() {
|
||||
frc::SmartDashboard::PutNumber(
|
||||
"Left Distance", leftEncoder.GetDistance());
|
||||
frc::SmartDashboard::PutNumber(
|
||||
"Right Distance", rightEncoder.GetDistance());
|
||||
frc::SmartDashboard::PutNumber("Left Speed", leftEncoder.GetRate());
|
||||
frc::SmartDashboard::PutNumber("Right Speed", rightEncoder.GetRate());
|
||||
frc::SmartDashboard::PutNumber("Gyro", gyro.GetAngle());
|
||||
}
|
||||
|
||||
void DriveTrain::Drive(double left, double right) {
|
||||
drive.TankDrive(left, right);
|
||||
}
|
||||
|
||||
void DriveTrain::Drive(frc::Joystick* joy) {
|
||||
Drive(-joy->GetY(), -joy->GetRawAxis(4));
|
||||
}
|
||||
|
||||
double DriveTrain::GetHeading() {
|
||||
return gyro.GetAngle();
|
||||
}
|
||||
|
||||
void DriveTrain::Reset() {
|
||||
gyro.Reset();
|
||||
leftEncoder.Reset();
|
||||
rightEncoder.Reset();
|
||||
}
|
||||
|
||||
double DriveTrain::GetDistance() {
|
||||
return (leftEncoder.GetDistance() + rightEncoder.GetDistance()) / 2;
|
||||
}
|
||||
|
||||
double DriveTrain::GetDistanceToObstacle() {
|
||||
// Really meters in simulation since it's a rangefinder...
|
||||
return rangefinder.GetAverageVoltage();
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <AnalogGyro.h>
|
||||
#include <AnalogInput.h>
|
||||
#include <Commands/Subsystem.h>
|
||||
#include <Encoder.h>
|
||||
#include <RobotDrive.h>
|
||||
#include <Talon.h>
|
||||
|
||||
namespace frc {
|
||||
class Joystick;
|
||||
}
|
||||
|
||||
/**
|
||||
* The DriveTrain subsystem incorporates the sensors and actuators attached to
|
||||
* the robots chassis. These include four drive motors, a left and right encoder
|
||||
* and a gyro.
|
||||
*/
|
||||
class DriveTrain : public frc::Subsystem {
|
||||
public:
|
||||
DriveTrain();
|
||||
|
||||
/**
|
||||
* When no other command is running let the operator drive around
|
||||
* using the PS3 joystick.
|
||||
*/
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
/**
|
||||
* The log method puts interesting information to the SmartDashboard.
|
||||
*/
|
||||
void Log();
|
||||
|
||||
/**
|
||||
* Tank style driving for the DriveTrain.
|
||||
* @param left Speed in range [-1,1]
|
||||
* @param right Speed in range [-1,1]
|
||||
*/
|
||||
void Drive(double left, double right);
|
||||
|
||||
/**
|
||||
* @param joy The ps3 style joystick to use to drive tank style.
|
||||
*/
|
||||
void Drive(frc::Joystick* joy);
|
||||
|
||||
/**
|
||||
* @return The robots heading in degrees.
|
||||
*/
|
||||
double GetHeading();
|
||||
|
||||
/**
|
||||
* Reset the robots sensors to the zero states.
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/**
|
||||
* @return The distance driven (average of left and right encoders).
|
||||
*/
|
||||
double GetDistance();
|
||||
|
||||
/**
|
||||
* @return The distance to the obstacle detected by the rangefinder.
|
||||
*/
|
||||
double GetDistanceToObstacle();
|
||||
|
||||
private:
|
||||
frc::Talon frontLeft{1};
|
||||
frc::Talon rearLeft{2};
|
||||
frc::Talon frontRight{3};
|
||||
frc::Talon rearRight{4};
|
||||
frc::RobotDrive drive{frontLeft, rearLeft, frontRight, rearRight};
|
||||
frc::Encoder leftEncoder{1, 2};
|
||||
frc::Encoder rightEncoder{3, 4};
|
||||
frc::AnalogInput rangefinder{6};
|
||||
frc::AnalogGyro gyro{1};
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Elevator.h"
|
||||
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
#include <SmartDashboard/SmartDashboard.h>
|
||||
|
||||
Elevator::Elevator()
|
||||
: frc::PIDSubsystem("Elevator", kP_real, kI_real, 0.0) {
|
||||
#ifdef SIMULATION // Check for simulation and update PID values
|
||||
GetPIDController()->SetPID(kP_simulation, kI_simulation, 0, 0);
|
||||
#endif
|
||||
SetAbsoluteTolerance(0.005);
|
||||
|
||||
// Let's show everything on the LiveWindow
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("Elevator", "Motor",
|
||||
// &motor);
|
||||
// frc::LiveWindow::GetInstance()->AddSensor("Elevator", "Pot", &pot);
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("Elevator", "PID",
|
||||
// GetPIDController());
|
||||
}
|
||||
|
||||
void Elevator::InitDefaultCommand() {}
|
||||
|
||||
void Elevator::Log() {
|
||||
// frc::SmartDashboard::PutData("Wrist Pot", &pot);
|
||||
}
|
||||
|
||||
double Elevator::ReturnPIDInput() {
|
||||
return pot.Get();
|
||||
}
|
||||
|
||||
void Elevator::UsePIDOutput(double d) {
|
||||
motor.Set(d);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <AnalogPotentiometer.h>
|
||||
#include <Commands/PIDSubsystem.h>
|
||||
#include <Victor.h>
|
||||
|
||||
/**
|
||||
* The elevator subsystem uses PID to go to a given height. Unfortunately, in
|
||||
* it's current
|
||||
* state PID values for simulation are different than in the real world do to
|
||||
* minor differences.
|
||||
*/
|
||||
class Elevator : public frc::PIDSubsystem {
|
||||
public:
|
||||
Elevator();
|
||||
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
/**
|
||||
* The log method puts interesting information to the SmartDashboard.
|
||||
*/
|
||||
void Log();
|
||||
|
||||
/**
|
||||
* Use the potentiometer as the PID sensor. This method is automatically
|
||||
* called by the subsystem.
|
||||
*/
|
||||
double ReturnPIDInput();
|
||||
|
||||
/**
|
||||
* Use the motor as the PID output. This method is automatically called
|
||||
* by
|
||||
* the subsystem.
|
||||
*/
|
||||
void UsePIDOutput(double d);
|
||||
|
||||
private:
|
||||
frc::Victor motor{5};
|
||||
|
||||
// Conversion value of potentiometer varies between the real world and
|
||||
// simulation
|
||||
#ifndef SIMULATION
|
||||
frc::AnalogPotentiometer pot{2, -2.0 / 5};
|
||||
#else
|
||||
frc::AnalogPotentiometer pot{2}; // Defaults to meters
|
||||
#endif
|
||||
|
||||
static constexpr double kP_real = 4;
|
||||
static constexpr double kI_real = 0.07;
|
||||
static constexpr double kP_simulation = 18;
|
||||
static constexpr double kI_simulation = 0.2;
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Wrist.h"
|
||||
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
#include <SmartDashboard/SmartDashboard.h>
|
||||
|
||||
Wrist::Wrist()
|
||||
: frc::PIDSubsystem("Wrist", kP_real, 0.0, 0.0) {
|
||||
#ifdef SIMULATION // Check for simulation and update PID values
|
||||
GetPIDController()->SetPID(kP_simulation, 0, 0, 0);
|
||||
#endif
|
||||
SetAbsoluteTolerance(2.5);
|
||||
|
||||
// Let's show everything on the LiveWindow
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("Wrist", "Motor",
|
||||
// &motor);
|
||||
// frc::LiveWindow::GetInstance()->AddSensor("Wrist", "Pot", &pot);
|
||||
frc::LiveWindow::GetInstance()->AddActuator(
|
||||
"Wrist", "PID", GetPIDController());
|
||||
}
|
||||
|
||||
void Wrist::InitDefaultCommand() {}
|
||||
|
||||
void Wrist::Log() {
|
||||
// frc::SmartDashboard::PutData("Wrist Angle", &pot);
|
||||
}
|
||||
|
||||
double Wrist::ReturnPIDInput() {
|
||||
return pot.Get();
|
||||
}
|
||||
|
||||
void Wrist::UsePIDOutput(double d) {
|
||||
motor.Set(d);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <AnalogPotentiometer.h>
|
||||
#include <Commands/PIDSubsystem.h>
|
||||
#include <Victor.h>
|
||||
|
||||
/**
|
||||
* The wrist subsystem is like the elevator, but with a rotational joint instead
|
||||
* of a linear joint.
|
||||
*/
|
||||
class Wrist : public PIDSubsystem {
|
||||
public:
|
||||
Wrist();
|
||||
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
/**
|
||||
* The log method puts interesting information to the SmartDashboard.
|
||||
*/
|
||||
void Log();
|
||||
|
||||
/**
|
||||
* Use the potentiometer as the PID sensor. This method is automatically
|
||||
* called by the subsystem.
|
||||
*/
|
||||
double ReturnPIDInput() override;
|
||||
|
||||
/**
|
||||
* Use the motor as the PID output. This method is automatically called
|
||||
* by
|
||||
* the subsystem.
|
||||
*/
|
||||
void UsePIDOutput(double d) override;
|
||||
|
||||
private:
|
||||
frc::Victor motor{6};
|
||||
|
||||
// Conversion value of potentiometer varies between the real world and
|
||||
// simulation
|
||||
#ifndef SIMULATION
|
||||
frc::AnalogPotentiometer pot{3, -270.0 / 5};
|
||||
#else
|
||||
frc::AnalogPotentiometer pot{3}; // Defaults to degrees
|
||||
#endif
|
||||
|
||||
static constexpr double kP_real = 1;
|
||||
static constexpr double kP_simulation = 0.05;
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <IterativeRobot.h>
|
||||
#include <Joystick.h>
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
#include <RobotDrive.h>
|
||||
#include <Timer.h>
|
||||
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
Robot() {
|
||||
myRobot.SetExpiration(0.1);
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
private:
|
||||
frc::RobotDrive myRobot{0, 1}; // Robot drive system
|
||||
frc::Joystick stick{0}; // Only joystick
|
||||
frc::LiveWindow* lw = frc::LiveWindow::GetInstance();
|
||||
frc::Timer timer;
|
||||
|
||||
void AutonomousInit() override {
|
||||
timer.Reset();
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
void AutonomousPeriodic() override {
|
||||
// Drive for 2 seconds
|
||||
if (timer.Get() < 2.0) {
|
||||
myRobot.Drive(-0.5, 0.0); // Drive forwards half speed
|
||||
} else {
|
||||
myRobot.Drive(0.0, 0.0); // Stop robot
|
||||
}
|
||||
}
|
||||
|
||||
void TeleopInit() override {}
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
// Drive with arcade style (use right stick)
|
||||
myRobot.ArcadeDrive(stick);
|
||||
}
|
||||
|
||||
void TestPeriodic() override { lw->Run(); }
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
58
wpilibcExamples/src/main/cpp/examples/Gyro/src/Robot.cpp
Normal file
58
wpilibcExamples/src/main/cpp/examples/Gyro/src/Robot.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <cmath>
|
||||
|
||||
#include <AnalogGyro.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <Joystick.h>
|
||||
#include <RobotDrive.h>
|
||||
|
||||
/**
|
||||
* This is a sample program to demonstrate how to use a gyro sensor to make a
|
||||
* robot drive
|
||||
* straight. This program uses a joystick to drive forwards and backwards while
|
||||
* the gyro
|
||||
* is used for direction keeping.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void RobotInit() override {
|
||||
gyro.SetSensitivity(kVoltsPerDegreePerSecond);
|
||||
}
|
||||
|
||||
/**
|
||||
* The motor speed is set from the joystick while the RobotDrive turning
|
||||
* value is assigned from the error between the setpoint and the gyro
|
||||
* angle.
|
||||
*/
|
||||
void TeleopPeriodic() override {
|
||||
double turningValue = (kAngleSetpoint - gyro.GetAngle()) * kP;
|
||||
// Invert the direction of the turn if we are going backwards
|
||||
turningValue = std::copysign(turningValue, joystick.GetY());
|
||||
myRobot.Drive(joystick.GetY(), turningValue);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr double kAngleSetpoint = 0.0;
|
||||
static constexpr double kP = 0.005; // Proportional turning constant
|
||||
|
||||
// Gyro calibration constant, may need to be adjusted
|
||||
// Gyro value of 360 is set to correspond to one full revolution
|
||||
static constexpr double kVoltsPerDegreePerSecond = 0.0128;
|
||||
|
||||
static constexpr int kLeftMotorPort = 0;
|
||||
static constexpr int kRightMotorPort = 1;
|
||||
static constexpr int kGyroPort = 0;
|
||||
static constexpr int kJoystickPort = 0;
|
||||
|
||||
frc::RobotDrive myRobot{kLeftMotorPort, kRightMotorPort};
|
||||
frc::AnalogGyro gyro{kGyroPort};
|
||||
frc::Joystick joystick{kJoystickPort};
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,55 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <AnalogGyro.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <Joystick.h>
|
||||
#include <RobotDrive.h>
|
||||
|
||||
/**
|
||||
* This is a sample program that uses mecanum drive with a gyro sensor to
|
||||
* maintian rotation vectorsin relation to the starting orientation of the robot
|
||||
* (field-oriented controls).
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void RobotInit() override {
|
||||
// invert the left side motors
|
||||
// you may need to change or remove this to match your robot
|
||||
myRobot.SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);
|
||||
myRobot.SetInvertedMotor(RobotDrive::kRearLeftMotor, true);
|
||||
|
||||
gyro.SetSensitivity(kVoltsPerDegreePerSecond);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mecanum drive is used with the gyro angle as an input.
|
||||
*/
|
||||
void TeleopPeriodic() override {
|
||||
myRobot.MecanumDrive_Cartesian(joystick.GetX(), joystick.GetY(),
|
||||
joystick.GetZ(), gyro.GetAngle());
|
||||
}
|
||||
|
||||
private:
|
||||
// Gyro calibration constant, may need to be adjusted
|
||||
// Gyro value of 360 is set to correspond to one full revolution
|
||||
static constexpr double kVoltsPerDegreePerSecond = 0.0128;
|
||||
|
||||
static constexpr int kFrontLeftMotorPort = 0;
|
||||
static constexpr int kFrontRightMotorPort = 1;
|
||||
static constexpr int kRearLeftMotorPort = 2;
|
||||
static constexpr int kRearRightMotorPort = 3;
|
||||
static constexpr int kGyroPort = 0;
|
||||
static constexpr int kJoystickPort = 0;
|
||||
|
||||
frc::RobotDrive myRobot{kFrontLeftMotorPort, kFrontRightMotorPort,
|
||||
kRearLeftMotorPort, kRearRightMotorPort};
|
||||
frc::AnalogGyro gyro{kGyroPort};
|
||||
frc::Joystick joystick{kJoystickPort};
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,70 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <thread>
|
||||
|
||||
#include <CameraServer.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/core/types.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
/**
|
||||
* This is a demo program showing the use of OpenCV to do vision processing. The
|
||||
* image is acquired from the USB camera, then a rectangle is put on the image
|
||||
* and
|
||||
* sent to the dashboard. OpenCV has many methods for different types of
|
||||
* processing.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
private:
|
||||
static void VisionThread() {
|
||||
// Get the USB camera from CameraServer
|
||||
cs::UsbCamera camera =
|
||||
CameraServer::GetInstance()
|
||||
->StartAutomaticCapture();
|
||||
// Set the resolution
|
||||
camera.SetResolution(640, 480);
|
||||
|
||||
// Get a CvSink. This will capture Mats from the Camera
|
||||
cs::CvSink cvSink = CameraServer::GetInstance()->GetVideo();
|
||||
// Setup a CvSource. This will send images back to the Dashboard
|
||||
cs::CvSource outputStream =
|
||||
CameraServer::GetInstance()->PutVideo(
|
||||
"Rectangle", 640, 480);
|
||||
|
||||
// Mats are very memory expensive. Lets reuse this Mat.
|
||||
cv::Mat mat;
|
||||
|
||||
while (true) {
|
||||
// Tell the CvSink to grab a frame from the camera and
|
||||
// put it
|
||||
// in the source mat. If there is an error notify the
|
||||
// output.
|
||||
if (cvSink.GrabFrame(mat) == 0) {
|
||||
// Send the output the error.
|
||||
outputStream.NotifyError(cvSink.GetError());
|
||||
// skip the rest of the current iteration
|
||||
continue;
|
||||
}
|
||||
// Put a rectangle on the image
|
||||
rectangle(mat, cv::Point(100, 100), cv::Point(400, 400),
|
||||
cv::Scalar(255, 255, 255), 5);
|
||||
// Give the output stream a new image to display
|
||||
outputStream.PutFrame(mat);
|
||||
}
|
||||
}
|
||||
|
||||
void RobotInit() {
|
||||
// We need to run our vision program in a separate Thread.
|
||||
// If not, our robot program will not run
|
||||
std::thread visionThread(VisionThread);
|
||||
visionThread.detach();
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,48 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <IterativeRobot.h>
|
||||
#include <Joystick.h>
|
||||
#include <RobotDrive.h>
|
||||
|
||||
/**
|
||||
* This is a demo program showing how to use Mecanum control with the RobotDrive
|
||||
* class.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void RobotInit() {
|
||||
// Invert the left side motors
|
||||
// You may need to change or remove this to match your robot
|
||||
robotDrive.SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);
|
||||
robotDrive.SetInvertedMotor(RobotDrive::kRearLeftMotor, true);
|
||||
}
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
/* Use the joystick X axis for lateral movement, Y axis for
|
||||
* forward
|
||||
* movement, and Z axis for rotation.
|
||||
*/
|
||||
robotDrive.MecanumDrive_Cartesian(
|
||||
stick.GetX(), stick.GetY(), stick.GetZ());
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int kFrontLeftChannel = 2;
|
||||
static constexpr int kRearLeftChannel = 3;
|
||||
static constexpr int kFrontRightChannel = 1;
|
||||
static constexpr int kRearRightChannel = 0;
|
||||
|
||||
static constexpr int kJoystickChannel = 0;
|
||||
|
||||
frc::RobotDrive robotDrive{kFrontLeftChannel, kRearLeftChannel,
|
||||
kFrontRightChannel, kRearRightChannel};
|
||||
|
||||
frc::Joystick stick{kJoystickChannel};
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,29 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <IterativeRobot.h>
|
||||
#include <Joystick.h>
|
||||
#include <Spark.h>
|
||||
|
||||
/**
|
||||
* This sample program shows how to control a motor using a joystick. In the
|
||||
* operator control part of the program, the joystick is read and the value is
|
||||
* written to the motor.
|
||||
*
|
||||
* Joystick analog values range from -1 to 1 and speed controller inputs as
|
||||
* range from -1 to 1 making it easy to work together.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void TeleopPeriodic() override { m_motor.Set(m_stick.GetY()); }
|
||||
|
||||
private:
|
||||
frc::Joystick m_stick{0};
|
||||
frc::Spark m_motor{0};
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "CheckForHotGoal.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
CheckForHotGoal::CheckForHotGoal(double time) {
|
||||
SetTimeout(time);
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool CheckForHotGoal::IsFinished() {
|
||||
return IsTimedOut() || Robot::shooter->GoalIsHot();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* This command looks for the hot goal and waits until it's detected or timed
|
||||
* out. The timeout is because it's better to shoot and get some autonomous
|
||||
* points than get none. When called sequentially, this command will block until
|
||||
* the hot goal is detected or until it is timed out.
|
||||
*/
|
||||
class CheckForHotGoal : public frc::Command {
|
||||
public:
|
||||
explicit CheckForHotGoal(double time);
|
||||
bool IsFinished() override;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "CloseClaw.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
CloseClaw::CloseClaw() {
|
||||
Requires(Robot::collector.get());
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void CloseClaw::Initialize() {
|
||||
Robot::collector->Close();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/InstantCommand.h>
|
||||
|
||||
/**
|
||||
* Close the claw.
|
||||
*
|
||||
* NOTE: It doesn't wait for the claw to close since there is no sensor to
|
||||
* detect that.
|
||||
*/
|
||||
class CloseClaw : public frc::InstantCommand {
|
||||
public:
|
||||
CloseClaw();
|
||||
void Initialize() override;
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Collect.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
#include "CloseClaw.h"
|
||||
#include "SetCollectionSpeed.h"
|
||||
#include "SetPivotSetpoint.h"
|
||||
#include "WaitForBall.h"
|
||||
|
||||
Collect::Collect() {
|
||||
AddSequential(new SetCollectionSpeed(Collector::kForward));
|
||||
AddParallel(new CloseClaw());
|
||||
AddSequential(new SetPivotSetpoint(Pivot::kCollect));
|
||||
AddSequential(new WaitForBall());
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Get the robot set to collect balls.
|
||||
*/
|
||||
class Collect : public frc::CommandGroup {
|
||||
public:
|
||||
Collect();
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "DriveAndShootAutonomous.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
#include "CheckForHotGoal.h"
|
||||
#include "CloseClaw.h"
|
||||
#include "DriveForward.h"
|
||||
#include "SetPivotSetpoint.h"
|
||||
#include "Shoot.h"
|
||||
#include "WaitForPressure.h"
|
||||
|
||||
DriveAndShootAutonomous::DriveAndShootAutonomous() {
|
||||
AddSequential(new CloseClaw());
|
||||
AddSequential(new WaitForPressure(), 2);
|
||||
#ifndef SIMULATION
|
||||
// NOTE: Simulation doesn't currently have the concept of hot.
|
||||
AddSequential(new CheckForHotGoal(2));
|
||||
#endif
|
||||
AddSequential(new SetPivotSetpoint(45));
|
||||
AddSequential(new DriveForward(8, 0.3));
|
||||
AddSequential(new Shoot());
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Drive over the line and then shoot the ball. If the hot goal is not detected,
|
||||
* it will wait briefly.
|
||||
*/
|
||||
class DriveAndShootAutonomous : public frc::CommandGroup {
|
||||
public:
|
||||
DriveAndShootAutonomous();
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "DriveForward.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
void DriveForward::init(double dist, double maxSpeed) {
|
||||
Requires(Robot::drivetrain.get());
|
||||
distance = dist;
|
||||
driveForwardSpeed = maxSpeed;
|
||||
}
|
||||
|
||||
DriveForward::DriveForward() {
|
||||
init(10, 0.5);
|
||||
}
|
||||
|
||||
DriveForward::DriveForward(double dist) {
|
||||
init(dist, 0.5);
|
||||
}
|
||||
|
||||
DriveForward::DriveForward(double dist, double maxSpeed) {
|
||||
init(dist, maxSpeed);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void DriveForward::Initialize() {
|
||||
Robot::drivetrain->GetRightEncoder()->Reset();
|
||||
SetTimeout(2);
|
||||
}
|
||||
|
||||
// Called repeatedly when this Command is scheduled to run
|
||||
void DriveForward::Execute() {
|
||||
error = (distance
|
||||
- Robot::drivetrain->GetRightEncoder()->GetDistance());
|
||||
if (driveForwardSpeed * kP * error >= driveForwardSpeed) {
|
||||
Robot::drivetrain->TankDrive(
|
||||
driveForwardSpeed, driveForwardSpeed);
|
||||
} else {
|
||||
Robot::drivetrain->TankDrive(driveForwardSpeed * kP * error,
|
||||
driveForwardSpeed * kP * error);
|
||||
}
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool DriveForward::IsFinished() {
|
||||
return (std::fabs(error) <= kTolerance) || IsTimedOut();
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
void DriveForward::End() {
|
||||
Robot::drivetrain->Stop();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* This command drives the robot over a given distance with simple proportional
|
||||
* control This command will drive a given distance limiting to a maximum speed.
|
||||
*/
|
||||
class DriveForward : public frc::Command {
|
||||
public:
|
||||
DriveForward();
|
||||
explicit DriveForward(double dist);
|
||||
DriveForward(double dist, double maxSpeed);
|
||||
void Initialize() override;
|
||||
void Execute() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
|
||||
private:
|
||||
double driveForwardSpeed;
|
||||
double distance;
|
||||
double error = 0;
|
||||
static constexpr double kTolerance = 0.1;
|
||||
static constexpr double kP = -1.0 / 5.0;
|
||||
|
||||
void init(double dist, double maxSpeed);
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "DriveWithJoystick.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
DriveWithJoystick::DriveWithJoystick() {
|
||||
Requires(Robot::drivetrain.get());
|
||||
}
|
||||
|
||||
// Called repeatedly when this Command is scheduled to run
|
||||
void DriveWithJoystick::Execute() {
|
||||
Robot::drivetrain->TankDrive(Robot::oi->GetJoystick());
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool DriveWithJoystick::IsFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
void DriveWithJoystick::End() {
|
||||
Robot::drivetrain->Stop();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* This command allows PS3 joystick to drive the robot. It is always running
|
||||
* except when interrupted by another command.
|
||||
*/
|
||||
class DriveWithJoystick : public frc::Command {
|
||||
public:
|
||||
DriveWithJoystick();
|
||||
void Execute() override;
|
||||
bool IsFinished() override;
|
||||
void End() override;
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "ExtendShooter.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
ExtendShooter::ExtendShooter()
|
||||
: frc::TimedCommand(1.0) {
|
||||
Requires(Robot::shooter.get());
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void ExtendShooter::Initialize() {
|
||||
Robot::shooter->ExtendBoth();
|
||||
}
|
||||
|
||||
// Called once after isFinished returns true
|
||||
void ExtendShooter::End() {
|
||||
Robot::shooter->RetractBoth();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/TimedCommand.h>
|
||||
|
||||
/**
|
||||
* Extend the shooter and then retract it after a second.
|
||||
*/
|
||||
class ExtendShooter : public frc::TimedCommand {
|
||||
public:
|
||||
ExtendShooter();
|
||||
void Initialize() override;
|
||||
void End() override;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "LowGoal.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
#include "ExtendShooter.h"
|
||||
#include "SetCollectionSpeed.h"
|
||||
#include "SetPivotSetpoint.h"
|
||||
|
||||
LowGoal::LowGoal() {
|
||||
AddSequential(new SetPivotSetpoint(Pivot::kLowGoal));
|
||||
AddSequential(new SetCollectionSpeed(Collector::kReverse));
|
||||
AddSequential(new ExtendShooter());
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Spit the ball out into the low goal assuming that the robot is in front of
|
||||
* it.
|
||||
*/
|
||||
class LowGoal : public frc::CommandGroup {
|
||||
public:
|
||||
LowGoal();
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "OpenClaw.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
OpenClaw::OpenClaw() {
|
||||
Requires(Robot::collector.get());
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void OpenClaw::Initialize() {
|
||||
Robot::collector->Open();
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool OpenClaw::IsFinished() {
|
||||
return Robot::collector->IsOpen();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Opens the claw
|
||||
*/
|
||||
class OpenClaw : public frc::Command {
|
||||
public:
|
||||
OpenClaw();
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "SetCollectionSpeed.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
SetCollectionSpeed::SetCollectionSpeed(double speed) {
|
||||
Requires(Robot::collector.get());
|
||||
this->speed = speed;
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void SetCollectionSpeed::Initialize() {
|
||||
Robot::collector->SetSpeed(speed);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/InstantCommand.h>
|
||||
|
||||
/**
|
||||
* This command sets the collector rollers spinning at the given speed. Since
|
||||
* there is no sensor for detecting speed, it finishes immediately. As a result,
|
||||
* the spinners may still be adjusting their speed.
|
||||
*/
|
||||
class SetCollectionSpeed : public frc::InstantCommand {
|
||||
public:
|
||||
explicit SetCollectionSpeed(double speed);
|
||||
void Initialize() override;
|
||||
|
||||
private:
|
||||
double speed;
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "SetPivotSetpoint.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
SetPivotSetpoint::SetPivotSetpoint(double setpoint) {
|
||||
this->setpoint = setpoint;
|
||||
Requires(Robot::pivot.get());
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
void SetPivotSetpoint::Initialize() {
|
||||
Robot::pivot->Enable();
|
||||
Robot::pivot->SetSetpoint(setpoint);
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool SetPivotSetpoint::IsFinished() {
|
||||
return Robot::pivot->OnTarget();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Moves the pivot to a given angle. This command finishes when it is within
|
||||
* the tolerance, but leaves the PID loop running to maintain the position.
|
||||
* Other commands using the pivot should make sure they disable PID!
|
||||
*/
|
||||
class SetPivotSetpoint : public frc::Command {
|
||||
public:
|
||||
explicit SetPivotSetpoint(double setpoint);
|
||||
void Initialize() override;
|
||||
bool IsFinished() override;
|
||||
|
||||
private:
|
||||
double setpoint;
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Shoot.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
#include "ExtendShooter.h"
|
||||
#include "OpenClaw.h"
|
||||
#include "SetCollectionSpeed.h"
|
||||
#include "WaitForPressure.h"
|
||||
|
||||
Shoot::Shoot() {
|
||||
AddSequential(new WaitForPressure());
|
||||
AddSequential(new SetCollectionSpeed(Collector::kStop));
|
||||
AddSequential(new OpenClaw());
|
||||
AddSequential(new ExtendShooter());
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/CommandGroup.h>
|
||||
|
||||
/**
|
||||
* Shoot the ball at the current angle.
|
||||
*/
|
||||
class Shoot : public frc::CommandGroup {
|
||||
public:
|
||||
Shoot();
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "WaitForBall.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
WaitForBall::WaitForBall() {
|
||||
Requires(Robot::collector.get());
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool WaitForBall::IsFinished() {
|
||||
return Robot::collector->HasBall();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Wait until the collector senses that it has the ball. This command does
|
||||
* nothing and is intended to be used in command groups to wait for this
|
||||
* condition.
|
||||
*/
|
||||
class WaitForBall : public frc::Command {
|
||||
public:
|
||||
WaitForBall();
|
||||
bool IsFinished() override;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "WaitForPressure.h"
|
||||
|
||||
#include "../Robot.h"
|
||||
|
||||
WaitForPressure::WaitForPressure() {
|
||||
Requires(Robot::pneumatics.get());
|
||||
}
|
||||
|
||||
// Make this return true when this Command no longer needs to run execute()
|
||||
bool WaitForPressure::IsFinished() {
|
||||
return Robot::pneumatics->IsPressurized();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Command.h>
|
||||
|
||||
/**
|
||||
* Wait until the pneumatics are fully pressurized. This command does nothing
|
||||
* and is intended to be used in command groups to wait for this condition.
|
||||
*/
|
||||
class WaitForPressure : public frc::Command {
|
||||
public:
|
||||
WaitForPressure();
|
||||
bool IsFinished() override;
|
||||
};
|
||||
41
wpilibcExamples/src/main/cpp/examples/PacGoat/src/OI.cpp
Normal file
41
wpilibcExamples/src/main/cpp/examples/PacGoat/src/OI.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "OI.h"
|
||||
|
||||
#include "Commands/Collect.h"
|
||||
#include "Commands/DriveForward.h"
|
||||
#include "Commands/LowGoal.h"
|
||||
#include "Commands/SetCollectionSpeed.h"
|
||||
#include "Commands/SetPivotSetpoint.h"
|
||||
#include "Commands/Shoot.h"
|
||||
#include "Subsystems/Collector.h"
|
||||
#include "Subsystems/Pivot.h"
|
||||
|
||||
OI::OI() {
|
||||
R1.WhenPressed(new LowGoal());
|
||||
R2.WhenPressed(new Collect());
|
||||
|
||||
L1.WhenPressed(new SetPivotSetpoint(Pivot::kShoot));
|
||||
L2.WhenPressed(new SetPivotSetpoint(Pivot::kShootNear));
|
||||
|
||||
sticks.WhenActive(new Shoot());
|
||||
|
||||
// SmartDashboard Buttons
|
||||
frc::SmartDashboard::PutData("Drive Forward", new DriveForward(2.25));
|
||||
frc::SmartDashboard::PutData("Drive Backward", new DriveForward(-2.25));
|
||||
frc::SmartDashboard::PutData("Start Rollers",
|
||||
new SetCollectionSpeed(Collector::kForward));
|
||||
frc::SmartDashboard::PutData("Stop Rollers",
|
||||
new SetCollectionSpeed(Collector::kStop));
|
||||
frc::SmartDashboard::PutData("Reverse Rollers",
|
||||
new SetCollectionSpeed(Collector::kReverse));
|
||||
}
|
||||
|
||||
frc::Joystick* OI::GetJoystick() {
|
||||
return &joystick;
|
||||
}
|
||||
29
wpilibcExamples/src/main/cpp/examples/PacGoat/src/OI.h
Normal file
29
wpilibcExamples/src/main/cpp/examples/PacGoat/src/OI.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Buttons/JoystickButton.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
#include "Triggers/DoubleButton.h"
|
||||
|
||||
class OI {
|
||||
public:
|
||||
OI();
|
||||
frc::Joystick* GetJoystick();
|
||||
|
||||
private:
|
||||
frc::Joystick joystick{0};
|
||||
|
||||
frc::JoystickButton L1{&joystick, 11};
|
||||
frc::JoystickButton L2{&joystick, 9};
|
||||
frc::JoystickButton R1{&joystick, 12};
|
||||
frc::JoystickButton R2{&joystick, 10};
|
||||
|
||||
DoubleButton sticks{&joystick, 2, 3};
|
||||
};
|
||||
87
wpilibcExamples/src/main/cpp/examples/PacGoat/src/Robot.cpp
Normal file
87
wpilibcExamples/src/main/cpp/examples/PacGoat/src/Robot.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <SmartDashboard/SmartDashboard.h>
|
||||
|
||||
std::shared_ptr<DriveTrain> Robot::drivetrain = std::make_shared<DriveTrain>();
|
||||
std::shared_ptr<Pivot> Robot::pivot = std::make_shared<Pivot>();
|
||||
std::shared_ptr<Collector> Robot::collector = std::make_shared<Collector>();
|
||||
std::shared_ptr<Shooter> Robot::shooter = std::make_shared<Shooter>();
|
||||
std::shared_ptr<Pneumatics> Robot::pneumatics = std::make_shared<Pneumatics>();
|
||||
std::unique_ptr<OI> Robot::oi = std::make_unique<OI>();
|
||||
|
||||
void Robot::RobotInit() {
|
||||
// Show what command your subsystem is running on the SmartDashboard
|
||||
frc::SmartDashboard::PutData(drivetrain.get());
|
||||
frc::SmartDashboard::PutData(pivot.get());
|
||||
frc::SmartDashboard::PutData(collector.get());
|
||||
frc::SmartDashboard::PutData(shooter.get());
|
||||
frc::SmartDashboard::PutData(pneumatics.get());
|
||||
|
||||
// instantiate the command used for the autonomous period
|
||||
autoChooser.AddDefault("Drive and Shoot", driveAndShootAuto.get());
|
||||
autoChooser.AddObject("Drive Forward", driveForwardAuto.get());
|
||||
frc::SmartDashboard::PutData("Auto Mode", &autoChooser);
|
||||
|
||||
pneumatics->Start(); // Pressurize the pneumatics.
|
||||
}
|
||||
|
||||
void Robot::AutonomousInit() {
|
||||
autonomousCommand = autoChooser.GetSelected();
|
||||
autonomousCommand->Start();
|
||||
}
|
||||
|
||||
void Robot::AutonomousPeriodic() {
|
||||
frc::Scheduler::GetInstance()->Run();
|
||||
Log();
|
||||
}
|
||||
|
||||
void Robot::TeleopInit() {
|
||||
// This makes sure that the autonomous stops running when
|
||||
// teleop starts running. If you want the autonomous to
|
||||
// continue until interrupted by another command, remove
|
||||
// this line or comment it out.
|
||||
if (autonomousCommand != nullptr) {
|
||||
autonomousCommand->Cancel();
|
||||
}
|
||||
std::cout << "Starting Teleop" << std::endl;
|
||||
}
|
||||
|
||||
void Robot::TeleopPeriodic() {
|
||||
frc::Scheduler::GetInstance()->Run();
|
||||
Log();
|
||||
}
|
||||
|
||||
void Robot::TestPeriodic() {
|
||||
frc::LiveWindow::GetInstance()->Run();
|
||||
}
|
||||
|
||||
void Robot::DisabledInit() {
|
||||
shooter->Unlatch();
|
||||
}
|
||||
|
||||
void Robot::DisabledPeriodic() {
|
||||
Log();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log interesting values to the SmartDashboard.
|
||||
*/
|
||||
void Robot::Log() {
|
||||
Robot::pneumatics->WritePressure();
|
||||
frc::SmartDashboard::PutNumber("Pivot Pot Value", pivot->GetAngle());
|
||||
frc::SmartDashboard::PutNumber("Left Distance",
|
||||
drivetrain->GetLeftEncoder()->GetDistance());
|
||||
frc::SmartDashboard::PutNumber("Right Distance",
|
||||
drivetrain->GetRightEncoder()->GetDistance());
|
||||
}
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
51
wpilibcExamples/src/main/cpp/examples/PacGoat/src/Robot.h
Normal file
51
wpilibcExamples/src/main/cpp/examples/PacGoat/src/Robot.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <memory>
|
||||
|
||||
#include <Commands/Command.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <SmartDashboard/SendableChooser.h>
|
||||
|
||||
#include "Commands/DriveAndShootAutonomous.h"
|
||||
#include "Commands/DriveForward.h"
|
||||
#include "OI.h"
|
||||
#include "Subsystems/Collector.h"
|
||||
#include "Subsystems/DriveTrain.h"
|
||||
#include "Subsystems/Pivot.h"
|
||||
#include "Subsystems/Pneumatics.h"
|
||||
#include "Subsystems/Shooter.h"
|
||||
|
||||
class Robot : public IterativeRobot {
|
||||
public:
|
||||
static std::shared_ptr<DriveTrain> drivetrain;
|
||||
static std::shared_ptr<Pivot> pivot;
|
||||
static std::shared_ptr<Collector> collector;
|
||||
static std::shared_ptr<Shooter> shooter;
|
||||
static std::shared_ptr<Pneumatics> pneumatics;
|
||||
static std::unique_ptr<OI> oi;
|
||||
|
||||
private:
|
||||
frc::Command* autonomousCommand = nullptr;
|
||||
std::unique_ptr<frc::Command> driveAndShootAuto{
|
||||
new DriveAndShootAutonomous()};
|
||||
std::unique_ptr<frc::Command> driveForwardAuto{new DriveForward()};
|
||||
SendableChooser<frc::Command*> autoChooser;
|
||||
|
||||
void RobotInit() override;
|
||||
void AutonomousInit() override;
|
||||
void AutonomousPeriodic() override;
|
||||
void TeleopInit() override;
|
||||
void TeleopPeriodic() override;
|
||||
void TestPeriodic() override;
|
||||
void DisabledInit() override;
|
||||
void DisabledPeriodic() override;
|
||||
|
||||
void Log();
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Collector.h"
|
||||
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
|
||||
Collector::Collector()
|
||||
: frc::Subsystem("Collector") {
|
||||
// Put everything to the LiveWindow for testing.
|
||||
// XXX: LiveWindow::GetInstance()->AddActuator("Collector", "Roller
|
||||
// Motor", &rollerMotor);
|
||||
LiveWindow::GetInstance()->AddSensor(
|
||||
"Collector", "Ball Detector", &ballDetector);
|
||||
LiveWindow::GetInstance()->AddSensor(
|
||||
"Collector", "Claw Open Detector", &openDetector);
|
||||
LiveWindow::GetInstance()->AddActuator("Collector", "Piston", &piston);
|
||||
}
|
||||
|
||||
bool Collector::HasBall() {
|
||||
return ballDetector.Get(); // TODO: prepend ! to reflect real robot
|
||||
}
|
||||
|
||||
void Collector::SetSpeed(double speed) {
|
||||
rollerMotor.Set(-speed);
|
||||
}
|
||||
|
||||
void Collector::Stop() {
|
||||
rollerMotor.Set(0);
|
||||
}
|
||||
|
||||
bool Collector::IsOpen() {
|
||||
return openDetector.Get(); // TODO: prepend ! to reflect real robot
|
||||
}
|
||||
|
||||
void Collector::Open() {
|
||||
piston.Set(true);
|
||||
}
|
||||
|
||||
void Collector::Close() {
|
||||
piston.Set(false);
|
||||
}
|
||||
|
||||
void Collector::InitDefaultCommand() {}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Subsystem.h>
|
||||
#include <DigitalInput.h>
|
||||
#include <Solenoid.h>
|
||||
#include <Victor.h>
|
||||
|
||||
/**
|
||||
* The Collector subsystem has one motor for the rollers, a limit switch for
|
||||
* ball
|
||||
* detection, a piston for opening and closing the claw, and a reed switch to
|
||||
* check if the piston is open.
|
||||
*/
|
||||
class Collector : public frc::Subsystem {
|
||||
public:
|
||||
// Constants for some useful speeds
|
||||
static constexpr double kForward = 1;
|
||||
static constexpr double kStop = 0;
|
||||
static constexpr double kReverse = -1;
|
||||
|
||||
Collector();
|
||||
|
||||
/**
|
||||
* NOTE: The current simulation model uses the the lower part of the
|
||||
* claw
|
||||
* since the limit switch wasn't exported. At some point, this will be
|
||||
* updated.
|
||||
*
|
||||
* @return Whether or not the robot has the ball.
|
||||
*/
|
||||
bool HasBall();
|
||||
|
||||
/**
|
||||
* @param speed The speed to spin the rollers.
|
||||
*/
|
||||
void SetSpeed(double speed);
|
||||
|
||||
/**
|
||||
* Stop the rollers from spinning
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* @return Whether or not the claw is open.
|
||||
*/
|
||||
bool IsOpen();
|
||||
|
||||
/**
|
||||
* Open the claw up. (For shooting)
|
||||
*/
|
||||
void Open();
|
||||
|
||||
/**
|
||||
* Close the claw. (For collecting and driving)
|
||||
*/
|
||||
void Close();
|
||||
|
||||
/**
|
||||
* No default command.
|
||||
*/
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
private:
|
||||
// Subsystem devices
|
||||
frc::Victor rollerMotor{6};
|
||||
frc::DigitalInput ballDetector{10};
|
||||
frc::Solenoid piston{1};
|
||||
frc::DigitalInput openDetector{6};
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "DriveTrain.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <Joystick.h>
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
|
||||
#include "../Commands/DriveWithJoystick.h"
|
||||
|
||||
DriveTrain::DriveTrain()
|
||||
: frc::Subsystem("DriveTrain") {
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("DriveTrain", "Front Left
|
||||
// CIM", &frontLeftCIM);
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("DriveTrain", "Front
|
||||
// Right CIM", &frontRightCIM);
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("DriveTrain", "Back Left
|
||||
// CIM", &backLeftCIM);
|
||||
// frc::LiveWindow::GetInstance()->AddActuator("DriveTrain", "Back Right
|
||||
// CIM", &backRightCIM);
|
||||
|
||||
// Configure the RobotDrive to reflect the fact that all our motors are
|
||||
// wired backwards and our drivers sensitivity preferences.
|
||||
drive.SetSafetyEnabled(false);
|
||||
drive.SetExpiration(0.1);
|
||||
drive.SetSensitivity(0.5);
|
||||
drive.SetMaxOutput(1.0);
|
||||
drive.SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);
|
||||
drive.SetInvertedMotor(RobotDrive::kRearLeftMotor, true);
|
||||
drive.SetInvertedMotor(RobotDrive::kFrontRightMotor, true);
|
||||
drive.SetInvertedMotor(RobotDrive::kRearRightMotor, true);
|
||||
|
||||
// Configure encoders
|
||||
rightEncoder->SetPIDSourceType(PIDSourceType::kDisplacement);
|
||||
leftEncoder->SetPIDSourceType(PIDSourceType::kDisplacement);
|
||||
|
||||
#ifndef SIMULATION
|
||||
// Converts to feet
|
||||
rightEncoder->SetDistancePerPulse(0.0785398);
|
||||
leftEncoder->SetDistancePerPulse(0.0785398);
|
||||
#else
|
||||
// Convert to feet 4in diameter wheels with 360 tick simulated encoders
|
||||
rightEncoder->SetDistancePerPulse(
|
||||
(4.0 /*in*/ * M_PI) / (360.0 * 12.0 /*in/ft*/));
|
||||
leftEncoder->SetDistancePerPulse(
|
||||
(4.0 /*in*/ * M_PI) / (360.0 * 12.0 /*in/ft*/));
|
||||
#endif
|
||||
|
||||
LiveWindow::GetInstance()->AddSensor(
|
||||
"DriveTrain", "Right Encoder", rightEncoder);
|
||||
LiveWindow::GetInstance()->AddSensor(
|
||||
"DriveTrain", "Left Encoder", leftEncoder);
|
||||
|
||||
// Configure gyro
|
||||
#ifndef SIMULATION
|
||||
gyro.SetSensitivity(0.007); // TODO: Handle more gracefully?
|
||||
#endif
|
||||
LiveWindow::GetInstance()->AddSensor("DriveTrain", "Gyro", &gyro);
|
||||
}
|
||||
|
||||
void DriveTrain::InitDefaultCommand() {
|
||||
SetDefaultCommand(new DriveWithJoystick());
|
||||
}
|
||||
|
||||
void DriveTrain::TankDrive(Joystick* joy) {
|
||||
drive.TankDrive(joy->GetY(), joy->GetRawAxis(4));
|
||||
}
|
||||
|
||||
void DriveTrain::TankDrive(double leftAxis, double rightAxis) {
|
||||
drive.TankDrive(leftAxis, rightAxis);
|
||||
}
|
||||
|
||||
void DriveTrain::Stop() {
|
||||
drive.TankDrive(0.0, 0.0);
|
||||
}
|
||||
|
||||
std::shared_ptr<Encoder> DriveTrain::GetLeftEncoder() {
|
||||
return leftEncoder;
|
||||
}
|
||||
|
||||
std::shared_ptr<Encoder> DriveTrain::GetRightEncoder() {
|
||||
return rightEncoder;
|
||||
}
|
||||
|
||||
double DriveTrain::GetAngle() {
|
||||
return gyro.GetAngle();
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <memory>
|
||||
|
||||
#include <AnalogGyro.h>
|
||||
#include <Commands/Subsystem.h>
|
||||
#include <Encoder.h>
|
||||
#include <RobotDrive.h>
|
||||
#include <Victor.h>
|
||||
|
||||
namespace frc {
|
||||
class Joystick;
|
||||
}
|
||||
|
||||
/**
|
||||
* The DriveTrain subsystem controls the robot's chassis and reads in
|
||||
* information about it's speed and position.
|
||||
*/
|
||||
class DriveTrain : public frc::Subsystem {
|
||||
public:
|
||||
DriveTrain();
|
||||
|
||||
/**
|
||||
* When other commands aren't using the drivetrain, allow tank drive
|
||||
* with
|
||||
* the joystick.
|
||||
*/
|
||||
void InitDefaultCommand();
|
||||
|
||||
/**
|
||||
* @param joy PS3 style joystick to use as the input for tank drive.
|
||||
*/
|
||||
void TankDrive(frc::Joystick* joy);
|
||||
|
||||
/**
|
||||
* @param leftAxis Left sides value
|
||||
* @param rightAxis Right sides value
|
||||
*/
|
||||
void TankDrive(double leftAxis, double rightAxis);
|
||||
|
||||
/**
|
||||
* Stop the drivetrain from moving.
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* @return The encoder getting the distance and speed of left side of
|
||||
* the drivetrain.
|
||||
*/
|
||||
std::shared_ptr<Encoder> GetLeftEncoder();
|
||||
|
||||
/**
|
||||
* @return The encoder getting the distance and speed of right side of
|
||||
* the drivetrain.
|
||||
*/
|
||||
std::shared_ptr<Encoder> GetRightEncoder();
|
||||
|
||||
/**
|
||||
* @return The current angle of the drivetrain.
|
||||
*/
|
||||
double GetAngle();
|
||||
|
||||
private:
|
||||
// Subsystem devices
|
||||
frc::Victor frontLeftCIM{1};
|
||||
frc::Victor rearLeftCIM{2};
|
||||
frc::Victor frontRightCIM{3};
|
||||
frc::Victor rearRightCIM{4};
|
||||
frc::RobotDrive drive{frontRightCIM, rearLeftCIM, frontRightCIM,
|
||||
rearRightCIM};
|
||||
std::shared_ptr<frc::Encoder> rightEncoder =
|
||||
std::make_shared<frc::Encoder>(
|
||||
1, 2, true, Encoder::k4X);
|
||||
std::shared_ptr<frc::Encoder> leftEncoder =
|
||||
std::make_shared<frc::Encoder>(
|
||||
3, 4, false, Encoder::k4X);
|
||||
frc::AnalogGyro gyro{0};
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Pivot.h"
|
||||
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
|
||||
Pivot::Pivot()
|
||||
: frc::PIDSubsystem("Pivot", 7.0, 0.0, 8.0) {
|
||||
SetAbsoluteTolerance(0.005);
|
||||
GetPIDController()->SetContinuous(false);
|
||||
#ifdef SIMULATION
|
||||
// PID is different in simulation.
|
||||
GetPIDController()->SetPID(0.5, 0.001, 2);
|
||||
SetAbsoluteTolerance(5);
|
||||
#endif
|
||||
|
||||
// Put everything to the LiveWindow for testing.
|
||||
frc::LiveWindow::GetInstance()->AddSensor(
|
||||
"Pivot", "Upper Limit Switch", &upperLimitSwitch);
|
||||
frc::LiveWindow::GetInstance()->AddSensor(
|
||||
"Pivot", "Lower Limit Switch", &lowerLimitSwitch);
|
||||
// XXX: frc::LiveWindow::GetInstance()->AddSensor("Pivot", "Pot", &pot);
|
||||
// XXX: frc::LiveWindow::GetInstance()->AddActuator("Pivot", "Motor",
|
||||
// &motor);
|
||||
frc::LiveWindow::GetInstance()->AddActuator(
|
||||
"Pivot", "PIDSubsystem Controller", GetPIDController());
|
||||
}
|
||||
|
||||
void InitDefaultCommand() {}
|
||||
|
||||
double Pivot::ReturnPIDInput() {
|
||||
return pot.Get();
|
||||
}
|
||||
|
||||
void Pivot::UsePIDOutput(double output) {
|
||||
motor.PIDWrite(output);
|
||||
}
|
||||
|
||||
bool Pivot::IsAtUpperLimit() {
|
||||
return upperLimitSwitch.Get(); // TODO: inverted from real robot
|
||||
// (prefix with !)
|
||||
}
|
||||
|
||||
bool Pivot::IsAtLowerLimit() {
|
||||
return lowerLimitSwitch.Get(); // TODO: inverted from real robot
|
||||
// (prefix with !)
|
||||
}
|
||||
|
||||
double Pivot::GetAngle() {
|
||||
return pot.Get();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <AnalogPotentiometer.h>
|
||||
#include <Commands/PIDSubsystem.h>
|
||||
#include <DigitalInput.h>
|
||||
#include <Victor.h>
|
||||
|
||||
/**
|
||||
* The Pivot subsystem contains the Van-door motor and the pot for PID control
|
||||
* of angle of the pivot and claw.
|
||||
*/
|
||||
class Pivot : public frc::PIDSubsystem {
|
||||
public:
|
||||
// Constants for some useful angles
|
||||
static constexpr double kCollect = 105;
|
||||
static constexpr double kLowGoal = 90;
|
||||
static constexpr double kShoot = 45;
|
||||
static constexpr double kShootNear = 30;
|
||||
|
||||
Pivot();
|
||||
|
||||
/**
|
||||
* No default command, if PID is enabled, the current setpoint will be
|
||||
* maintained.
|
||||
*/
|
||||
void InitDefaultCommand() override {}
|
||||
|
||||
/**
|
||||
* @return The angle read in by the potentiometer
|
||||
*/
|
||||
double ReturnPIDInput() override;
|
||||
|
||||
/**
|
||||
* Set the motor speed based off of the PID output
|
||||
*/
|
||||
void UsePIDOutput(double output) override;
|
||||
|
||||
/**
|
||||
* @return If the pivot is at its upper limit.
|
||||
*/
|
||||
bool IsAtUpperLimit();
|
||||
|
||||
/**
|
||||
* @return If the pivot is at its lower limit.
|
||||
*/
|
||||
bool IsAtLowerLimit();
|
||||
|
||||
/**
|
||||
* @return The current angle of the pivot.
|
||||
*/
|
||||
double GetAngle();
|
||||
|
||||
private:
|
||||
// Subsystem devices
|
||||
|
||||
// Sensors for measuring the position of the pivot
|
||||
frc::DigitalInput upperLimitSwitch{13};
|
||||
frc::DigitalInput lowerLimitSwitch{12};
|
||||
|
||||
/* 0 degrees is vertical facing up.
|
||||
* Angle increases the more forward the pivot goes.
|
||||
*/
|
||||
frc::AnalogPotentiometer pot{1};
|
||||
|
||||
// Motor to move the pivot
|
||||
frc::Victor motor{5};
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Pneumatics.h"
|
||||
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
|
||||
Pneumatics::Pneumatics()
|
||||
: frc::Subsystem("Pneumatics") {
|
||||
frc::LiveWindow::GetInstance()->AddSensor(
|
||||
"Pneumatics", "Pressure Sensor", pressureSensor);
|
||||
}
|
||||
|
||||
/**
|
||||
* No default command
|
||||
*/
|
||||
void Pneumatics::InitDefaultCommand() {}
|
||||
|
||||
/**
|
||||
* Start the compressor going. The compressor automatically starts and stops as
|
||||
* it goes above and below maximum pressure.
|
||||
*/
|
||||
void Pneumatics::Start() {
|
||||
#ifndef SIMULATION
|
||||
compressor.Start();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not the system is fully pressurized.
|
||||
*/
|
||||
bool Pneumatics::IsPressurized() {
|
||||
#ifndef SIMULATION
|
||||
return kMaxPressure <= pressureSensor.GetVoltage();
|
||||
#else
|
||||
return true; // NOTE: Simulation always has full pressure
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the pressure on the SmartDashboard.
|
||||
*/
|
||||
void Pneumatics::WritePressure() {
|
||||
frc::SmartDashboard::PutNumber("Pressure", pressureSensor.GetVoltage());
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <AnalogInput.h>
|
||||
#include <Commands/Subsystem.h>
|
||||
#include <Compressor.h>
|
||||
|
||||
/**
|
||||
* The Pneumatics subsystem contains the compressor and a pressure sensor.
|
||||
*
|
||||
* NOTE: The simulator currently doesn't support the compressor or pressure
|
||||
* sensors.
|
||||
*/
|
||||
class Pneumatics : public frc::Subsystem {
|
||||
public:
|
||||
Pneumatics();
|
||||
|
||||
/**
|
||||
* No default command
|
||||
*/
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
/**
|
||||
* Start the compressor going. The compressor automatically starts and
|
||||
* stops as it goes above and below maximum pressure.
|
||||
*/
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* @return Whether or not the system is fully pressurized.
|
||||
*/
|
||||
bool IsPressurized();
|
||||
|
||||
/**
|
||||
* Puts the pressure on the SmartDashboard.
|
||||
*/
|
||||
void WritePressure();
|
||||
|
||||
private:
|
||||
frc::AnalogInput pressureSensor{3};
|
||||
|
||||
#ifndef SIMULATION
|
||||
frc::Compressor compressor{1}; // TODO: (1, 14, 1, 8);
|
||||
#endif
|
||||
|
||||
static constexpr double kMaxPressure = 2.55;
|
||||
};
|
||||
@@ -0,0 +1,91 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "Shooter.h"
|
||||
|
||||
#include <LiveWindow/LiveWindow.h>
|
||||
|
||||
Shooter::Shooter()
|
||||
: Subsystem("Shooter") {
|
||||
// Put everything to the LiveWindow for testing.
|
||||
frc::LiveWindow::GetInstance()->AddSensor(
|
||||
"Shooter", "Hot Goal Sensor", &hotGoalSensor);
|
||||
frc::LiveWindow::GetInstance()->AddSensor("Shooter",
|
||||
"Piston1 Reed Switch Front ", &piston1ReedSwitchFront);
|
||||
frc::LiveWindow::GetInstance()->AddSensor("Shooter",
|
||||
"Piston1 Reed Switch Back ", &piston1ReedSwitchBack);
|
||||
frc::LiveWindow::GetInstance()->AddActuator(
|
||||
"Shooter", "Latch Piston", &latchPiston);
|
||||
}
|
||||
|
||||
void Shooter::InitDefaultCommand() {
|
||||
// Set the default command for a subsystem here.
|
||||
// SetDefaultCommand(new MySpecialCommand());
|
||||
}
|
||||
|
||||
void Shooter::ExtendBoth() {
|
||||
piston1.Set(frc::DoubleSolenoid::kForward);
|
||||
piston2.Set(frc::DoubleSolenoid::kForward);
|
||||
}
|
||||
|
||||
void Shooter::RetractBoth() {
|
||||
piston1.Set(frc::DoubleSolenoid::kReverse);
|
||||
piston2.Set(frc::DoubleSolenoid::kReverse);
|
||||
}
|
||||
|
||||
void Shooter::Extend1() {
|
||||
piston1.Set(frc::DoubleSolenoid::kForward);
|
||||
}
|
||||
|
||||
void Shooter::Retract1() {
|
||||
piston1.Set(frc::DoubleSolenoid::kReverse);
|
||||
}
|
||||
|
||||
void Shooter::Extend2() {
|
||||
piston2.Set(frc::DoubleSolenoid::kReverse);
|
||||
}
|
||||
|
||||
void Shooter::Retract2() {
|
||||
piston2.Set(frc::DoubleSolenoid::kForward);
|
||||
}
|
||||
|
||||
void Shooter::Off1() {
|
||||
piston1.Set(frc::DoubleSolenoid::kOff);
|
||||
}
|
||||
|
||||
void Shooter::Off2() {
|
||||
piston2.Set(frc::DoubleSolenoid::kOff);
|
||||
}
|
||||
|
||||
void Shooter::Unlatch() {
|
||||
latchPiston.Set(true);
|
||||
}
|
||||
|
||||
void Shooter::Latch() {
|
||||
latchPiston.Set(false);
|
||||
}
|
||||
|
||||
void Shooter::ToggleLatchPosition() {
|
||||
latchPiston.Set(!latchPiston.Get());
|
||||
}
|
||||
|
||||
bool Shooter::Piston1IsExtended() {
|
||||
return !piston1ReedSwitchFront.Get();
|
||||
}
|
||||
|
||||
bool Shooter::Piston1IsRetracted() {
|
||||
return !piston1ReedSwitchBack.Get();
|
||||
}
|
||||
|
||||
void Shooter::OffBoth() {
|
||||
piston1.Set(frc::DoubleSolenoid::kOff);
|
||||
piston2.Set(frc::DoubleSolenoid::kOff);
|
||||
}
|
||||
|
||||
bool Shooter::GoalIsHot() {
|
||||
return hotGoalSensor.Get();
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Commands/Subsystem.h>
|
||||
#include <DigitalInput.h>
|
||||
#include <DoubleSolenoid.h>
|
||||
#include <Solenoid.h>
|
||||
|
||||
/**
|
||||
* The Shooter subsystem handles shooting. The mechanism for shooting is
|
||||
* slightly complicated because it has to pneumatic cylinders for shooting, and
|
||||
* a third latch to allow the pressure to partially build up and reduce the
|
||||
* effect of the airflow. For shorter shots, when full power isn't needed, only
|
||||
* one cylinder fires.
|
||||
*
|
||||
* NOTE: Simulation currently approximates this as as single pneumatic cylinder
|
||||
* and ignores the latch.
|
||||
*/
|
||||
class Shooter : public frc::Subsystem {
|
||||
public:
|
||||
Shooter();
|
||||
void InitDefaultCommand() override;
|
||||
|
||||
/**
|
||||
* Extend both solenoids to shoot.
|
||||
*/
|
||||
void ExtendBoth();
|
||||
|
||||
/**
|
||||
* Retract both solenoids to prepare to shoot.
|
||||
*/
|
||||
void RetractBoth();
|
||||
|
||||
/**
|
||||
* Extend solenoid 1 to shoot.
|
||||
*/
|
||||
void Extend1();
|
||||
|
||||
/**
|
||||
* Retract solenoid 1 to prepare to shoot.
|
||||
*/
|
||||
void Retract1();
|
||||
|
||||
/**
|
||||
* Extend solenoid 2 to shoot.
|
||||
*/
|
||||
void Extend2();
|
||||
|
||||
/**
|
||||
* Retract solenoid 2 to prepare to shoot.
|
||||
*/
|
||||
void Retract2();
|
||||
|
||||
/**
|
||||
* Turns off the piston1 double solenoid. This won't actuate anything
|
||||
* because double solenoids preserve their state when turned off. This
|
||||
* should be called in order to reduce the amount of time that the coils
|
||||
* are
|
||||
* powered.
|
||||
*/
|
||||
void Off1();
|
||||
|
||||
/**
|
||||
* Turns off the piston1 double solenoid. This won't actuate anything
|
||||
* because double solenoids preserve their state when turned off. This
|
||||
* should be called in order to reduce the amount of time that the coils
|
||||
* are
|
||||
* powered.
|
||||
*/
|
||||
void Off2();
|
||||
|
||||
/**
|
||||
* Release the latch so that we can shoot
|
||||
*/
|
||||
void Unlatch();
|
||||
|
||||
/**
|
||||
* Latch so that pressure can build up and we aren't limited by air
|
||||
* flow.
|
||||
*/
|
||||
void Latch();
|
||||
|
||||
/**
|
||||
* Toggles the latch postions
|
||||
*/
|
||||
void ToggleLatchPosition();
|
||||
|
||||
/**
|
||||
* @return Whether or not piston 1 is fully extended.
|
||||
*/
|
||||
bool Piston1IsExtended();
|
||||
|
||||
/**
|
||||
* @return Whether or not piston 1 is fully retracted.
|
||||
*/
|
||||
bool Piston1IsRetracted();
|
||||
|
||||
/**
|
||||
* Turns off all double solenoids. Double solenoids hold their position
|
||||
* when
|
||||
* they are turned off. We should turn them off whenever possible to
|
||||
* extend
|
||||
* the life of the coils
|
||||
*/
|
||||
void OffBoth();
|
||||
|
||||
/**
|
||||
* @return Whether or not the goal is hot as read by the banner sensor
|
||||
*/
|
||||
bool GoalIsHot();
|
||||
|
||||
private:
|
||||
// Devices
|
||||
frc::DoubleSolenoid piston1{3, 4};
|
||||
frc::DoubleSolenoid piston2{5, 6};
|
||||
frc::Solenoid latchPiston{1, 2};
|
||||
frc::DigitalInput piston1ReedSwitchFront{9};
|
||||
frc::DigitalInput piston1ReedSwitchBack{11};
|
||||
frc::DigitalInput hotGoalSensor{
|
||||
7}; // NOTE: Currently ignored in simulation
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 "DoubleButton.h"
|
||||
|
||||
#include <Joystick.h>
|
||||
|
||||
DoubleButton::DoubleButton(frc::Joystick* joy, int button1, int button2) {
|
||||
this->joy = joy;
|
||||
this->button1 = button1;
|
||||
this->button2 = button2;
|
||||
}
|
||||
|
||||
bool DoubleButton::Get() {
|
||||
return joy->GetRawButton(button1) && joy->GetRawButton(button2);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <Buttons/Trigger.h>
|
||||
|
||||
namespace frc {
|
||||
class Joystick;
|
||||
}
|
||||
|
||||
class DoubleButton : public frc::Trigger {
|
||||
public:
|
||||
DoubleButton(frc::Joystick* joy, int button1, int button2);
|
||||
|
||||
bool Get();
|
||||
|
||||
private:
|
||||
frc::Joystick* joy;
|
||||
int button1;
|
||||
int button2;
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <array>
|
||||
|
||||
#include <AnalogInput.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <Joystick.h>
|
||||
#include <PIDController.h>
|
||||
#include <Spark.h>
|
||||
|
||||
/**
|
||||
* This is a sample program to demonstrate how to use a soft potentiometer and a
|
||||
* PID Controller to reach and maintain position setpoints on an elevator
|
||||
* mechanism.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void RobotInit() override { pidController.SetInputRange(0, 5); }
|
||||
|
||||
void TeleopInit() override { pidController.Enable(); }
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
// when the button is pressed once, the selected elevator
|
||||
// setpoint
|
||||
// is incremented
|
||||
bool currentButtonValue = joystick.GetTrigger();
|
||||
if (currentButtonValue && !previousButtonValue) {
|
||||
// index of the elevator setpoint wraps around.
|
||||
index = (index + 1) % (sizeof(kSetPoints) / 8);
|
||||
}
|
||||
previousButtonValue = currentButtonValue;
|
||||
|
||||
pidController.SetSetpoint(kSetPoints[index]);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int kPotChannel = 1;
|
||||
static constexpr int kMotorChannel = 7;
|
||||
static constexpr int kJoystickChannel = 0;
|
||||
|
||||
// Bottom, middle, and top elevator setpoints
|
||||
static constexpr std::array<double, 3> kSetPoints = {1.0, 2.6, 4.3};
|
||||
|
||||
/* proportional, integral, and derivative speed constants; motor
|
||||
* inverted
|
||||
* DANGER: when tuning PID constants, high/inappropriate values for
|
||||
* pGain,
|
||||
* iGain, and dGain may cause dangerous, uncontrollable, or
|
||||
* undesired behavior!
|
||||
*
|
||||
* These may need to be positive for a non-inverted motor
|
||||
*/
|
||||
static constexpr double kP = -5.0;
|
||||
static constexpr double kI = -0.02;
|
||||
static constexpr double kD = -2.0;
|
||||
|
||||
int index = 0;
|
||||
bool previousButtonValue = false;
|
||||
|
||||
frc::AnalogInput potentiometer{kPotChannel};
|
||||
frc::Joystick joystick{kJoystickChannel};
|
||||
frc::Spark elevatorMotor{kMotorChannel};
|
||||
|
||||
/* potentiometer (AnalogInput) and elevatorMotor (Victor) can be used as
|
||||
* a
|
||||
* PIDSource and PIDOutput respectively. The PIDController takes
|
||||
* pointers
|
||||
* to the PIDSource and PIDOutput, so you must use &potentiometer and
|
||||
* &elevatorMotor to get their pointers.
|
||||
*/
|
||||
frc::PIDController pidController{
|
||||
kP, kI, kD, &potentiometer, &elevatorMotor};
|
||||
};
|
||||
|
||||
constexpr std::array<double, 3> Robot::kSetPoints;
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,25 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <CameraServer.h>
|
||||
#include <IterativeRobot.h>
|
||||
|
||||
/**
|
||||
* Uses the CameraServer class to automatically capture video from a USB webcam
|
||||
* and send it to the FRC dashboard without doing any vision processing. This
|
||||
* is the easiest way to get camera images to the dashboard. Just add this to
|
||||
* the
|
||||
* RobotInit() method in your program.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void RobotInit() {
|
||||
CameraServer::GetInstance()->StartAutomaticCapture();
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
55
wpilibcExamples/src/main/cpp/examples/Relay/src/Robot.cpp
Normal file
55
wpilibcExamples/src/main/cpp/examples/Relay/src/Robot.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <IterativeRobot.h>
|
||||
#include <Joystick.h>
|
||||
#include <Relay.h>
|
||||
|
||||
/**
|
||||
* This is a sample program which uses joystick buttons to control a relay.
|
||||
* A Relay (generally a spike) has two outputs, each of which can be at either
|
||||
* 0V or 12V and so can be used for actions such as turning a motor off,
|
||||
* full forwards, or full reverse, and is generally used on the compressor.
|
||||
* This program uses two buttons on a joystick and each button corresponds to
|
||||
* one output; pressing the button sets the output to 12V and releasing sets
|
||||
* it to 0V.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void TeleopPeriodic() override {
|
||||
/* Retrieve the button values. GetRawButton will return
|
||||
* true if the button is pressed and false if not.
|
||||
*/
|
||||
bool forward = m_stick.GetRawButton(kRelayForwardButton);
|
||||
bool reverse = m_stick.GetRawButton(kRelayReverseButton);
|
||||
|
||||
/* Depending on the button values, we want to use one of
|
||||
* kOn, kOff, kForward, or kReverse.
|
||||
* kOn sets both outputs to 12V, kOff sets both to 0V,
|
||||
* kForward sets forward to 12V and reverse to 0V, and
|
||||
* kReverse sets reverse to 12V and forward to 0V.
|
||||
*/
|
||||
if (forward && reverse) {
|
||||
m_relay.Set(Relay::kOn);
|
||||
} else if (forward) {
|
||||
m_relay.Set(Relay::kForward);
|
||||
} else if (reverse) {
|
||||
m_relay.Set(Relay::kReverse);
|
||||
} else {
|
||||
m_relay.Set(Relay::kOff);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
frc::Joystick m_stick{0};
|
||||
frc::Relay m_relay{0};
|
||||
|
||||
static constexpr int kRelayForwardButton = 1;
|
||||
static constexpr int kRelayReverseButton = 2;
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
67
wpilibcExamples/src/main/cpp/examples/Solenoid/src/Robot.cpp
Normal file
67
wpilibcExamples/src/main/cpp/examples/Solenoid/src/Robot.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <DoubleSolenoid.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <Joystick.h>
|
||||
#include <Solenoid.h>
|
||||
|
||||
/**
|
||||
* This is a sample program showing the use of the solenoid classes during
|
||||
* operator control.
|
||||
* Three buttons from a joystick will be used to control two solenoids:
|
||||
* One button to control the position of a single solenoid and the other
|
||||
* two buttons to control a double solenoid.
|
||||
* Single solenoids can either be on or off, such that the air diverted through
|
||||
* them goes through either one channel or the other.
|
||||
* Double solenoids have three states: Off, Forward, and Reverse. Forward and
|
||||
* Reverse divert the air through the two channels and correspond to the
|
||||
* on and off of a single solenoid, but a double solenoid can also be "off",
|
||||
* where both channels are diverted to exhaust such that there is no pressure
|
||||
* in either channel.
|
||||
* Additionally, double solenoids take up two channels on your PCM whereas
|
||||
* single solenoids only take a single channel.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void TeleopPeriodic() override {
|
||||
/* The output of GetRawButton is true/false depending on whether
|
||||
* the button is pressed; Set takes a boolean for for whether to
|
||||
* use the default (false) channel or the other (true).
|
||||
*/
|
||||
m_solenoid.Set(m_stick.GetRawButton(kSolenoidButton));
|
||||
|
||||
/* In order to set the double solenoid, we will say that if
|
||||
* neither
|
||||
* button is pressed, it is off, if just one button is pressed,
|
||||
* set the solenoid to correspond to that button, and if both
|
||||
* are pressed, set the solenoid to Forwards.
|
||||
*/
|
||||
if (m_stick.GetRawButton(kDoubleSolenoidForward)) {
|
||||
m_doubleSolenoid.Set(frc::DoubleSolenoid::kForward);
|
||||
} else if (m_stick.GetRawButton(kDoubleSolenoidReverse)) {
|
||||
m_doubleSolenoid.Set(frc::DoubleSolenoid::kReverse);
|
||||
} else {
|
||||
m_doubleSolenoid.Set(frc::DoubleSolenoid::kOff);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
frc::Joystick m_stick{0};
|
||||
|
||||
// Solenoid corresponds to a single solenoid.
|
||||
frc::Solenoid m_solenoid{0};
|
||||
|
||||
// DoubleSolenoid corresponds to a double solenoid.
|
||||
frc::DoubleSolenoid m_doubleSolenoid{1, 2};
|
||||
|
||||
static constexpr int kSolenoidButton = 1;
|
||||
static constexpr int kDoubleSolenoidForward = 2;
|
||||
static constexpr int kDoubleSolenoidReverse = 3;
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,49 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <AnalogInput.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <RobotDrive.h>
|
||||
|
||||
/**
|
||||
* This is a sample program demonstrating how to use an ultrasonic sensor and
|
||||
* proportional control to maintain a set distance from an object.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
/**
|
||||
* Tells the robot to drive to a set distance (in inches) from an object
|
||||
* using proportional control.
|
||||
*/
|
||||
void TeleopPeriodic() override {
|
||||
// sensor returns a value from 0-4095 that is scaled to inches
|
||||
double currentDistance = ultrasonic.GetValue() * kValueToInches;
|
||||
// convert distance error to a motor speed
|
||||
double currentSpeed = (kHoldDistance - currentDistance) * kP;
|
||||
// drive robot
|
||||
myRobot.Drive(currentSpeed, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
// Distance in inches the robot wants to stay from an object
|
||||
static constexpr int kHoldDistance = 12;
|
||||
|
||||
// Factor to convert sensor values to a distance in inches
|
||||
static constexpr double kValueToInches = 0.125;
|
||||
|
||||
// Proportional speed constant
|
||||
static constexpr double kP = 0.05;
|
||||
|
||||
static constexpr int kLeftMotorPort = 0;
|
||||
static constexpr int kRightMotorPort = 1;
|
||||
static constexpr int kUltrasonicPort = 0;
|
||||
|
||||
frc::AnalogInput ultrasonic{kUltrasonicPort};
|
||||
frc::RobotDrive myRobot{kLeftMotorPort, kRightMotorPort};
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
@@ -0,0 +1,79 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <AnalogInput.h>
|
||||
#include <IterativeRobot.h>
|
||||
#include <PIDController.h>
|
||||
#include <PIDOutput.h>
|
||||
#include <RobotDrive.h>
|
||||
|
||||
/**
|
||||
* This is a sample program demonstrating how to use an ultrasonic sensor and
|
||||
* proportional control to maintain a set distance from an object.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
/**
|
||||
* Drives the robot a set distance from an object using PID control and
|
||||
* the
|
||||
* ultrasonic sensor.
|
||||
*/
|
||||
void TeleopInit() override {
|
||||
// Set expected range to 0-24 inches; e.g. at 24 inches from
|
||||
// object go
|
||||
// full forward, at 0 inches from object go full backward.
|
||||
pidController.SetInputRange(0, 24 * kValueToInches);
|
||||
// Set setpoint of the pidController
|
||||
pidController.SetSetpoint(kHoldDistance * kValueToInches);
|
||||
pidController.Enable(); // begin PID control
|
||||
}
|
||||
|
||||
private:
|
||||
// internal class to write to myRobot (a RobotDrive object) using a
|
||||
// PIDOutput
|
||||
class MyPIDOutput : public frc::PIDOutput {
|
||||
public:
|
||||
explicit MyPIDOutput(frc::RobotDrive& r)
|
||||
: rd(r) {
|
||||
rd.SetSafetyEnabled(false);
|
||||
}
|
||||
|
||||
void PIDWrite(double output) override {
|
||||
rd.Drive(output, 0); // write to myRobot (RobotDrive)
|
||||
// by reference
|
||||
}
|
||||
|
||||
private:
|
||||
frc::RobotDrive& rd;
|
||||
};
|
||||
|
||||
// Distance in inches the robot wants to stay from an object
|
||||
static constexpr int kHoldDistance = 12;
|
||||
|
||||
// Factor to convert sensor values to a distance in inches
|
||||
static constexpr double kValueToInches = 0.125;
|
||||
|
||||
// proportional speed constant
|
||||
static constexpr double kP = 7.0;
|
||||
|
||||
// integral speed constant
|
||||
static constexpr double kI = 0.018;
|
||||
|
||||
// derivative speed constant
|
||||
static constexpr double kD = 1.5;
|
||||
|
||||
static constexpr int kLeftMotorPort = 0;
|
||||
static constexpr int kRightMotorPort = 1;
|
||||
static constexpr int kUltrasonicPort = 0;
|
||||
|
||||
frc::AnalogInput ultrasonic{kUltrasonicPort};
|
||||
frc::RobotDrive myRobot{kLeftMotorPort, kRightMotorPort};
|
||||
frc::PIDController pidController{
|
||||
kP, kI, kD, &ultrasonic, new MyPIDOutput(myRobot)};
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot)
|
||||
482
wpilibcExamples/src/main/cpp/examples/examples.xml
Normal file
482
wpilibcExamples/src/main/cpp/examples/examples.xml
Normal file
@@ -0,0 +1,482 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<examples>
|
||||
<!-- TODO add back in when there are enough samples to justify tags
|
||||
<tagDescription>
|
||||
<name>Simple Robot</name>
|
||||
<description>Examples for simple robot programs.</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Network Tables</name>
|
||||
<description>Examples of how to use Network Tables to accomplish a
|
||||
variety of tasks such as sending and receiving values to both
|
||||
dashboards and co-processors.</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Simulation</name>
|
||||
<description>Examples that can be run in simulation.</description>
|
||||
</tagDescription>-->
|
||||
<tagDescription>
|
||||
<name>Getting Started with C++</name>
|
||||
<description>Examples for getting started with FRC C++</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>CommandBased Robot</name>
|
||||
<description>Examples for CommandBased robot programs.</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Actuators</name>
|
||||
<description>Example programs that demonstrate the use of various actuators</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Analog</name>
|
||||
<description>Examples programs that show different uses of analog inputs,
|
||||
outputs and various analog sensors</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>CAN</name>
|
||||
<description>Example programs that demonstrate the use of the CAN components in the control
|
||||
system</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Complete List</name>
|
||||
<description>Complete list of all sample programs across all categories</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Digital</name>
|
||||
<description>Example programs that demonstrate the sensors that use the digital I/O ports</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>I2C</name>
|
||||
<description>Example programs that demonstrate the use of I2C and various sensors that use
|
||||
it</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Joystick</name>
|
||||
<description>Example programs that demonstate different uses of joysticks for robot
|
||||
driving</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Pneumatics</name>
|
||||
<description>Example programs that demonstrate the use of the compressor and solenoids</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Robot and Motor</name>
|
||||
<description>Example programs that demonstrate driving a robot and motors including safety,
|
||||
servos, etc.</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>SPI</name>
|
||||
<description>Example programs that demonstrate the use of the SPI bus and sensors that
|
||||
connect to it</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Safety</name>
|
||||
<description>Example programs that demonstate the motor safety classes and how to use them
|
||||
with your programs</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Sensors</name>
|
||||
<description>Example programs that demonstrate the use of the various commonly used sensors
|
||||
on FRC robots</description>
|
||||
</tagDescription>
|
||||
<tagDescription>
|
||||
<name>Vision</name>
|
||||
<description>Example programs that demonstrate the use of a camera for image acquisition and
|
||||
processing</description>
|
||||
</tagDescription>
|
||||
<example>
|
||||
<name>Motor Controller</name>
|
||||
<description>Demonstrate controlling a single motor with a Joystick.</description>
|
||||
<tags>
|
||||
<tag>Robot and Motor</tag>
|
||||
<tag>Actuators</tag>
|
||||
<tag>Joystick</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/MotorControl/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Motor Control With Encoder</name>
|
||||
<description>Demonstrate controlling a single motor with a Joystick and displaying the net
|
||||
movement of the motor using an encoder.</description>
|
||||
<tags>
|
||||
<tag>Robot and Motor</tag>
|
||||
<tag>Digital</tag>
|
||||
<tag>Sensors</tag>
|
||||
<tag>Actuators</tag>
|
||||
<tag>Joystick</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/MotorControl/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Relay</name>
|
||||
<description>Demonstrate controlling a Relay from Joystick buttons.</description>
|
||||
<tags>
|
||||
<tag>Actuators</tag>
|
||||
<tag>Joystick</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/Relay/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>PDP CAN Monitoring</name>
|
||||
<description>Demonstrate using CAN to monitor the voltage, current, and temperature in the
|
||||
Power Distribution Panel.</description>
|
||||
<tags>
|
||||
<tag>Complete List</tag>
|
||||
<tag>CAN</tag>
|
||||
<tag>Sensors</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/CANPDP/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Solenoids</name>
|
||||
<description>Demonstrate controlling a single and double solenoid from Joystick buttons.</description>
|
||||
<tags>
|
||||
<tag>Actuators</tag>
|
||||
<tag>Joystick</tag>
|
||||
<tag>Pneumatics</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/Solenoid/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Encoder</name>
|
||||
<description>Demonstrate displaying the value of a quadrature encoder on the
|
||||
SmartDashboard.</description>
|
||||
<tags>
|
||||
<tag>Complete List</tag>
|
||||
<tag>Digital</tag>
|
||||
<tag>Sensors</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/Encoder/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Arcade Drive</name>
|
||||
<description>An example program which demonstrates the use of Arcade Drive with the RobotDrive class</description>
|
||||
<tags>
|
||||
<tag>Getting Started with C++</tag>
|
||||
<tag>Robot and Motor</tag>
|
||||
<tag>Joystick</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/ArcadeDrive/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Mecanum Drive</name>
|
||||
<description>An example program which demonstrates the use of Mecanum Drive with the RobotDrive class</description>
|
||||
<tags>
|
||||
<tag>Getting Started with C++</tag>
|
||||
<tag>Robot and Motor</tag>
|
||||
<tag>Joystick</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/MecanumDrive/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Ultrasonic</name>
|
||||
<description>Demonstrate maintaining a set distance using an ultrasonic sensor.</description>
|
||||
<tags>
|
||||
<tag>Robot and Motor</tag>
|
||||
<tag>Complete List</tag>
|
||||
<tag>Sensors</tag>
|
||||
<tag>Analog</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/Ultrasonic/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>UltrasonicPID</name>
|
||||
<description>Demonstrate maintaining a set distance using an ultrasonic sensor and PID
|
||||
control.</description>
|
||||
<tags>
|
||||
<tag>Robot and Motor</tag>
|
||||
<tag>Complete List</tag>
|
||||
<tag>Sensors</tag>
|
||||
<tag>Analog</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/UltrasonicPID/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Gyro</name>
|
||||
<description>An example program showing how to drive straight with using a gyro sensor.</description>
|
||||
<tags>
|
||||
<tag>Robot and Motor</tag>
|
||||
<tag>Complete List</tag>
|
||||
<tag>Sensors</tag>
|
||||
<tag>Analog</tag>
|
||||
<tag>Joystick</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/Gyro/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Gyro Mecanum</name>
|
||||
<description>An example program showing how to perform mecanum drive with field oriented
|
||||
controls.</description>
|
||||
<tags>
|
||||
<tag>Robot and Motor</tag>
|
||||
<tag>Complete List</tag>
|
||||
<tag>Sensors</tag>
|
||||
<tag>Analog</tag>
|
||||
<tag>Joysitck</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/GyroMecanum/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>PotentiometerPID</name>
|
||||
<description>An example to demonstrate the use of a potentiometer and PID control to reach
|
||||
elevator position setpoints.</description>
|
||||
<tags>
|
||||
<tag>Joystick</tag>
|
||||
<tag>Actuators</tag>
|
||||
<tag>Complete List</tag>
|
||||
<tag>Sensors</tag>
|
||||
<tag>Analog</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/PotentiometerPID/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Getting Started</name>
|
||||
<description>An example program which demonstrates the simplest autonomous and
|
||||
teleoperated routines.</description>
|
||||
<tags>
|
||||
<tag>Getting Started with C++</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/GettingStarted/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Simple Vision</name>
|
||||
<description>The minimal program to acquire images from an attached USB camera on the robot
|
||||
and send them to the dashboard.</description>
|
||||
<tags>
|
||||
<tag>Vision</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/QuickVision/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Intermediate Vision</name>
|
||||
<description>An example program that acquires images from an attached USB camera and adds
|
||||
some
|
||||
annotation to the image as you might do for showing operators the result of some image
|
||||
recognition, and sends it to the dashboard for display.</description>
|
||||
<tags>
|
||||
<tag>Vision</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/IntermediateVision/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>Axis Camera Sample</name>
|
||||
<description>An example program that acquires images from an Axis network camera and adds
|
||||
some
|
||||
annotation to the image as you might do for showing operators the result of some image
|
||||
recognition, and sends it to the dashboard for display. This demonstrates the use of the
|
||||
AxisCamera class.</description>
|
||||
<tags>
|
||||
<tag>Vision</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/AxisCameraSample/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>GearsBot</name>
|
||||
<description>A fully functional example CommandBased program for
|
||||
WPIs GearsBot robot. This code can run on your computer if it
|
||||
supports simulation.</description>
|
||||
<tags>
|
||||
<tag>CommandBased Robot</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<world>/usr/share/frcsim/worlds/GearsBotDemo.world</world>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
<package>src/Commands</package>
|
||||
<package>src/Subsystems</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/GearsBot/src/Commands/Autonomous.cpp" destination="src/Commands/Autonomous.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/Autonomous.h" destination="src/Commands/Autonomous.h" />
|
||||
<file source="examples/GearsBot/src/Commands/CloseClaw.cpp" destination="src/Commands/CloseClaw.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/CloseClaw.h" destination="src/Commands/CloseClaw.h" />
|
||||
<file source="examples/GearsBot/src/Commands/DriveStraight.cpp" destination="src/Commands/DriveStraight.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/DriveStraight.h" destination="src/Commands/DriveStraight.h" />
|
||||
<file source="examples/GearsBot/src/Commands/OpenClaw.cpp" destination="src/Commands/OpenClaw.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/OpenClaw.h" destination="src/Commands/OpenClaw.h" />
|
||||
<file source="examples/GearsBot/src/Commands/Pickup.cpp" destination="src/Commands/Pickup.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/Pickup.h" destination="src/Commands/Pickup.h" />
|
||||
<file source="examples/GearsBot/src/Commands/Place.cpp" destination="src/Commands/Place.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/Place.h" destination="src/Commands/Place.h" />
|
||||
<file source="examples/GearsBot/src/Commands/PrepareToPickup.cpp" destination="src/Commands/PrepareToPickup.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/PrepareToPickup.h" destination="src/Commands/PrepareToPickup.h" />
|
||||
<file source="examples/GearsBot/src/Commands/SetDistanceToBox.cpp" destination="src/Commands/SetDistanceToBox.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/SetDistanceToBox.h" destination="src/Commands/SetDistanceToBox.h" />
|
||||
<file source="examples/GearsBot/src/Commands/SetElevatorSetpoint.cpp" destination="src/Commands/SetElevatorSetpoint.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/SetElevatorSetpoint.h" destination="src/Commands/SetElevatorSetpoint.h" />
|
||||
<file source="examples/GearsBot/src/Commands/SetWristSetpoint.cpp" destination="src/Commands/SetWristSetpoint.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/SetWristSetpoint.h" destination="src/Commands/SetWristSetpoint.h" />
|
||||
<file source="examples/GearsBot/src/Commands/TankDriveWithJoystick.cpp" destination="src/Commands/TankDriveWithJoystick.cpp" />
|
||||
<file source="examples/GearsBot/src/Commands/TankDriveWithJoystick.h" destination="src/Commands/TankDriveWithJoystick.h" />
|
||||
<file source="examples/GearsBot/src/OI.cpp" destination="src/OI.cpp" />
|
||||
<file source="examples/GearsBot/src/OI.h" destination="src/OI.h" />
|
||||
<file source="examples/GearsBot/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
<file source="examples/GearsBot/src/Robot.h" destination="src/Robot.h" />
|
||||
<file source="examples/GearsBot/src/Subsystems/Claw.cpp" destination="src/Subsystems/Claw.cpp" />
|
||||
<file source="examples/GearsBot/src/Subsystems/Claw.h" destination="src/Subsystems/Claw.h" />
|
||||
<file source="examples/GearsBot/src/Subsystems/DriveTrain.cpp" destination="src/Subsystems/DriveTrain.cpp" />
|
||||
<file source="examples/GearsBot/src/Subsystems/DriveTrain.h" destination="src/Subsystems/DriveTrain.h" />
|
||||
<file source="examples/GearsBot/src/Subsystems/Elevator.cpp" destination="src/Subsystems/Elevator.cpp" />
|
||||
<file source="examples/GearsBot/src/Subsystems/Elevator.h" destination="src/Subsystems/Elevator.h" />
|
||||
<file source="examples/GearsBot/src/Subsystems/Wrist.cpp" destination="src/Subsystems/Wrist.cpp" />
|
||||
<file source="examples/GearsBot/src/Subsystems/Wrist.h" destination="src/Subsystems/Wrist.h" />
|
||||
</files>
|
||||
</example>
|
||||
<example>
|
||||
<name>PacGoat</name>
|
||||
<description>A fully functional example CommandBased program for FRC Team 190&#39;s 2014
|
||||
robot. This code can run on your computer if it supports simulation.</description>
|
||||
<tags>
|
||||
<tag>CommandBased Robot</tag>
|
||||
<tag>Complete List</tag>
|
||||
</tags>
|
||||
<world>/usr/share/frcsim/worlds/PacGoat2014.world</world>
|
||||
<packages>
|
||||
<package>src</package>
|
||||
<package>src/Commands</package>
|
||||
<package>src/Subsystems</package>
|
||||
<package>src/Triggers</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/PacGoat/src/Commands/CheckForHotGoal.cpp" destination="src/Commands/CheckForHotGoal.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/CheckForHotGoal.h" destination="src/Commands/CheckForHotGoal.h" />
|
||||
<file source="examples/PacGoat/src/Commands/CloseClaw.cpp" destination="src/Commands/CloseClaw.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/CloseClaw.h" destination="src/Commands/CloseClaw.h" />
|
||||
<file source="examples/PacGoat/src/Commands/Collect.cpp" destination="src/Commands/Collect.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/Collect.h" destination="src/Commands/Collect.h" />
|
||||
<file source="examples/PacGoat/src/Commands/DriveAndShootAutonomous.cpp" destination="src/Commands/DriveAndShootAutonomous.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/DriveAndShootAutonomous.h" destination="src/Commands/DriveAndShootAutonomous.h" />
|
||||
<file source="examples/PacGoat/src/Commands/DriveForward.cpp" destination="src/Commands/DriveForward.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/DriveForward.h" destination="src/Commands/DriveForward.h" />
|
||||
<file source="examples/PacGoat/src/Commands/DriveWithJoystick.cpp" destination="src/Commands/DriveWithJoystick.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/DriveWithJoystick.h" destination="src/Commands/DriveWithJoystick.h" />
|
||||
<file source="examples/PacGoat/src/Commands/ExtendShooter.cpp" destination="src/Commands/ExtendShooter.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/ExtendShooter.h" destination="src/Commands/ExtendShooter.h" />
|
||||
<file source="examples/PacGoat/src/Commands/LowGoal.cpp" destination="src/Commands/LowGoal.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/LowGoal.h" destination="src/Commands/LowGoal.h" />
|
||||
<file source="examples/PacGoat/src/Commands/OpenClaw.cpp" destination="src/Commands/OpenClaw.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/OpenClaw.h" destination="src/Commands/OpenClaw.h" />
|
||||
<file source="examples/PacGoat/src/Commands/SetCollectionSpeed.cpp" destination="src/Commands/SetCollectionSpeed.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/SetCollectionSpeed.h" destination="src/Commands/SetCollectionSpeed.h" />
|
||||
<file source="examples/PacGoat/src/Commands/SetPivotSetpoint.cpp" destination="src/Commands/SetPivotSetpoint.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/SetPivotSetpoint.h" destination="src/Commands/SetPivotSetpoint.h" />
|
||||
<file source="examples/PacGoat/src/Commands/Shoot.cpp" destination="src/Commands/Shoot.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/Shoot.h" destination="src/Commands/Shoot.h" />
|
||||
<file source="examples/PacGoat/src/Commands/WaitForBall.cpp" destination="src/Commands/WaitForBall.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/WaitForBall.h" destination="src/Commands/WaitForBall.h" />
|
||||
<file source="examples/PacGoat/src/Commands/WaitForPressure.cpp" destination="src/Commands/WaitForPressure.cpp" />
|
||||
<file source="examples/PacGoat/src/Commands/WaitForPressure.h" destination="src/Commands/WaitForPressure.h" />
|
||||
<file source="examples/PacGoat/src/OI.cpp" destination="src/OI.cpp" />
|
||||
<file source="examples/PacGoat/src/OI.h" destination="src/OI.h" />
|
||||
<file source="examples/PacGoat/src/Robot.cpp" destination="src/Robot.cpp" />
|
||||
<file source="examples/PacGoat/src/Robot.h" destination="src/Robot.h" />
|
||||
<file source="examples/PacGoat/src/Subsystems/Collector.cpp" destination="src/Subsystems/Collector.cpp" />
|
||||
<file source="examples/PacGoat/src/Subsystems/Collector.h" destination="src/Subsystems/Collector.h" />
|
||||
<file source="examples/PacGoat/src/Subsystems/DriveTrain.cpp" destination="src/Subsystems/DriveTrain.cpp" />
|
||||
<file source="examples/PacGoat/src/Subsystems/DriveTrain.h" destination="src/Subsystems/DriveTrain.h" />
|
||||
<file source="examples/PacGoat/src/Subsystems/Pivot.cpp" destination="src/Subsystems/Pivot.cpp" />
|
||||
<file source="examples/PacGoat/src/Subsystems/Pivot.h" destination="src/Subsystems/Pivot.h" />
|
||||
<file source="examples/PacGoat/src/Subsystems/Pneumatics.cpp" destination="src/Subsystems/Pneumatics.cpp" />
|
||||
<file source="examples/PacGoat/src/Subsystems/Pneumatics.h" destination="src/Subsystems/Pneumatics.h" />
|
||||
<file source="examples/PacGoat/src/Subsystems/Shooter.cpp" destination="src/Subsystems/Shooter.cpp" />
|
||||
<file source="examples/PacGoat/src/Subsystems/Shooter.h" destination="src/Subsystems/Shooter.h" />
|
||||
<file source="examples/PacGoat/src/Triggers/DoubleButton.cpp" destination="src/Triggers/DoubleButton.cpp" />
|
||||
<file source="examples/PacGoat/src/Triggers/DoubleButton.h" destination="src/Triggers/DoubleButton.h" />
|
||||
</files>
|
||||
</example>
|
||||
</examples>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user