SmartDashboard / Cameras
SmartDashboard is a key component in the FRC Control System produced by FIRST. It's a desktop application that provides a real-time view of the operation of your robot, by displaying values from your robot code. Whether you want to monitor sensor readings, tune parameters, or pick autonomous modes, SmartDashboard plays an integral role.
Writing Data to SmartDashboard
To send data from your robot code to the SmartDashboard, use the static
putXXX methods in the
SmartDashboard class. Here's a breakdown:
- Sending Basic Data Types
SmartDashboard.putBoolean("Is Active", true);
- Sending Complex Data Types
- For any data type implementing the
Sendableinterface, you can put it directly:
AnalogPotentiometer pot = new AnalogPotentiometer(1); SmartDashboard.putData("Potentiometer", pot);
- For any data type implementing the
Reading Data from SmartDashboard
Reading from the SmartDashboard allows your robot to react to inputs or configurations set by drivers or operators.
Fetching Basic Data Types
double speed = SmartDashboard.getNumber("Speed", 0.0);
String status = SmartDashboard.getString("Status", "Default");
boolean isActive = SmartDashboard.getBoolean("Is Active", false);
The second argument in each method is a default value, which is returned if the specified key does not exist.
Widgets and Layouts
The data you put on the SmartDashboard can be represented in various ways, called widgets. By default, SmartDashboard selects an appropriate widget based on the type of data. However, you can change this by right-clicking on an entry and selecting another widget.
SmartDashboard also supports different layouts to help organize your data in a more logical or aesthetically pleasing manner. Experiment with the "Add" menu on SmartDashboard to see available options.
Integrating Camera Feed with SmartDashboard
A live camera feed can be invaluable for FRC teams, whether it's for drivers to better navigate the field or for processing images on the fly. The WPILib suite, in tandem with SmartDashboard, makes streaming a camera feed straightforward.
Setting Up the Camera
Connect the Camera: Most teams use USB cameras due to their simplicity. Connect your camera to the roboRIO's USB port.
Initialize the Camera in Code: You can utilize the CameraServer class to quickly start streaming a camera feed.
// In your robot's initialization code: CameraServer.getInstance().startAutomaticCapture(); The above code automatically configures the camera with default settings and starts streaming.
Viewing Camera Feed on SmartDashboard
Open SmartDashboard: Once you've initialized your camera in code and the robot code is running, open the SmartDashboard.
Add the Camera Stream: From the SmartDashboard menu, click on
View > Add > Camera Stream. If your camera is streaming correctly, it should appear in the dropdown list. Select it, and the stream will appear on your SmartDashboard.
Position and Resize: Like other widgets on the SmartDashboard, you can move and resize the camera stream to fit your layout preferences.
- Multiple Cameras: If you have multiple cameras on your robot, you can initialize each one and give them distinct names. This allows you to switch between different views on the SmartDashboard. CameraServer.getInstance().startAutomaticCapture(0).setName("Front Camera"); CameraServer.getInstance().startAutomaticCapture(1).setName("Rear Camera");
- Adjusting Camera Settings: Many USB cameras allow settings adjustments like resolution, frames per second (FPS), and brightness. Refer to the camera's documentation and WPILib's
UsbCameraclass to tweak these settings programmatically.
- Set up a basic robot project and write code that sends a variety of data types to the SmartDashboard.
- Experiment with retrieving data in your robot code that you set directly on the SmartDashboard.
- Connect a USB camera to your roboRIO and initialize it in your robot code.
- Display the camera feed on the SmartDashboard and adjust its position and size.
- Organize your dashboard using a layout of your choice.