Merge branch 'main' into 2027

This commit is contained in:
Peter Johnson
2025-02-20 00:26:23 -08:00
123 changed files with 4634 additions and 2291 deletions

View File

@@ -59,28 +59,32 @@
"left",
"X"
],
"value": 0
"value": 0,
"PositiveDirection": "Right"
},
{
"NameParts": [
"right",
"X"
],
"value": 4
"value": 4,
"PositiveDirection": "Right"
},
{
"NameParts": [
"left",
"Y"
],
"value": 1
"value": 1,
"PositiveDirection": "Back"
},
{
"NameParts": [
"right",
"Y"
],
"value": 5
"value": 5,
"PositiveDirection": "Back"
}
],
"triggers": [
@@ -173,28 +177,32 @@
"left",
"X"
],
"value": 0
"value": 0,
"PositiveDirection": "Right"
},
{
"NameParts": [
"left",
"Y"
],
"value": 1
"value": 1,
"PositiveDirection": "Back"
},
{
"NameParts": [
"right",
"X"
],
"value": 2
"value": 2,
"PositiveDirection": "Right"
},
{
"NameParts": [
"right",
"Y"
],
"value": 5
"value": 5,
"PositiveDirection": "Back"
}
],
"triggers": [
@@ -287,28 +295,32 @@
"left",
"X"
],
"value": 0
"value": 0,
"PositiveDirection": "Right"
},
{
"NameParts": [
"left",
"Y"
],
"value": 1
"value": 1,
"PositiveDirection": "Back"
},
{
"NameParts": [
"right",
"X"
],
"value": 2
"value": 2,
"PositiveDirection": "Right"
},
{
"NameParts": [
"right",
"Y"
],
"value": 5
"value": 5,
"PositiveDirection": "Back"
}
],
"triggers": [
@@ -408,28 +420,32 @@
"left",
"X"
],
"value": 0
"value": 0,
"PositiveDirection": "Right"
},
{
"NameParts": [
"right",
"X"
],
"value": 3
"value": 3,
"PositiveDirection": "Right"
},
{
"NameParts": [
"left",
"Y"
],
"value": 1
"value": 1,
"PositiveDirection": "Back"
},
{
"NameParts": [
"right",
"Y"
],
"value": 4
"value": 4,
"PositiveDirection": "Back"
}
]
}

View File

@@ -62,7 +62,8 @@
"type": "object",
"required": [
"NameParts",
"value"
"value",
"PositiveDirection"
],
"properties": {
"NameParts": {
@@ -76,6 +77,10 @@
"value": {
"description": "The axis value",
"type": "integer"
},
"PositiveDirection": {
"description": "The positive direction of the axis.",
"type": "string"
}
}
}

View File

@@ -102,7 +102,7 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
}
{% for stick in sticks %}
/**
* Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller.
* Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. {{ stick.PositiveDirection }} is positive.
*
* @return The axis value.
*/

View File

@@ -128,7 +128,7 @@ public class PS4Controller extends GenericHID implements Sendable {
}
/**
* Get the X axis value of left side of the controller.
* Get the X axis value of left side of the controller. Right is positive.
*
* @return The axis value.
*/
@@ -137,7 +137,7 @@ public class PS4Controller extends GenericHID implements Sendable {
}
/**
* Get the Y axis value of left side of the controller.
* Get the Y axis value of left side of the controller. Back is positive.
*
* @return The axis value.
*/
@@ -146,7 +146,7 @@ public class PS4Controller extends GenericHID implements Sendable {
}
/**
* Get the X axis value of right side of the controller.
* Get the X axis value of right side of the controller. Right is positive.
*
* @return The axis value.
*/
@@ -155,7 +155,7 @@ public class PS4Controller extends GenericHID implements Sendable {
}
/**
* Get the Y axis value of right side of the controller.
* Get the Y axis value of right side of the controller. Back is positive.
*
* @return The axis value.
*/

View File

@@ -128,7 +128,7 @@ public class PS5Controller extends GenericHID implements Sendable {
}
/**
* Get the X axis value of left side of the controller.
* Get the X axis value of left side of the controller. Right is positive.
*
* @return The axis value.
*/
@@ -137,7 +137,7 @@ public class PS5Controller extends GenericHID implements Sendable {
}
/**
* Get the Y axis value of left side of the controller.
* Get the Y axis value of left side of the controller. Back is positive.
*
* @return The axis value.
*/
@@ -146,7 +146,7 @@ public class PS5Controller extends GenericHID implements Sendable {
}
/**
* Get the X axis value of right side of the controller.
* Get the X axis value of right side of the controller. Right is positive.
*
* @return The axis value.
*/
@@ -155,7 +155,7 @@ public class PS5Controller extends GenericHID implements Sendable {
}
/**
* Get the Y axis value of right side of the controller.
* Get the Y axis value of right side of the controller. Back is positive.
*
* @return The axis value.
*/

View File

@@ -126,7 +126,7 @@ public class StadiaController extends GenericHID implements Sendable {
}
/**
* Get the X axis value of left side of the controller.
* Get the X axis value of left side of the controller. Right is positive.
*
* @return The axis value.
*/
@@ -135,7 +135,7 @@ public class StadiaController extends GenericHID implements Sendable {
}
/**
* Get the X axis value of right side of the controller.
* Get the X axis value of right side of the controller. Right is positive.
*
* @return The axis value.
*/
@@ -144,7 +144,7 @@ public class StadiaController extends GenericHID implements Sendable {
}
/**
* Get the Y axis value of left side of the controller.
* Get the Y axis value of left side of the controller. Back is positive.
*
* @return The axis value.
*/
@@ -153,7 +153,7 @@ public class StadiaController extends GenericHID implements Sendable {
}
/**
* Get the Y axis value of right side of the controller.
* Get the Y axis value of right side of the controller. Back is positive.
*
* @return The axis value.
*/

View File

@@ -120,7 +120,7 @@ public class XboxController extends GenericHID implements Sendable {
}
/**
* Get the X axis value of left side of the controller.
* Get the X axis value of left side of the controller. Right is positive.
*
* @return The axis value.
*/
@@ -129,7 +129,7 @@ public class XboxController extends GenericHID implements Sendable {
}
/**
* Get the X axis value of right side of the controller.
* Get the X axis value of right side of the controller. Right is positive.
*
* @return The axis value.
*/
@@ -138,7 +138,7 @@ public class XboxController extends GenericHID implements Sendable {
}
/**
* Get the Y axis value of left side of the controller.
* Get the Y axis value of left side of the controller. Back is positive.
*
* @return The axis value.
*/
@@ -147,7 +147,7 @@ public class XboxController extends GenericHID implements Sendable {
}
/**
* Get the Y axis value of right side of the controller.
* Get the Y axis value of right side of the controller. Back is positive.
*
* @return The axis value.
*/

View File

@@ -11,13 +11,57 @@ import edu.wpi.first.hal.PWMJNI;
/**
* A class for driving addressable LEDs, such as WS2812B, WS2815, and NeoPixels.
*
* <p>By default, the timing supports WS2812B and WS2815 LEDs, but is configurable using
* setBitTiming()
* <p>By default, the timing supports WS2812B and WS2815 LEDs, but is configurable using {@link
* #setBitTiming(int, int, int, int)}
*
* <p>Some LEDs use a different color order than the default GRB. The color order is configurable
* using {@link #setColorOrder(ColorOrder)}.
*
* <p>Only 1 LED driver is currently supported by the roboRIO. However, multiple LED strips can be
* connected in series and controlled from the single driver.
*/
public class AddressableLED implements AutoCloseable {
/** Order that color data is sent over the wire. */
public enum ColorOrder {
/** RGB order. */
kRGB(AddressableLEDJNI.COLOR_ORDER_RGB),
/** RBG order. */
kRBG(AddressableLEDJNI.COLOR_ORDER_RBG),
/** BGR order. */
kBGR(AddressableLEDJNI.COLOR_ORDER_BGR),
/** BRG order. */
kBRG(AddressableLEDJNI.COLOR_ORDER_BRG),
/** GBR order. */
kGBR(AddressableLEDJNI.COLOR_ORDER_GBR),
/** GRB order. This is the default order. */
kGRB(AddressableLEDJNI.COLOR_ORDER_GRB);
/** The native value for this ColorOrder. */
public final int value;
ColorOrder(int value) {
this.value = value;
}
/**
* Gets a color order from an int value.
*
* @param value int value
* @return color order
*/
public ColorOrder fromValue(int value) {
return switch (value) {
case AddressableLEDJNI.COLOR_ORDER_RBG -> kRBG;
case AddressableLEDJNI.COLOR_ORDER_BGR -> kBGR;
case AddressableLEDJNI.COLOR_ORDER_BRG -> kBRG;
case AddressableLEDJNI.COLOR_ORDER_GRB -> kGRB;
case AddressableLEDJNI.COLOR_ORDER_GBR -> kGBR;
case AddressableLEDJNI.COLOR_ORDER_RGB -> kRGB;
default -> kGRB;
};
}
}
private final int m_pwmHandle;
private final int m_handle;
@@ -42,6 +86,17 @@ public class AddressableLED implements AutoCloseable {
}
}
/**
* Sets the color order for this AddressableLED. The default order is GRB.
*
* <p>This will take effect on the next call to {@link #setData(AddressableLEDBuffer)}.
*
* @param order the color order
*/
public void setColorOrder(ColorOrder order) {
AddressableLEDJNI.setColorOrder(m_handle, order.value);
}
/**
* Sets the length of the LED strip.
*

View File

@@ -178,7 +178,7 @@ public class Joystick extends GenericHID {
/**
* Get the X value of the joystick. This depends on the mapping of the joystick connected to the
* current port.
* current port. On most joysticks, positive is to the right.
*
* @return The X value of the joystick.
*/
@@ -188,7 +188,7 @@ public class Joystick extends GenericHID {
/**
* Get the Y value of the joystick. This depends on the mapping of the joystick connected to the
* current port.
* current port. On most joysticks, positive is to the back.
*
* @return The Y value of the joystick.
*/
@@ -302,8 +302,8 @@ public class Joystick extends GenericHID {
}
/**
* Get the magnitude of the direction vector formed by the joystick's current position relative to
* its origin.
* Get the magnitude of the vector formed by the joystick's current position relative to its
* origin.
*
* @return The magnitude of the direction vector
*/
@@ -312,16 +312,26 @@ public class Joystick extends GenericHID {
}
/**
* Get the direction of the vector formed by the joystick and its origin in radians.
* Get the direction of the vector formed by the joystick and its origin in radians. 0 is forward
* and clockwise is positive. (Straight right is π/2.)
*
* @return The direction of the vector in radians
*/
public double getDirectionRadians() {
// https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system
// A positive rotation around the X axis moves the joystick right, and a
// positive rotation around the Y axis moves the joystick backward. When
// treating them as translations, 0 radians is measured from the right
// direction, and angle increases clockwise.
//
// It's rotated 90 degrees CCW (y is negated and the arguments are reversed)
// so that 0 radians is forward.
return Math.atan2(getX(), -getY());
}
/**
* Get the direction of the vector formed by the joystick and its origin in degrees.
* Get the direction of the vector formed by the joystick and its origin in degrees. 0 is forward
* and clockwise is positive. (Straight right is 90.)
*
* @return The direction of the vector in degrees
*/

View File

@@ -75,10 +75,10 @@ public class LinearSystemSim<States extends Num, Inputs extends Num, Outputs ext
* @param dt The time between updates in seconds.
*/
public void update(double dt) {
// Update X. By default, this is the linear system dynamics X = Ax + Bu
// Update x. By default, this is the linear system dynamics xₖ₊₁ = Ax + Buₖ.
m_x = updateX(m_x, m_u, dt);
// y = cx + du
// y = Cxₖ + Duₖ
m_y = m_plant.calculateY(m_x, m_u);
// Add measurement noise.
@@ -164,6 +164,11 @@ public class LinearSystemSim<States extends Num, Inputs extends Num, Outputs ext
*/
public void setState(Matrix<States, N1> state) {
m_x = state;
// Update the output to reflect the new state.
//
// yₖ = Cxₖ + Duₖ
m_y = m_plant.calculateY(m_x, m_u);
}
/**

View File

@@ -81,7 +81,18 @@ class AlertTest {
}
@Test
void setUnset() {
void setUnsetSingle() {
try (var one = makeAlert("one", AlertType.kInfo)) {
assertFalse(isAlertActive("one", AlertType.kInfo));
one.set(true);
assertTrue(isAlertActive("one", AlertType.kInfo));
one.set(false);
assertFalse(isAlertActive("one", AlertType.kInfo));
}
}
@Test
void setUnsetMultiple() {
try (var one = makeAlert("one", AlertType.kError);
var two = makeAlert("two", AlertType.kInfo)) {
assertFalse(isAlertActive("one", AlertType.kError));

View File

@@ -63,6 +63,17 @@ class ElevatorSimTest {
}
}
@Test
void testInitialState() {
double startingHeightMeters = 0.5;
var sim =
new ElevatorSim(
DCMotor.getKrakenX60(2), 20, 8.0, 0.1, 0.0, 1.0, true, startingHeightMeters, 0.01, 0.0);
assertEquals(startingHeightMeters, sim.getPosition());
assertEquals(0, sim.getVelocity());
}
@Test
void testMinMax() {
var sim =

View File

@@ -12,28 +12,46 @@ import edu.wpi.first.math.util.Units;
import org.junit.jupiter.api.Test;
class SingleJointedArmSimTest {
SingleJointedArmSim m_sim =
new SingleJointedArmSim(
DCMotor.getVex775Pro(2),
300,
3.0,
Units.inchesToMeters(30.0),
-Math.PI,
0.0,
true,
Math.PI / 2.0);
@Test
void testArmDisabled() {
SingleJointedArmSim sim =
new SingleJointedArmSim(
DCMotor.getVex775Pro(2),
300,
3.0,
Units.inchesToMeters(30.0),
-Math.PI,
0.0,
true,
Math.PI / 2.0);
// Reset Arm angle to 0
m_sim.setState(VecBuilder.fill(0.0, 0.0));
sim.setState(VecBuilder.fill(0.0, 0.0));
for (int i = 0; i < 12 / 0.02; i++) {
m_sim.setInput(0.0);
m_sim.update(0.020);
sim.setInput(0.0);
sim.update(0.020);
}
// the arm should swing down
assertEquals(-Math.PI / 2.0, m_sim.getAngle(), 0.1);
assertEquals(-Math.PI / 2.0, sim.getAngle(), 0.1);
}
@Test
void testInitialState() {
double startingAngleRads = Math.PI / 4.0;
SingleJointedArmSim sim =
new SingleJointedArmSim(
DCMotor.getKrakenX60(2),
125,
3.0,
Units.inchesToMeters(30.0),
0,
Math.PI / 2.0,
true,
startingAngleRads);
assertEquals(startingAngleRads, sim.getAngle());
assertEquals(0, sim.getVelocity());
}
}