Merge branch 'main' into 2027

This commit is contained in:
Peter Johnson
2025-05-29 21:41:50 -07:00
347 changed files with 18562 additions and 11557 deletions

View File

@@ -0,0 +1,36 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/AnalogAccelerometer.h>
#include <frc/AnalogInput.h>
#include <frc/TimedRobot.h>
/**
* AnalogAccelerometer snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
// Sets the sensitivity of the accelerometer to 1 volt per G
m_accelerometer.SetSensitivity(1);
// Sets the zero voltage of the accelerometer to 3 volts
m_accelerometer.SetZero(3);
}
void TeleopPeriodic() override {
// Gets the current acceleration
m_accelerometer.GetAcceleration();
}
private:
// Creates an analog accelerometer on analog input 0
frc::AnalogAccelerometer m_accelerometer{0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -0,0 +1,35 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/AnalogEncoder.h>
#include <frc/TimedRobot.h>
/**
* AnalogEncoder snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
class Robot : public frc::TimedRobot {
public:
Robot() {}
void TeleopPeriodic() override {
// Gets the rotation
m_encoder.Get();
}
private:
// Initializes an analog encoder on Analog Input pin 0
frc::AnalogEncoder m_encoder{0};
// Initializes an analog encoder on DIO pins 0 to return a value of 4 for
// a full rotation, with the encoder reporting 0 half way through rotation (2
// out of 4)
frc::AnalogEncoder m_encoderFR{0, 4.0, 2.0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -0,0 +1,59 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/AnalogInput.h>
#include <frc/TimedRobot.h>
/**
* AnalogInput snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/analog-input-software.html
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
// Sets the AnalogInput to 4-bit oversampling. 16 samples will be added
// together.
// Thus, the reported values will increase by about a factor of 16, and the
// update rate will decrease by a similar amount.
m_analog.SetOversampleBits(4);
// Sets the AnalogInput to 4-bit averaging. 16 samples will be averaged
// together. The update rate will decrease by a factor of 16.
m_analog.SetAverageBits(4);
// Gets the raw instantaneous measured value from the analog input, without
// applying any calibration and ignoring oversampling and averaging
// settings.
m_analog.GetValue();
// Gets the instantaneous measured voltage from the analog input.
// Oversampling and averaging settings are ignored
m_analog.GetVoltage();
// Gets the averaged value from the analog input. The value is not
// rescaled, but oversampling and averaging are both applied.
m_analog.GetAverageValue();
// Gets the averaged voltage from the analog input. Rescaling,
// oversampling, and averaging are all applied.
m_analog.GetAverageVoltage();
}
void TeleopPeriodic() override {
}
private:
// Initializes an AnalogInput on port 0
frc::AnalogInput m_analog{0};
// The count and value variables to fill
int64_t count;
int64_t value;
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -0,0 +1,45 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/AnalogInput.h>
#include <frc/AnalogPotentiometer.h>
#include <frc/TimedRobot.h>
/**
* AnalogPotentiometer snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/analog-potentiometers-software.html
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
// Set averaging bits to 2
m_input.SetAverageBits(2);
}
void TeleopPeriodic() override {
// Get the value of the potentiometer
m_pot.Get();
}
private:
// Initializes an AnalogPotentiometer on analog port 0
// The full range of motion (in meaningful external units) is 0-180 (this
// could be degrees, for instance) The "starting point" of the motion, i.e.
// where the mechanism is located when the potentiometer reads 0v, is 30.
frc::AnalogPotentiometer m_pot{0, 180, 30};
// Initializes an AnalogInput on port 1
frc::AnalogInput m_input{1};
// Initializes an AnalogPotentiometer with the given AnalogInput
// The full range of motion (in meaningful external units) is 0-180 (this
// could be degrees, for instance) The "starting point" of the motion, i.e.
// where the mechanism is located when the potentiometer reads 0v, is 30.
frc::AnalogPotentiometer m_pot1{&m_input, 180, 30};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -0,0 +1,29 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/DigitalInput.h>
#include <frc/TimedRobot.h>
/**
* Digital Input snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/digital-input-software.html
*/
class Robot : public frc::TimedRobot {
public:
void TeleopPeriodic() override {
// Gets the value of the digital input. Returns true if the circuit is
// open.
m_input.Get();
}
private:
// Initializes a DigitalInput on DIO 0
frc::DigitalInput m_input{0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -2,8 +2,6 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <numbers>
#include <frc/DutyCycleEncoder.h>
#include <frc/TimedRobot.h>

View File

@@ -2,11 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <numbers>
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include <wpi/deprecated.h>
/**

View File

@@ -0,0 +1,54 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/motorcontrol/Spark.h>
/**
* Encoder drive to distance snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
// Configures the encoder's distance-per-pulse
// The robot moves forward 1 foot per encoder rotation
// There are 256 pulses per encoder rotation
m_encoder.SetDistancePerPulse(1.0 / 256.0);
// Invert the right side of the drivetrain. You might have to invert the
// other side
rightLeader.SetInverted(true);
// Configure the followers to follow the leaders
leftLeader.AddFollower(leftFollower);
rightLeader.AddFollower(rightFollower);
}
void AutonomousPeriodic() override {
// Drives forward at half speed until the robot has moved 5 feet, then
// stops:
if (m_encoder.GetDistance() < 5) {
drive.TankDrive(0.5, 0.5);
} else {
drive.TankDrive(0, 0);
}
}
private:
// Creates an encoder on DIO ports 0 and 1.
frc::Encoder m_encoder{0, 1};
// Initialize motor controllers and drive
frc::Spark leftLeader{0};
frc::Spark leftFollower{1};
frc::Spark rightLeader{2};
frc::Spark rightFollower{3};
frc::DifferentialDrive drive{[&](double output) { leftLeader.Set(output); },
[&](double output) { rightLeader.Set(output); }};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -0,0 +1,38 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/DigitalInput.h>
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/motorcontrol/Spark.h>
/**
* Encoder mechanism homing snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
class Robot : public frc::TimedRobot {
public:
void AutonomousPeriodic() override {
// Runs the motor backwards at half speed until the limit switch is pressed
// then turn off the motor and reset the encoder
if (!m_limit.Get()) {
m_spark.Set(-0.5);
} else {
m_spark.Set(0);
m_encoder.Reset();
}
}
private:
frc::Encoder m_encoder{0, 1};
frc::Spark m_spark{0};
// Limit switch on DIO 2
frc::DigitalInput m_limit{2};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -0,0 +1,50 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/DigitalInput.h>
#include <frc/Encoder.h>
#include <frc/Joystick.h>
#include <frc/TimedRobot.h>
#include <frc/motorcontrol/PWMVictorSPX.h>
/**
* Limit Switch snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/limit-switch.html
*/
class Robot : public frc::TimedRobot {
public:
void TeleopPeriodic() override { SetMotorSpeed(m_joystick.GetRawAxis(2)); }
void SetMotorSpeed(double speed) {
if (speed > 0) {
if (m_toplimitSwitch.Get()) {
// We are going up and top limit is tripped so stop
m_motor.Set(0);
} else {
// We are going up but top limit is not tripped so go at commanded speed
m_motor.Set(speed);
}
} else {
if (m_bottomlimitSwitch.Get()) {
// We are going down and bottom limit is tripped so stop
m_motor.Set(0);
} else {
// We are going down but bottom limit is not tripped so go at commanded
// speed
m_motor.Set(speed);
}
}
}
private:
frc::DigitalInput m_toplimitSwitch{0};
frc::DigitalInput m_bottomlimitSwitch{1};
frc::PWMVictorSPX m_motor{0};
frc::Joystick m_joystick{0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -19,5 +19,89 @@
],
"foldername": "DutyCycleEncoder",
"gradlebase": "cpp"
},
{
"name": "AnalogEncoder",
"description": "Snippets of AnalogEncoder class usage for frc-docs.",
"tags": [
"Hardware",
"Encoder",
"Analog"
],
"foldername": "AnalogEncoder",
"gradlebase": "cpp"
},
{
"name": "EncoderDrive",
"description": "Snippets of driving to a distance for frc-docs.",
"tags": [
"Hardware",
"Encoder",
"Differential Drive"
],
"foldername": "EncoderDrive",
"gradlebase": "cpp"
},
{
"name": "EncoderHoming",
"description": "Snippets of homing a mechanism for frc-docs.",
"tags": [
"Hardware",
"Encoder",
"Digital Input"
],
"foldername": "EncoderHoming",
"gradlebase": "cpp"
},
{
"name": "LimitSwitch",
"description": "Snippets of Limit Switch for frc-docs.",
"tags": [
"Hardware",
"Digital Input"
],
"foldername": "LimitSwitch",
"gradlebase": "cpp"
},
{
"name": "DigitalInput",
"description": "Snippets of Digital Input for frc-docs.",
"tags": [
"Hardware",
"Digital Input"
],
"foldername": "DigitalInput",
"gradlebase": "cpp"
},
{
"name": "AnalogInput",
"description": "Snippets of Analog Input for frc-docs.",
"tags": [
"Hardware",
"Analog"
],
"foldername": "AnalogInput",
"gradlebase": "cpp"
},
{
"name": "AnalogPotentiometer",
"description": "Snippets of Analog Potentiometer for frc-docs.",
"tags": [
"Hardware",
"Analog"
],
"foldername": "AnalogPotentiometer",
"gradlebase": "cpp"
},
{
"name": "AnalogAccelerometer",
"description": "Snippets of Analog Accelerometer for frc-docs.",
"tags": [
"Hardware",
"Analog",
"Accelerometer"
],
"foldername": "AnalogAccelerometer",
"gradlebase": "cpp"
}
]