5
5
package edu .wpi .first .wpilibj .smartdashboard ;
6
6
7
7
import edu .wpi .first .math .geometry .Rotation2d ;
8
- import edu .wpi .first .networktables .DoubleEntry ;
9
- import edu .wpi .first .networktables .NetworkTable ;
10
- import edu .wpi .first .networktables .StringEntry ;
11
- import edu .wpi .first .networktables .StringPublisher ;
12
- import edu .wpi .first .networktables .StringTopic ;
8
+ import edu .wpi .first .telemetry .TelemetryTable ;
13
9
import edu .wpi .first .wpilibj .util .Color8Bit ;
14
10
15
11
/**
19
15
* @see Mechanism2d
20
16
*/
21
17
public class MechanismLigament2d extends MechanismObject2d {
22
- private StringPublisher m_typePub ;
23
- private double m_angle ;
24
- private DoubleEntry m_angleEntry ;
18
+ private Rotation2d m_angle ;
25
19
private String m_color ;
26
- private StringEntry m_colorEntry ;
27
20
private double m_length ;
28
- private DoubleEntry m_lengthEntry ;
29
21
private double m_weight ;
30
- private DoubleEntry m_weightEntry ;
31
-
32
- private static String kSmartDashboardType = "line" ;
33
22
34
23
/**
35
24
* Create a new ligament.
@@ -60,36 +49,13 @@ public MechanismLigament2d(String name, double length, double angle) {
60
49
this (name , length , angle , 10 , new Color8Bit (235 , 137 , 52 ));
61
50
}
62
51
63
- @ Override
64
- public void close () {
65
- super .close ();
66
- if (m_typePub != null ) {
67
- m_typePub .close ();
68
- }
69
- if (m_angleEntry != null ) {
70
- m_angleEntry .close ();
71
- }
72
- if (m_colorEntry != null ) {
73
- m_colorEntry .close ();
74
- }
75
- if (m_lengthEntry != null ) {
76
- m_lengthEntry .close ();
77
- }
78
- if (m_weightEntry != null ) {
79
- m_weightEntry .close ();
80
- }
81
- }
82
-
83
52
/**
84
53
* Set the ligament's angle relative to its parent.
85
54
*
86
55
* @param degrees the angle in degrees
87
56
*/
88
57
public final synchronized void setAngle (double degrees ) {
89
- m_angle = degrees ;
90
- if (m_angleEntry != null ) {
91
- m_angleEntry .set (degrees );
92
- }
58
+ m_angle = Rotation2d .fromDegrees (degrees );
93
59
}
94
60
95
61
/**
@@ -106,10 +72,7 @@ public synchronized void setAngle(Rotation2d angle) {
106
72
*
107
73
* @return the angle in degrees
108
74
*/
109
- public synchronized double getAngle () {
110
- if (m_angleEntry != null ) {
111
- m_angle = m_angleEntry .get ();
112
- }
75
+ public synchronized Rotation2d getAngle () {
113
76
return m_angle ;
114
77
}
115
78
@@ -120,9 +83,6 @@ public synchronized double getAngle() {
120
83
*/
121
84
public final synchronized void setLength (double length ) {
122
85
m_length = length ;
123
- if (m_lengthEntry != null ) {
124
- m_lengthEntry .set (length );
125
- }
126
86
}
127
87
128
88
/**
@@ -131,9 +91,6 @@ public final synchronized void setLength(double length) {
131
91
* @return the line length
132
92
*/
133
93
public synchronized double getLength () {
134
- if (m_lengthEntry != null ) {
135
- m_length = m_lengthEntry .get ();
136
- }
137
94
return m_length ;
138
95
}
139
96
@@ -144,9 +101,6 @@ public synchronized double getLength() {
144
101
*/
145
102
public final synchronized void setColor (Color8Bit color ) {
146
103
m_color = String .format ("#%02X%02X%02X" , color .red , color .green , color .blue );
147
- if (m_colorEntry != null ) {
148
- m_colorEntry .set (m_color );
149
- }
150
104
}
151
105
152
106
/**
@@ -155,9 +109,6 @@ public final synchronized void setColor(Color8Bit color) {
155
109
* @return the color of the line
156
110
*/
157
111
public synchronized Color8Bit getColor () {
158
- if (m_colorEntry != null ) {
159
- m_color = m_colorEntry .get ();
160
- }
161
112
int r = 0 ;
162
113
int g = 0 ;
163
114
int b = 0 ;
@@ -182,9 +133,6 @@ public synchronized Color8Bit getColor() {
182
133
*/
183
134
public final synchronized void setLineWeight (double weight ) {
184
135
m_weight = weight ;
185
- if (m_weightEntry != null ) {
186
- m_weightEntry .set (weight );
187
- }
188
136
}
189
137
190
138
/**
@@ -193,46 +141,17 @@ public final synchronized void setLineWeight(double weight) {
193
141
* @return the line thickness
194
142
*/
195
143
public synchronized double getLineWeight () {
196
- if (m_weightEntry != null ) {
197
- m_weight = m_weightEntry .get ();
198
- }
199
144
return m_weight ;
200
145
}
201
146
202
147
@ Override
203
- protected void updateEntries (NetworkTable table ) {
204
- if (m_typePub != null ) {
205
- m_typePub .close ();
206
- }
207
- m_typePub =
208
- table
209
- .getStringTopic (".type" )
210
- .publishEx (
211
- StringTopic .kTypeString , "{\" SmartDashboard\" :\" " + kSmartDashboardType + "\" }" );
212
- m_typePub .set (kSmartDashboardType );
213
-
214
- if (m_angleEntry != null ) {
215
- m_angleEntry .close ();
216
- }
217
- m_angleEntry = table .getDoubleTopic ("angle" ).getEntry (0.0 );
218
- m_angleEntry .set (m_angle );
219
-
220
- if (m_lengthEntry != null ) {
221
- m_lengthEntry .close ();
222
- }
223
- m_lengthEntry = table .getDoubleTopic ("length" ).getEntry (0.0 );
224
- m_lengthEntry .set (m_length );
225
-
226
- if (m_colorEntry != null ) {
227
- m_colorEntry .close ();
228
- }
229
- m_colorEntry = table .getStringTopic ("color" ).getEntry ("" );
230
- m_colorEntry .set (m_color );
231
-
232
- if (m_weightEntry != null ) {
233
- m_weightEntry .close ();
234
- }
235
- m_weightEntry = table .getDoubleTopic ("weight" ).getEntry (0.0 );
236
- m_weightEntry .set (m_weight );
148
+ public void toTelemetry (TelemetryTable table , boolean first ) {
149
+ if (first ) {
150
+ table .log (".type" , "line" );
151
+ }
152
+ table .log ("angle" , m_angle );
153
+ table .log ("length" , m_length );
154
+ table .log ("color" , m_color );
155
+ table .log ("weight" , m_weight );
237
156
}
238
157
}
0 commit comments