Skip to content

Commit f654087

Browse files
committed
SmartDashboard; tidy up with folders
1 parent 5bf7af2 commit f654087

File tree

8 files changed

+83
-7
lines changed

8 files changed

+83
-7
lines changed

src/main/java/frc/robot/examples/JoystickExamples.java renamed to src/main/java/frc/robot/examples/hid/JoystickExamples.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Open Source Software; you can modify and/or share it under the terms of
33
// the WPILib BSD license file in the root directory of this project.
44

5-
package frc.robot.examples;
5+
package frc.robot.examples.hid;
66

77
import edu.wpi.first.wpilibj.Joystick;
88
import edu.wpi.first.wpilibj.XboxController;
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* Joystick examples.
14+
* HID = Human Interface Device (like a joystick)
1415
*/
1516
public abstract class JoystickExamples {
1617
// Get joystick using Port Number on Driver Station

src/main/java/frc/robot/examples/MotorControllerExamples.java renamed to src/main/java/frc/robot/examples/motors/MotorControllerExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Open Source Software; you can modify and/or share it under the terms of
33
// the WPILib BSD license file in the root directory of this project.
44

5-
package frc.robot.examples;
5+
package frc.robot.examples.motors;
66

77
import com.revrobotics.CANSparkMax;
88
import com.revrobotics.SparkPIDController;

src/main/java/frc/robot/examples/PneumaticsExamples.java renamed to src/main/java/frc/robot/examples/pneumatics/PneumaticsExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Open Source Software; you can modify and/or share it under the terms of
33
// the WPILib BSD license file in the root directory of this project.
44

5-
package frc.robot.examples;
5+
package frc.robot.examples.pneumatics;
66

77
import edu.wpi.first.wpilibj.DoubleSolenoid;
88
import edu.wpi.first.wpilibj.PneumaticsModuleType;

src/main/java/frc/robot/examples/DigitalInputExamples.java renamed to src/main/java/frc/robot/examples/sensors/DigitalInputExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Open Source Software; you can modify and/or share it under the terms of
33
// the WPILib BSD license file in the root directory of this project.
44

5-
package frc.robot.examples;
5+
package frc.robot.examples.sensors;
66

77
import edu.wpi.first.wpilibj.DigitalInput;
88

src/main/java/frc/robot/examples/EncoderExamples.java renamed to src/main/java/frc/robot/examples/sensors/EncoderExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Open Source Software; you can modify and/or share it under the terms of
33
// the WPILib BSD license file in the root directory of this project.
44

5-
package frc.robot.examples;
5+
package frc.robot.examples.sensors;
66

77
import com.revrobotics.CANSparkLowLevel.MotorType;
88

src/main/java/frc/robot/examples/GyroExamples.java renamed to src/main/java/frc/robot/examples/sensors/GyroExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Open Source Software; you can modify and/or share it under the terms of
33
// the WPILib BSD license file in the root directory of this project.
44

5-
package frc.robot.examples;
5+
package frc.robot.examples.sensors;
66

77
import com.kauailabs.navx.frc.AHRS;
88

src/main/java/frc/robot/examples/UltrasonicExamples.java renamed to src/main/java/frc/robot/examples/sensors/UltrasonicExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Open Source Software; you can modify and/or share it under the terms of
33
// the WPILib BSD license file in the root directory of this project.
44

5-
package frc.robot.examples;
5+
package frc.robot.examples.sensors;
66

77
import edu.wpi.first.wpilibj.Ultrasonic;
88

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
package frc.robot.examples.telemetry;
6+
7+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
8+
9+
/**
10+
* Examples for logging data in your code to Smart Dashboard.
11+
* This allows you to view variables on the Driver Station in real time.
12+
*/
13+
public abstract class SmartDashboardExamples {
14+
15+
/**
16+
* You can put data to the Smart Dashboard in your code. Each variable you put needs to have
17+
* a unique key to go with it. The unique key is a string. This key is the name of the variable
18+
* so you can find it on the dashbord on the Driver Station laptop. This also works in the simulator.
19+
*/
20+
private void SmartDashobard_PutData_Example() {
21+
// You can put numbers, booleans, and strings
22+
23+
// numbers (int, double, float, etc)
24+
double someNumberInYourCode = 4342;
25+
SmartDashboard.putNumber("", someNumberInYourCode);
26+
27+
// booleans (true or false)
28+
boolean someBooleanInYourCode = true;
29+
SmartDashboard.putBoolean("", someBooleanInYourCode);
30+
31+
// strings
32+
String someStringInYourCode = "SomeString";
33+
SmartDashboard.putString("", someStringInYourCode);
34+
35+
36+
// You can put arrays to the dashboard as well
37+
38+
// array of numbers (int[], double[], float[], etc)
39+
double[] someArrayOfNumbersInYourCode = { 1, 2, 3 };
40+
SmartDashboard.putNumberArray("", someArrayOfNumbersInYourCode);
41+
42+
// array of booleans
43+
boolean[] someArrayOfBooleansInYourCode = { true, false, true };
44+
SmartDashboard.putBooleanArray("", someArrayOfBooleansInYourCode);
45+
46+
// array of strings
47+
String[] someArrayOfStringsInYourCode = { "ABC", "DEF", "GHI" };
48+
SmartDashboard.putStringArray("", someArrayOfStringsInYourCode);
49+
}
50+
51+
/**
52+
* You can also get data from the Smart Dashboard. You can change the variable on the Driver Station laptop
53+
* and the variable in the code will update in real time. This can be useful in certain situations.
54+
*/
55+
private void SmartDashboard_GetData_Example() {
56+
// Put empty data to start with so there is a value on the Driver Station dashboard to change
57+
SmartDashboard.putNumber("ChangeMe!", 1);
58+
59+
// Once on the dashboard it will show up and can be retrieved at any point.
60+
// If the key does not exist meaning we never put it there in the first place, then return a default value.
61+
double defaultValue = 0;
62+
double currentValue = SmartDashboard.getNumber("ChangeMe!", defaultValue);
63+
64+
// Keep in mind that if you set the variable in the code it will update on the laptop too.
65+
// The data is "bi-directional" meaning the code can change it and so can the Dashboard on the Driver Station
66+
double someNewValue = 4342;
67+
SmartDashboard.putNumber("ChangeMe!", someNewValue);
68+
// updatedValue is now 4342
69+
double updatedValue = SmartDashboard.getNumber("ChangeMe!", defaultValue);
70+
71+
72+
// The same principles apply for booleans, strings, and all their array counterparts
73+
}
74+
75+
}

0 commit comments

Comments
 (0)