Merge branch 'main' into 2027

This commit is contained in:
Peter Johnson
2025-04-25 23:45:43 -07:00
79 changed files with 2093 additions and 415 deletions

View File

@@ -0,0 +1,25 @@
// 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.
package edu.wpi.first.wpilibj.snippets.dutycycleencoder;
import edu.wpi.first.wpilibj.RobotBase;
/**
* Do NOT add any static variables to this class, or any initialization at all. Unless you know what
* you are doing, do not modify this file except to change the parameter class to the startRobot
* call.
*/
public final class Main {
private Main() {}
/**
* Main initialization function. Do not perform any initialization here.
*
* <p>If you change your main robot class, change the parameter type.
*/
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}

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.
package edu.wpi.first.wpilibj.snippets.dutycycleencoder;
import edu.wpi.first.wpilibj.DutyCycleEncoder;
import edu.wpi.first.wpilibj.TimedRobot;
/**
* DutyCycleEncoder snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
public class Robot extends TimedRobot {
// Initializes a duty cycle encoder on DIO pins 0
DutyCycleEncoder m_encoder = new DutyCycleEncoder(0);
// Initializes a duty cycle 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)
DutyCycleEncoder m_encoderFR = new DutyCycleEncoder(0, 4.0, 2.0);
/** Called once at the beginning of the robot program. */
public Robot() {}
@Override
public void teleopPeriodic() {
// Gets the rotation
m_encoder.get();
// Gets if the encoder is connected
m_encoder.isConnected();
m_encoderFR.get();
}
}

View File

@@ -0,0 +1,25 @@
// 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.
package edu.wpi.first.wpilibj.snippets.encoder;
import edu.wpi.first.wpilibj.RobotBase;
/**
* Do NOT add any static variables to this class, or any initialization at all. Unless you know what
* you are doing, do not modify this file except to change the parameter class to the startRobot
* call.
*/
public final class Main {
private Main() {}
/**
* Main initialization function. Do not perform any initialization here.
*
* <p>If you change your main robot class, change the parameter type.
*/
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}

View File

@@ -0,0 +1,62 @@
// 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.
package edu.wpi.first.wpilibj.snippets.encoder;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.TimedRobot;
/**
* Encoder snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
@SuppressWarnings("deprecation")
public class Robot extends TimedRobot {
// Initializes an encoder on DIO pins 0 and 1
// Defaults to 4X decoding and non-inverted
Encoder m_encoder = new Encoder(0, 1);
// Initializes an encoder on DIO pins 0 and 1
// 2X encoding and non-inverted
Encoder m_encoder2x = new Encoder(0, 1, false, Encoder.EncodingType.k2X);
/** Called once at the beginning of the robot program. */
public Robot() {
// Configures the encoder to return a distance of 4 for every 256 pulses
// Also changes the units of getRate
m_encoder.setDistancePerPulse(4.0 / 256.0);
// Configures the encoder to consider itself stopped after .1 seconds
m_encoder.setMaxPeriod(0.1);
// Configures the encoder to consider itself stopped when its rate is below 10
m_encoder.setMinRate(10);
// Reverses the direction of the encoder
m_encoder.setReverseDirection(true);
// Configures an encoder to average its period measurement over 5 samples
// Can be between 1 and 127 samples
m_encoder.setSamplesToAverage(5);
m_encoder2x.getRate();
}
@Override
public void teleopPeriodic() {
// Gets the distance traveled
m_encoder.getDistance();
// Gets the current rate of the encoder
m_encoder.getRate();
// Gets whether the encoder is stopped
m_encoder.getStopped();
// Gets the last direction in which the encoder moved
m_encoder.getDirection();
// Gets the current period of the encoder
m_encoder.getPeriod();
// Resets the encoder to read a distance of zero
m_encoder.reset();
}
}

View File

@@ -0,0 +1,25 @@
[
{
"name": "Encoder",
"description": "Snippets of Encoder class usage for frc-docs.",
"tags": [
"Hardware",
"Encoder"
],
"foldername": "encoder",
"gradlebase": "java",
"mainclass": "Main"
},
{
"name": "DutyCycleEncoder",
"description": "Snippets of DutyCycleEncoder class usage for frc-docs.",
"tags": [
"Hardware",
"Encoder",
"Duty Cycle"
],
"foldername": "dutycycleencoder",
"gradlebase": "java",
"mainclass": "Main"
}
]