Skip to content

Commit cf0fa0b

Browse files
committed
Merge remote-tracking branch 'origin' into async-periodic
2 parents d365ddb + fc8c870 commit cf0fa0b

5 files changed

Lines changed: 45 additions & 13 deletions

File tree

.github/workflows/release.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
release:
10+
name: Release Tag
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- name: Create Release
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
tag: ${{ github.ref_name }}
19+
run: |
20+
gh release create "$tag" --repo="$GITHUB_REPOSITORY" --title="$tag" --generate-notes

src/main/java/org/carlmontrobotics/lib199/Mocks.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.util.Arrays;
99
import java.util.HashMap;
1010
import java.util.concurrent.CopyOnWriteArrayList;
11+
import java.util.function.Consumer;
12+
import java.util.function.Predicate;
1113
import java.util.stream.Collectors;
1214

1315
import org.mockito.MockSettings;
@@ -19,6 +21,13 @@
1921
public final class Mocks {
2022

2123
private static final CopyOnWriteArrayList<WeakReference<Object>> MOCKS = new CopyOnWriteArrayList<>();
24+
private static final Predicate<WeakReference<?>> IS_REFERENCE_CLEARED = reference -> reference.get() == null;
25+
private static final Consumer<WeakReference<Object>> CLEAR_INVOCATIONS_ON_REFERENCED_MOCK = reference -> Mockito.clearInvocations(reference.get());
26+
private static final Predicate<WeakReference<Object>> CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERENCE_NOT_CLEARED = reference -> {
27+
if(IS_REFERENCE_CLEARED.test(reference)) return true;
28+
CLEAR_INVOCATIONS_ON_REFERENCED_MOCK.accept(reference);
29+
return false;
30+
};
2231

2332
static {
2433
// Use a single predicate so that clearing references and invocations is an atomic operation
@@ -27,12 +36,7 @@ public final class Mocks {
2736
// 2) Garbage collected references are removed
2837
// 3) Mock is garbage collected
2938
// 4) Mock invocations are cleared -> throws NullPointerException
30-
Lib199Subsystem.registerAsyncPeriodic(() -> MOCKS.removeIf(reference -> {
31-
Object mock = reference.get();
32-
if(mock == null) return true;
33-
Mockito.clearInvocations(mock);
34-
return false;
35-
}));
39+
Lib199Subsystem.registerAsyncPeriodic(() -> MOCKS.removeIf(CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERENCE_NOT_CLEARED));
3640
}
3741

3842
/**
@@ -56,7 +60,7 @@ public static <T, U> T createMock(Class<T> classToMock, U implClass, Class<?>...
5660
* @param <U> the class type which will be used to provide method implementations
5761
* @param classToMock the class type which will be mocked
5862
* @param implClass the object to which to try to forward method calls
59-
* @param forwardUnknownCalls whether methods which are not overriden will call their real methods
63+
* @param forwardUnknownCalls whether methods which are not overridden will call their real methods
6064
* @param interfaces a list of interfaces which the mocked object should extend
6165
* @return an instance of <code>T</code> in which some or all of the classes methods are replaced with a mocked implementation from <code>U</code>
6266
* @see #createMock(Class, Object, Class...)
@@ -72,7 +76,7 @@ public static <T, U> T createMock(Class<T> classToMock, U implClass, boolean for
7276
* @param <U> the class type which will be used to provide method implementations
7377
* @param classToMock the class type which will be mocked
7478
* @param implClass the object to which to try to forward method calls
75-
* @param defaultAnswer The answer to use when no overriden implementation is found
79+
* @param defaultAnswer The answer to use when no overridden implementation is found
7680
* @param interfaces a list of interfaces which the mocked object should extend
7781
* @return an instance of <code>T</code> in which some or all of the classes methods are replaced with a mocked implementation from <code>U</code>
7882
* @see #createMock(Class, Object, Class...)

src/main/java/org/carlmontrobotics/lib199/MotorControllerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static UsbCamera configureCamera() {
171171
}
172172

173173
/**
174-
* This method is equivilent to calling {@link #configureCamera()} {@code numCameras} times.
174+
* This method is equivalent to calling {@link #configureCamera()} {@code numCameras} times.
175175
* The last camera will be set as the primary Camera feed.
176176
* To change it, call {@code CameraServer.getServer().setSource()}.
177177
*

src/main/java/org/carlmontrobotics/lib199/MotorErrors.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ private static <T extends Enum<T>> void reportError(String vendor, T error, T ok
4747
if(error == null || error == ok) {
4848
return;
4949
}
50-
System.err.println("Error: " + error.name() + " occured while configuring " + vendor + " motor");
50+
System.err.println("Error: " + error.name() + " occurred while configuring " + vendor + " motor");
5151
System.err.println("Full stack trace:");
5252
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
5353
System.err.println(Arrays.toString(stack));
5454
}
5555

5656
public static void checkSparkMaxErrors(CANSparkMax spark) {
57-
//Purposely obivously impersonal to differentiate from actual computer generated errors
57+
//Purposely obviously impersonal to differentiate from actual computer generated errors
5858
short faults = spark.getFaults();
5959
short stickyFaults = spark.getStickyFaults();
6060
short prevFaults = flags.containsKey(spark) ? flags.get(spark) : 0;
@@ -114,7 +114,7 @@ public static void doReportSparkMaxTemp() {
114114
temperatureSparks.forEach((port, spark) -> {
115115
double temp = spark.getMotorTemperature();
116116
SmartDashboard.putNumber("Port " + port + " Spark Max Temp", temp);
117-
// Check if temperature exceeds the setpoint or if the contoller has already overheated to prevent other code from resetting the current limit after the controller has cooled
117+
// Check if temperature exceeds the setpoint or if the controller has already overheated to prevent other code from resetting the current limit after the controller has cooled
118118
if(temp >= sparkTemperatureLimits.get(port) || overheatedSparks.contains(port)) {
119119
if(!overheatedSparks.contains(port)) {
120120
overheatedSparks.add(port);

src/main/java/org/carlmontrobotics/lib199/path/RobotPath.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ public Command getPathCommand(boolean faceInPathDirection, boolean stopAtEnd) {
8585
if (trajectory == null) {
8686
generateTrajectory();
8787
}
88-
hs.reset();
8988
// We want the robot to stay facing the same direction (in this case), so save
9089
// the current heading (make sure to update at the start of the command)
9190
AtomicReference<Rotation2d> headingRef = new AtomicReference<>(dt.getPose().getRotation());
9291
Supplier<Rotation2d> desiredHeading = (!faceInPathDirection) ? () -> headingRef.get() : () -> hs.sample();
9392
Command command = dt.createAutoCommand(trajectory, desiredHeading);
93+
command = new InstantCommand(hs::reset).andThen(command, new InstantCommand(hs::stop));
9494
if (stopAtEnd) {
9595
command = command.andThen(new InstantCommand(dt::stop, dt));
9696
}
@@ -310,5 +310,13 @@ public void reset() {
310310
timerStarted = false;
311311
timer.reset();
312312
}
313+
314+
/**
315+
* Stops the timer
316+
*/
317+
public void stop() {
318+
timer.stop();
319+
reset();
320+
}
313321
}
314322
}

0 commit comments

Comments
 (0)