mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpilib] ExHub Follower Fixes (#8892)
A chunk of updates to followers on Expansion Hub Fixes followers not implicitly enabling. Allows followers to follow other followers Throws exceptions on construction if a follower cycle is detected. Allows reversing followers. The enable thing will fix https://github.com/wpilibsuite/SystemcoreTesting/discussions/259#discussioncomment-16886195 Closes #8843 Depends on https://github.com/wpilibsuite/scservices/pull/30
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// 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 org.wpilib.hardware.expansionhub;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.wpilib.hardware.expansionhub.ExpansionHubMotor.FollowDirection;
|
||||
import org.wpilib.hardware.hal.HAL;
|
||||
|
||||
class ExpansionHubMotorTest {
|
||||
@Test
|
||||
void testFollower() {
|
||||
HAL.initialize(500, 0);
|
||||
try (ExpansionHubMotor motor0 = new ExpansionHubMotor(0, 0);
|
||||
ExpansionHubMotor motor1 = new ExpansionHubMotor(0, 1);
|
||||
ExpansionHubMotor motor2 = new ExpansionHubMotor(0, 2); ) {
|
||||
motor1.follow(motor2, FollowDirection.Opposed);
|
||||
motor2.follow(motor0, FollowDirection.Opposed);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFollowerCycle() {
|
||||
HAL.initialize(500, 0);
|
||||
try (ExpansionHubMotor motor0 = new ExpansionHubMotor(0, 0);
|
||||
ExpansionHubMotor motor1 = new ExpansionHubMotor(0, 1);
|
||||
ExpansionHubMotor motor2 = new ExpansionHubMotor(0, 2); ) {
|
||||
motor1.follow(motor2, FollowDirection.Opposed);
|
||||
motor2.follow(motor0, FollowDirection.Opposed);
|
||||
assertThrows(
|
||||
IllegalStateException.class, () -> motor0.follow(motor1, FollowDirection.Opposed));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user