Skip to content

Commit 42c69e1

Browse files
committed
[telemetry, tunable] Add new Telemetry and Tunable implementations
1 parent 1eca886 commit 42c69e1

File tree

285 files changed

+8469
-2238
lines changed

Some content is hidden

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

285 files changed

+8469
-2238
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)")
288288
set(DATALOG_DEP_REPLACE "find_dependency(datalog)")
289289
add_subdirectory(wpiutil)
290290

291+
add_subdirectory(telemetry)
291292
add_subdirectory(datalog)
292293

293294
if(WITH_NTCORE)

README-CMake.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ If you want JNI and Java, you will need a JDK of at least version 21 installed.
3838

3939
If you are building with unit tests or simulation modules, you will also need an Internet connection for the initial setup process, as CMake will clone google-test and imgui from GitHub.
4040

41+
Building the GUI on Linux requires libxcursor-dev, libxrandr-dev, libxinerama-dev, libxi-dev, and libgl-dev.
42+
4143
## Build Options
4244

4345
The following build options are available:

apriltag/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ model {
103103
return
104104
}
105105
it.cppCompiler.define 'WPILIB_EXPORTS'
106+
lib project: ':telemetry', library: 'telemetry', linkage: 'shared'
106107
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
107108
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
108109
}

commandsv2/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ wpilib_java_library(
113113
"//cscore:cscore-java",
114114
"//hal:hal-java",
115115
"//ntcore:ntcore-java",
116+
"//telemetry:telemetry-java",
116117
"//wpiannotations",
117118
"//wpilibj:wpilibj-java",
118119
"//wpimath:wpimath-java",
@@ -148,6 +149,7 @@ wpilib_java_junit5_test(
148149
":commandsv2-java",
149150
"//hal:hal-java",
150151
"//ntcore:ntcore-java",
152+
"//telemetry:telemetry-java",
151153
"//wpiannotations",
152154
"//wpilibj:wpilibj-java",
153155
"//wpimath:wpimath-java",

commandsv2/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ if(WITH_JAVA)
1818
${JACKSON_JARS}
1919
cscore_jar
2020
cameraserver_jar
21+
datalog_jar
22+
telemetry_jar
2123
wpimath_jar
2224
wpiunits_jar
2325
wpiutil_jar

commandsv2/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ evaluationDependsOn(':wpimath')
1010
evaluationDependsOn(':wpilibc')
1111
evaluationDependsOn(':cameraserver')
1212
evaluationDependsOn(':wpilibj')
13+
evaluationDependsOn(':datalog')
14+
evaluationDependsOn(':telemetry')
1315

1416
apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
1517

@@ -22,7 +24,8 @@ dependencies {
2224
implementation project(':wpimath')
2325
implementation project(':wpilibj')
2426
implementation project(':wpiannotations')
25-
api project(':datalog')
27+
implementation project(':datalog')
28+
implementation project(':telemetry')
2629
testImplementation 'org.mockito:mockito-core:4.1.0'
2730
annotationProcessor project(':javacPlugin')
2831
testAnnotationProcessor project(':javacPlugin')

commandsv2/src/main/java/org/wpilib/command2/SubsystemBase.java

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44

55
package org.wpilib.command2;
66

7-
import org.wpilib.util.sendable.Sendable;
8-
import org.wpilib.util.sendable.SendableBuilder;
9-
import org.wpilib.util.sendable.SendableRegistry;
7+
import org.wpilib.telemetry.TelemetryLoggable;
8+
import org.wpilib.telemetry.TelemetryTable;
109

1110
/**
1211
* A base for subsystems that handles registration in the constructor, and provides a more intuitive
1312
* method for setting the default command.
1413
*
1514
* <p>This class is provided by the NewCommands VendorDep
1615
*/
17-
public abstract class SubsystemBase implements Subsystem, Sendable {
16+
public abstract class SubsystemBase implements Subsystem, TelemetryLoggable {
1817
/** Constructor. Telemetry/log name defaults to the classname. */
1918
@SuppressWarnings("this-escape")
2019
public SubsystemBase() {
2120
String name = this.getClass().getSimpleName();
22-
name = name.substring(name.lastIndexOf('.') + 1);
23-
SendableRegistry.add(this, name, name);
21+
m_name = name.substring(name.lastIndexOf('.') + 1);
2422
CommandScheduler.getInstance().registerSubsystem(this);
2523
}
2624

@@ -31,7 +29,7 @@ public SubsystemBase() {
3129
*/
3230
@SuppressWarnings("this-escape")
3331
public SubsystemBase(String name) {
34-
SendableRegistry.add(this, name, name);
32+
m_name = name;
3533
CommandScheduler.getInstance().registerSubsystem(this);
3634
}
3735

@@ -42,7 +40,7 @@ public SubsystemBase(String name) {
4240
*/
4341
@Override
4442
public String getName() {
45-
return SendableRegistry.getName(this);
43+
return m_name;
4644
}
4745

4846
/**
@@ -51,50 +49,24 @@ public String getName() {
5149
* @param name name
5250
*/
5351
public void setName(String name) {
54-
SendableRegistry.setName(this, name);
52+
m_name = name;
5553
}
5654

57-
/**
58-
* Gets the subsystem name of this Subsystem.
59-
*
60-
* @return Subsystem name
61-
*/
62-
public String getSubsystem() {
63-
return SendableRegistry.getSubsystem(this);
64-
}
65-
66-
/**
67-
* Sets the subsystem name of this Subsystem.
68-
*
69-
* @param subsystem subsystem name
70-
*/
71-
public void setSubsystem(String subsystem) {
72-
SendableRegistry.setSubsystem(this, subsystem);
73-
}
55+
@Override
56+
public void updateTelemetry(TelemetryTable table) {
57+
var defaultCommand = getDefaultCommand();
58+
table.log(".hasDefault", defaultCommand != null);
59+
table.log(".default", defaultCommand != null ? defaultCommand.getName() : "none");
7460

75-
/**
76-
* Associates a {@link Sendable} with this Subsystem. Also update the child's name.
77-
*
78-
* @param name name to give child
79-
* @param child sendable
80-
*/
81-
public void addChild(String name, Sendable child) {
82-
SendableRegistry.add(child, getSubsystem(), name);
61+
var currentCommand = getCurrentCommand();
62+
table.log(".hasCommand", currentCommand != null);
63+
table.log(".command", currentCommand != null ? currentCommand.getName() : "none");
8364
}
8465

8566
@Override
86-
public void initSendable(SendableBuilder builder) {
87-
builder.setSmartDashboardType("Subsystem");
88-
89-
builder.addBooleanProperty(".hasDefault", () -> getDefaultCommand() != null, null);
90-
builder.addStringProperty(
91-
".default",
92-
() -> getDefaultCommand() != null ? getDefaultCommand().getName() : "none",
93-
null);
94-
builder.addBooleanProperty(".hasCommand", () -> getCurrentCommand() != null, null);
95-
builder.addStringProperty(
96-
".command",
97-
() -> getCurrentCommand() != null ? getCurrentCommand().getName() : "none",
98-
null);
67+
public String getTelemetryType() {
68+
return "Subsystem";
9969
}
70+
71+
private String m_name;
10072
}

commandsv2/src/main/native/cpp/frc2/command/SubsystemBase.cpp

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,35 @@
88

99
#include "wpi/commands2/Command.hpp"
1010
#include "wpi/commands2/CommandScheduler.hpp"
11-
#include "wpi/util/sendable/SendableBuilder.hpp"
12-
#include "wpi/util/sendable/SendableRegistry.hpp"
11+
#include "wpi/telemetry/TelemetryTable.hpp"
1312

1413
using namespace wpi::cmd;
1514

1615
SubsystemBase::SubsystemBase() {
17-
wpi::util::SendableRegistry::Add(this, GetTypeName(*this));
1816
CommandScheduler::GetInstance().RegisterSubsystem({this});
1917
}
2018

21-
SubsystemBase::SubsystemBase(std::string_view name) {
22-
wpi::util::SendableRegistry::Add(this, name);
19+
SubsystemBase::SubsystemBase(std::string_view name) : m_name{name} {
2320
CommandScheduler::GetInstance().RegisterSubsystem({this});
2421
}
2522

26-
void SubsystemBase::InitSendable(wpi::util::SendableBuilder& builder) {
27-
builder.SetSmartDashboardType("Subsystem");
28-
builder.AddBooleanProperty(
29-
".hasDefault", [this] { return GetDefaultCommand() != nullptr; },
30-
nullptr);
31-
builder.AddStringProperty(
32-
".default",
33-
[this]() -> std::string {
34-
auto command = GetDefaultCommand();
35-
if (command == nullptr) {
36-
return "none";
37-
}
38-
return command->GetName();
39-
},
40-
nullptr);
41-
builder.AddBooleanProperty(
42-
".hasCommand", [this] { return GetCurrentCommand() != nullptr; },
43-
nullptr);
44-
builder.AddStringProperty(
45-
".command",
46-
[this]() -> std::string {
47-
auto command = GetCurrentCommand();
48-
if (command == nullptr) {
49-
return "none";
50-
}
51-
return command->GetName();
52-
},
53-
nullptr);
23+
void SubsystemBase::UpdateTelemetry(wpi::TelemetryTable& table) const {
24+
auto defaultCommand = GetDefaultCommand();
25+
table.Log(".hasDefault", defaultCommand != nullptr);
26+
table.Log(".default", defaultCommand ? defaultCommand->GetName() : "none");
27+
auto currentCommand = GetCurrentCommand();
28+
table.Log(".hasCommand", currentCommand != nullptr);
29+
table.Log(".command", currentCommand ? currentCommand->GetName() : "none");
5430
}
5531

56-
std::string SubsystemBase::GetName() const {
57-
return wpi::util::SendableRegistry::GetName(this);
58-
}
59-
60-
void SubsystemBase::SetName(std::string_view name) {
61-
wpi::util::SendableRegistry::SetName(this, name);
32+
std::string_view SubsystemBase::GetTelemetryType() const {
33+
return "Subsystem";
6234
}
6335

64-
std::string SubsystemBase::GetSubsystem() const {
65-
return wpi::util::SendableRegistry::GetSubsystem(this);
66-
}
67-
68-
void SubsystemBase::SetSubsystem(std::string_view name) {
69-
wpi::util::SendableRegistry::SetSubsystem(this, name);
36+
std::string SubsystemBase::GetName() const {
37+
return m_name;
7038
}
7139

72-
void SubsystemBase::AddChild(std::string name, wpi::util::Sendable* child) {
73-
wpi::util::SendableRegistry::Add(child, GetSubsystem(), name);
40+
void SubsystemBase::SetName(std::string_view name) {
41+
m_name = name;
7442
}

commandsv2/src/main/native/include/wpi/commands2/SubsystemBase.hpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <string_view>
99

1010
#include "wpi/commands2/Subsystem.hpp"
11-
#include "wpi/util/sendable/Sendable.hpp"
12-
#include "wpi/util/sendable/SendableHelper.hpp"
11+
#include "wpi/telemetry/TelemetryLoggable.hpp"
1312

1413
namespace wpi::cmd {
1514
/**
@@ -18,11 +17,11 @@ namespace wpi::cmd {
1817
*
1918
* This class is provided by the NewCommands VendorDep
2019
*/
21-
class SubsystemBase : public Subsystem,
22-
public wpi::util::Sendable,
23-
public wpi::util::SendableHelper<SubsystemBase> {
20+
class SubsystemBase : public Subsystem, public wpi::TelemetryLoggable {
2421
public:
25-
void InitSendable(wpi::util::SendableBuilder& builder) override;
22+
void UpdateTelemetry(wpi::TelemetryTable& table) const override;
23+
24+
std::string_view GetTelemetryType() const override;
2625

2726
/**
2827
* Gets the name of this Subsystem.
@@ -38,29 +37,6 @@ class SubsystemBase : public Subsystem,
3837
*/
3938
void SetName(std::string_view name);
4039

41-
/**
42-
* Gets the subsystem name of this Subsystem.
43-
*
44-
* @return Subsystem name
45-
*/
46-
std::string GetSubsystem() const;
47-
48-
/**
49-
* Sets the subsystem name of this Subsystem.
50-
*
51-
* @param name subsystem name
52-
*/
53-
void SetSubsystem(std::string_view name);
54-
55-
/**
56-
* Associate a Sendable with this Subsystem.
57-
* Also update the child's name.
58-
*
59-
* @param name name to give child
60-
* @param child sendable
61-
*/
62-
void AddChild(std::string name, wpi::util::Sendable* child);
63-
6440
protected:
6541
/**
6642
* Constructor. Telemetry/log name defaults to the classname.
@@ -72,5 +48,8 @@ class SubsystemBase : public Subsystem,
7248
* @param name Name of the subsystem for telemetry and logging.
7349
*/
7450
explicit SubsystemBase(std::string_view name);
51+
52+
private:
53+
std::string m_name;
7554
};
7655
} // namespace wpi::cmd

datalog/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ wpilib_cc_library(
2626
strip_include_prefix = "src/main/native/include",
2727
visibility = ["//visibility:public"],
2828
deps = [
29+
"//telemetry",
2930
"//wpiutil",
3031
],
3132
)
@@ -78,6 +79,7 @@ wpilib_jni_java_library(
7879
native_libs = [":datalogjni"],
7980
visibility = ["//visibility:public"],
8081
deps = [
82+
"//telemetry:telemetry-java",
8183
"//wpiutil:wpiutil-java",
8284
"@maven//:us_hebi_quickbuf_quickbuf_runtime",
8385
],
@@ -142,6 +144,7 @@ wpilib_java_junit5_test(
142144
tags = ["exclusive"],
143145
deps = [
144146
":datalog-java",
147+
"//telemetry:telemetry-java",
145148
"//wpiutil:wpiutil-java",
146149
],
147150
)

0 commit comments

Comments
 (0)