Skip to content

Commit 4136f67

Browse files
committed
[wpimath] Replace Speeds with Velocities
I left "free speed" alone since that's the technical term for it. In general, velocity is a vector quantity, and speed is a magnitude (i.e., a strictly positive value). This PR also replaces the speed verbiage in MotorController with duty cycle. Fixes #8423.
1 parent 1680e67 commit 4136f67

File tree

530 files changed

+7778
-7586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

530 files changed

+7778
-7586
lines changed

glass/src/lib/native/cpp/hardware/PWM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using namespace wpi::glass;
1717

1818
void wpi::glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
19-
auto data = model->GetSpeedData();
19+
auto data = model->GetDutyCycleData();
2020
if (!data) {
2121
return;
2222
}

glass/src/lib/native/cpp/other/Drive.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ void wpi::glass::DisplayDrive(DriveModel* m) {
4141
// Draw the primary rectangle.
4242
draw->AddRect(ImVec2(x1, y1), ImVec2(x2, y2), color);
4343

44-
// Display the speed vector.
44+
// Display the velocity vector.
4545
ImVec2 center{(x1 + x2) / 2.0f, (y1 + y2) / 2.0f};
46-
ImVec2 speed = m->GetSpeedVector();
47-
ImVec2 arrow = center + speed * 50.0f;
46+
ImVec2 velocity = m->GetVelocityVector();
47+
ImVec2 arrow = center + velocity * 50.0f;
4848

4949
draw->AddLine(center, arrow, color, 2.0f);
5050

@@ -61,8 +61,8 @@ void wpi::glass::DisplayDrive(DriveModel* m) {
6161
};
6262

6363
// Draw the arrow if there is any translation; draw an X otherwise.
64-
if (std::abs(speed.y) > 0 || std::abs(speed.x) > 0) {
65-
drawArrow(arrow, std::atan2(speed.x, -speed.y));
64+
if (std::abs(velocity.y) > 0 || std::abs(velocity.x) > 0) {
65+
drawArrow(arrow, std::atan2(velocity.x, -velocity.y));
6666
} else {
6767
ImVec2 a{7.5f, +7.5f};
6868
ImVec2 b{7.5f, -7.5f};

glass/src/lib/native/include/wpi/glass/hardware/PWM.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class DoubleSource;
1515

1616
class PWMModel : public Model {
1717
public:
18-
virtual DoubleSource* GetSpeedData() = 0;
18+
virtual DoubleSource* GetDutyCycleData() = 0;
1919

20-
virtual void SetSpeed(double val) = 0;
20+
virtual void SetDutyCycle(double dutyCycle) = 0;
2121
};
2222

2323
class PWMsModel : public Model {

glass/src/lib/native/include/wpi/glass/other/Drive.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DriveModel : public Model {
3131
virtual const char* GetName() const = 0;
3232
virtual const std::vector<WheelInfo>& GetWheels() const = 0;
3333

34-
virtual ImVec2 GetSpeedVector() const = 0;
34+
virtual ImVec2 GetVelocityVector() const = 0;
3535

3636
// Clamped between -1 and 1 with -1 being full CCW.
3737
virtual double GetRotation() const = 0;

glass/src/libnt/native/cpp/NTDifferentialDrive.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ NTDifferentialDriveModel::NTDifferentialDriveModel(
2424
m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe("")},
2525
m_controllable{inst.GetBooleanTopic(fmt::format("{}/.controllable", path))
2626
.Subscribe(false)},
27-
m_lPercent{inst.GetDoubleTopic(fmt::format("{}/Left Motor Speed", path))
28-
.GetEntry(0)},
29-
m_rPercent{inst.GetDoubleTopic(fmt::format("{}/Right Motor Speed", path))
30-
.GetEntry(0)},
27+
m_lPercent{
28+
inst.GetDoubleTopic(fmt::format("{}/Left Motor Velocity", path))
29+
.GetEntry(0)},
30+
m_rPercent{
31+
inst.GetDoubleTopic(fmt::format("{}/Right Motor Velocity", path))
32+
.GetEntry(0)},
3133
m_nameValue{wpi::util::rsplit(path, '/').second},
3234
m_lPercentData{fmt::format("NTDiffDriveL:{}", path)},
3335
m_rPercentData{fmt::format("NTDiffDriveR:{}", path)} {
@@ -55,7 +57,7 @@ void NTDifferentialDriveModel::Update() {
5557
double l = m_lPercentData.GetValue();
5658
double r = m_rPercentData.GetValue();
5759

58-
m_speedVector = ImVec2(0.0, -(l + r) / 2.0);
60+
m_velocityVector = ImVec2(0.0, -(l + r) / 2.0);
5961
m_rotation = (l - r) / 2.0;
6062
}
6163

glass/src/libnt/native/cpp/NTMecanumDrive.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ NTMecanumDriveModel::NTMecanumDriveModel(wpi::nt::NetworkTableInstance inst,
2424
m_controllable{inst.GetBooleanTopic(fmt::format("{}/.controllable", path))
2525
.Subscribe(0)},
2626
m_flPercent{
27-
inst.GetDoubleTopic(fmt::format("{}/Front Left Motor Speed", path))
28-
.GetEntry(0)},
29-
m_frPercent{
30-
inst.GetDoubleTopic(fmt::format("{}/Front Right Motor Speed", path))
27+
inst.GetDoubleTopic(fmt::format("{}/Front Left Motor Velocity", path))
3128
.GetEntry(0)},
29+
m_frPercent{inst.GetDoubleTopic(
30+
fmt::format("{}/Front Right Motor Velocity", path))
31+
.GetEntry(0)},
3232
m_rlPercent{
33-
inst.GetDoubleTopic(fmt::format("{}/Rear Left Motor Speed", path))
33+
inst.GetDoubleTopic(fmt::format("{}/Rear Left Motor Velocity", path))
3434
.GetEntry(0)},
3535
m_rrPercent{
36-
inst.GetDoubleTopic(fmt::format("{}/Rear Right Motor Speed", path))
36+
inst.GetDoubleTopic(fmt::format("{}/Rear Right Motor Velocity", path))
3737
.GetEntry(0)},
3838
m_nameValue{wpi::util::rsplit(path, '/').second},
3939
m_flPercentData{fmt::format("NTMcnmDriveFL:{}", path)},
@@ -78,7 +78,7 @@ void NTMecanumDriveModel::Update() {
7878
double rl = m_rlPercentData.GetValue();
7979
double rr = m_rrPercentData.GetValue();
8080

81-
m_speedVector =
81+
m_velocityVector =
8282
ImVec2((fl - fr - rl + rr) / 4.0f, -(fl + fr + rl + rr) / 4.0f);
8383
m_rotation = -(-fl + fr - rl + rr) / 4;
8484
}

glass/src/libnt/native/include/wpi/glass/networktables/NTDifferentialDrive.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class NTDifferentialDriveModel : public DriveModel {
2929
return m_wheels;
3030
}
3131

32-
ImVec2 GetSpeedVector() const override { return m_speedVector; }
32+
ImVec2 GetVelocityVector() const override { return m_velocityVector; }
3333
double GetRotation() const override { return m_rotation; }
3434

3535
void Update() override;
@@ -49,7 +49,7 @@ class NTDifferentialDriveModel : public DriveModel {
4949
DoubleSource m_rPercentData;
5050

5151
std::vector<DriveModel::WheelInfo> m_wheels;
52-
ImVec2 m_speedVector;
52+
ImVec2 m_velocityVector;
5353
double m_rotation;
5454
};
5555
} // namespace wpi::glass

glass/src/libnt/native/include/wpi/glass/networktables/NTMecanumDrive.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class NTMecanumDriveModel : public DriveModel {
2929
return m_wheels;
3030
}
3131

32-
ImVec2 GetSpeedVector() const override { return m_speedVector; }
32+
ImVec2 GetVelocityVector() const override { return m_velocityVector; }
3333
double GetRotation() const override { return m_rotation; }
3434

3535
void Update() override;
@@ -53,7 +53,7 @@ class NTMecanumDriveModel : public DriveModel {
5353
DoubleSource m_rrPercentData;
5454

5555
std::vector<DriveModel::WheelInfo> m_wheels;
56-
ImVec2 m_speedVector;
56+
ImVec2 m_velocityVector;
5757
double m_rotation;
5858
};
5959
} // namespace wpi::glass

hal/src/main/java/org/wpilib/hardware/hal/CounterJNI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class CounterJNI extends JNIWrapper {
6666
* Gets the Period of the most recent count.
6767
*
6868
* <p>Returns the time interval of the most recent count. This can be used for velocity
69-
* calculations to determine shaft speed.
69+
* calculations to determine shaft velocity.
7070
*
7171
* @param counterHandle the counter handle
7272
* @return the period of the last two pulses in units of seconds

hal/src/main/java/org/wpilib/hardware/hal/EncoderJNI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static native int initializeEncoder(
8888
* Gets the Period of the most recent count.
8989
*
9090
* <p>Returns the time interval of the most recent count. This can be used for velocity
91-
* calculations to determine shaft speed.
91+
* calculations to determine shaft velocity.
9292
*
9393
* @param encoderHandle the encoder handle
9494
* @return the period of the last two pulses in units of seconds

0 commit comments

Comments
 (0)