-
Notifications
You must be signed in to change notification settings - Fork 6
Singleton Pattern
Singletons are used to create classes that can only have a single instance (hence the name, singleton), such as RobotContainer
or Autonomous
.
We do this by having a private static variable where the type is the class we're making a singleton. For example, in Java, we do:
public class Singleton {
private static Singleton instance;
}
Then, in our constructor, we set the instance if it is null. We throw an exception if it is not null.
public class Singleton {
private static Singleton instance;
public Singleton() {
if (instance != null) {
// Throw an exception or do some logging
return;
}
instance = this;
}
}
So why use a singleton?
To stop our future selves from making dumb choices. Many classes, such as RobotContainer
should not have multiple instances. We only have one robot, so we only want a single container for that robot. Multiple containers would mean multiple subsystems and thus multiple motors on the same port and then issues. So, we make RobotContainer
a singleton!
-Brought to you by Dr. Singleton
This is an officially licensed product of Team 4026. Decatur Robotics 2024 is not sponsored by any other Team, and is not responsible for any damages caused by using this product or trusting the programming team, which is by far the least most trustworthy team(Shadow owen money gang, we love coding the robot). By using this product, you are consenting to your information, and thus your identity to be stolen and first-born child taken.
- Editing Documentation & Markdown Syntax
- Code Team to-do List
- Code Standards
- Common Library Structure
- Interfaces
- General Setup
- Branching System
- How to Create Pull Requests
- How to Switch Branches
- Code Reviews
- Reverting Commits
- Singleton Pattern
- Software Installations
- Necessary IntelliJ Plugins
- Vendordeps
- Setting Up New Projects
- Autoformatter Set Up
- Showbot Requirements
- Autonomous
- Calling a Command Based on a Button Press
- CAN
- Clearing Sticky Faults
- Current Limits
- PID Config and Usage
- Robot.java, TeleopInit, DisabledInit
- RoboRio Ports
- SetDefaultCommand
- Wait for Time
- SlewRateLimiter
- LEDs
- InstantCommand
- PhotonVision
- Apriltags
- Camera Display on Shuffleboard
- Object Detection
- Raspberry Pi
- Network Tables
- List of Network Tables (2023)
Up to date as of SJ2, end of 2023 season