Skip to content

Commit

Permalink
[wpimath] Remove unit suffixes from variable names
Browse files Browse the repository at this point in the history
* Move units into API docs instead because suffixes make user code verbose and hard to read
* Rename trackWidth to trackwidth
* Make ultrasonic classes use meters instead of a mix of m, cm, mm, ft,
  and inches
  • Loading branch information
calcmogul committed Dec 20, 2024
1 parent 03f0fc4 commit b26396d
Show file tree
Hide file tree
Showing 254 changed files with 2,935 additions and 3,568 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,31 @@ jobs:
build/allOutputs/
retention-days: 7

PathWeaver:
name: "Build - PathWeaver"
needs: [build-artifacts]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
repository: wpilibsuite/PathWeaver
fetch-depth: 0
- name: Patch PathWeaver to use local development
run: sed -i "s/wpilibTools.deps.wpilibVersion.*/wpilibTools.deps.wpilibVersion = \'$YEAR\.424242\.+\'/" dependencies.gradle
- uses: actions/download-artifact@v4
with:
name: MavenArtifacts
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- name: Move artifacts
run: mkdir -p ~/releases/maven/development && cp -r edu ~/releases/maven/development
- name: Build with Gradle
run: ./gradlew build
- uses: actions/upload-artifact@v4
with:
name: PathWeaver Build
path: |
build/allOutputs/
retention-days: 7
# PathWeaver:
# name: "Build - PathWeaver"
# needs: [build-artifacts]
# runs-on: ubuntu-24.04
# steps:
# - uses: actions/checkout@v4
# with:
# repository: wpilibsuite/PathWeaver
# fetch-depth: 0
# - name: Patch PathWeaver to use local development
# run: sed -i "s/wpilibTools.deps.wpilibVersion.*/wpilibTools.deps.wpilibVersion = \'$YEAR\.424242\.+\'/" dependencies.gradle
# - uses: actions/download-artifact@v4
# with:
# name: MavenArtifacts
# - uses: actions/setup-java@v4
# with:
# java-version: 17
# distribution: 'temurin'
# - name: Move artifacts
# run: mkdir -p ~/releases/maven/development && cp -r edu ~/releases/maven/development
# - name: Build with Gradle
# run: ./gradlew build
# - uses: actions/upload-artifact@v4
# with:
# name: PathWeaver Build
# path: |
# build/allOutputs/
# retention-days: 7
Original file line number Diff line number Diff line change
Expand Up @@ -1025,10 +1025,10 @@ public interface LoggerFunction {
/**
* Runs main run loop with timeout.
*
* @param timeoutSeconds Timeout in seconds.
* @param timeout Timeout in seconds.
* @return 3 on timeout, 2 on signal, 1 on other.
*/
public static native int runMainRunLoopTimeout(double timeoutSeconds);
public static native int runMainRunLoopTimeout(double timeout);

/** Stops main run loop. */
public static native void stopMainRunLoop();
Expand Down
4 changes: 2 additions & 2 deletions cscore/src/main/native/cpp/jni/CameraServerJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,9 +2085,9 @@ Java_edu_wpi_first_cscore_CameraServerJNI_runMainRunLoop
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_cscore_CameraServerJNI_runMainRunLoopTimeout
(JNIEnv*, jclass, jdouble timeoutSeconds)
(JNIEnv*, jclass, jdouble timeout)
{
return cs::RunMainRunLoopTimeout(timeoutSeconds);
return cs::RunMainRunLoopTimeout(timeout);
}

/*
Expand Down
11 changes: 10 additions & 1 deletion cscore/src/main/native/include/cscore_runloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
#pragma once

namespace cs {

void RunMainRunLoop();
int RunMainRunLoopTimeout(double timeoutSeconds);

/**
* Runs main run loop with timeout.
*
* @param timeout Timeout in seconds.
*/
int RunMainRunLoopTimeout(double timeout);

void StopMainRunLoop();

} // namespace cs
7 changes: 4 additions & 3 deletions cscore/src/main/native/linux/RunLoopHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ static wpi::Event& GetInstance() {
}

namespace cs {

void RunMainRunLoop() {
wpi::Event& event = GetInstance();
wpi::WaitForObject(event.GetHandle());
}

int RunMainRunLoopTimeout(double timeoutSeconds) {
int RunMainRunLoopTimeout(double timeout) {
wpi::Event& event = GetInstance();
bool timedOut = false;
bool signaled =
wpi::WaitForObject(event.GetHandle(), timeoutSeconds, &timedOut);
bool signaled = wpi::WaitForObject(event.GetHandle(), timeout, &timedOut);
if (timedOut) {
return 3;
}
Expand All @@ -35,4 +35,5 @@ void StopMainRunLoop() {
wpi::Event& event = GetInstance();
event.Set();
}

} // namespace cs
6 changes: 4 additions & 2 deletions cscore/src/main/native/objcpp/RunLoopHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>

namespace cs {

void RunMainRunLoop() {
if (CFRunLoopGetMain() != CFRunLoopGetCurrent()) {
NSLog(@"This method can only be called from the main thread");
Expand All @@ -16,15 +17,16 @@ void RunMainRunLoop() {
CFRunLoopRun();
}

int RunMainRunLoopTimeout(double timeoutSeconds) {
int RunMainRunLoopTimeout(double timeout) {
if (CFRunLoopGetMain() != CFRunLoopGetCurrent()) {
NSLog(@"This method can only be called from the main thread");
return -1;
}
return CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeoutSeconds, false);
return CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeout, false);
}

void StopMainRunLoop() {
CFRunLoopStop(CFRunLoopGetMain());
}

}
7 changes: 4 additions & 3 deletions cscore/src/main/native/windows/RunLoopHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ static wpi::Event& GetInstance() {
}

namespace cs {

void RunMainRunLoop() {
wpi::Event& event = GetInstance();
wpi::WaitForObject(event.GetHandle());
}

int RunMainRunLoopTimeout(double timeoutSeconds) {
int RunMainRunLoopTimeout(double timeout) {
wpi::Event& event = GetInstance();
bool timedOut = false;
bool signaled =
wpi::WaitForObject(event.GetHandle(), timeoutSeconds, &timedOut);
bool signaled = wpi::WaitForObject(event.GetHandle(), timeout, &timedOut);
if (timedOut) {
return 3;
}
Expand All @@ -35,4 +35,5 @@ void StopMainRunLoop() {
wpi::Event& event = GetInstance();
event.Set();
}

} // namespace cs
9 changes: 4 additions & 5 deletions hal/src/main/java/edu/wpi/first/hal/DMAJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public class DMAJNI extends JNIWrapper {
* <p>This can only be called if DMA is not started.
*
* @param handle the dma handle
* @param periodSeconds the period to trigger in seconds
* @param period the period to trigger in seconds
* @see "HAL_SetDMATimedTrigger"
*/
public static native void setTimedTrigger(int handle, double periodSeconds);
public static native void setTimedTrigger(int handle, double period);

/**
* Sets DMA transfers to occur at a specific timed interval in FPGA cycles.
Expand Down Expand Up @@ -229,14 +229,13 @@ public static native int setExternalTrigger(
* Reads a DMA sample from the queue.
*
* @param handle the dma handle
* @param timeoutSeconds the time to wait for data to be queued before timing out
* @param timeout the time in seconds to wait for data to be queued before timing out
* @param buffer the sample object to place data into
* @param sampleStore index 0-21 channelOffsets, index 22: capture size, index 23: triggerChannels
* (bitflags), index 24: remaining, index 25: read status
* @return timestamp of the DMA Sample
*/
public static native long readDMA(
int handle, double timeoutSeconds, int[] buffer, int[] sampleStore);
public static native long readDMA(int handle, double timeout, int[] buffer, int[] sampleStore);

/**
* Get the sensor DMA sample.
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ static class BaseStore {
/** Default constructor. */
public DMAJNISample() {}

public int update(int dmaHandle, double timeoutSeconds) {
m_timeStamp = DMAJNI.readDMA(dmaHandle, timeoutSeconds, m_dataBuffer, m_storage);
public int update(int dmaHandle, double timeout) {
m_timeStamp = DMAJNI.readDMA(dmaHandle, timeout, m_dataBuffer, m_storage);
return m_storage[25];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
namespace sysid {

/**
* Calculates the track width given the left distance, right distance, and
* Calculates the trackwidth given the left distance, right distance, and
* accumulated gyro angle.
*
* @param l The distance traveled by the left side of the drivetrain.
* @param r The distance traveled by the right side of the drivetrain.
* @param accum The accumulated gyro angle.
*/
constexpr double CalculateTrackWidth(double l, double r,
constexpr double CalculateTrackwidth(double l, double r,
units::radian_t accum) {
// The below comes from solving ω = (vr − vl) / 2r for 2r.
return (gcem::abs(r) + gcem::abs(l)) / gcem::abs(accum.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include <gtest/gtest.h>

#include "sysid/analysis/TrackWidthAnalysis.h"
#include "sysid/analysis/TrackwidthAnalysis.h"

TEST(TrackWidthAnalysisTest, Calculate) {
double result = sysid::CalculateTrackWidth(-0.5386, 0.5386, 90_deg);
TEST(TrackwidthAnalysisTest, Calculate) {
double result = sysid::CalculateTrackwidth(-0.5386, 0.5386, 90_deg);
EXPECT_NEAR(result, 0.6858, 1E-4);
}
Loading

0 comments on commit b26396d

Please sign in to comment.