### Start CameraServer and Get Video/Output Streams (C++) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/vision-processing/introduction/cameraserver-class.rst This C++ snippet shows how to initiate automatic camera capture, retrieve a CvSink for video frames, and set up a CvSource for processed video output using the CameraServer library. ```c++ #include "cameraserver/CameraServer.h" // Creates UsbCamera and MjpegServer [1] and connects them frc::CameraServer::StartAutomaticCapture(); // Creates the CvSink and connects it to the UsbCamera cs::CvSink cvSink = frc::CameraServer::GetVideo(); // Creates the CvSource and MjpegServer [2] and connects them cs::CvSource outputStream = frc::CameraServer::PutVideo("Blur", 640, 480); ``` -------------------------------- ### Start CameraServer and Get Video/Output Streams (Java) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/vision-processing/introduction/cameraserver-class.rst This Java snippet demonstrates how to start the automatic camera capture, obtain a CvSink for receiving video frames, and create a CvSource for outputting processed video. It utilizes the high-level CameraServer API. ```java import edu.wpi.first.cameraserver.CameraServer; import edu.wpi.cscore.CvSink; import edu.wpi.cscore.CvSource; // Creates UsbCamera and MjpegServer [1] and connects them CameraServer.startAutomaticCapture(); // Creates the CvSink and connects it to the UsbCamera CvSink cvSink = CameraServer.getVideo(); // Creates the CvSource and MjpegServer [2] and connects them CvSource outputStream = CameraServer.putVideo("Blur", 640, 480); ``` -------------------------------- ### Setup Mecanum Drive - Java Source: https://context7.com/wpilibsuite/frc-docs/llms.txt Provides a Java example for setting up and controlling a holonomic mecanum drivetrain using WPILib's MecanumDrive class. This includes initializing the four motor controllers, inverting specific motors for correct movement, and demonstrating both Cartesian and Polar drive modes with a joystick input. ```java // Java - Mecanum Drive Setup public class Robot extends TimedRobot { private PWMSparkMax frontLeft = new PWMSparkMax(0); private PWMSparkMax frontRight = new PWMSparkMax(1); private PWMSparkMax backLeft = new PWMSparkMax(2); private PWMSparkMax backRight = new PWMSparkMax(3); private MecanumDrive robotDrive; private Joystick stick = new Joystick(0); @Override public void robotInit() { frontRight.setInverted(true); backRight.setInverted(true); robotDrive = new MecanumDrive(frontLeft, backLeft, frontRight, backRight); } @Override public void teleopPeriodic() { // Cartesian drive using X, Y, and rotation axes robotDrive.driveCartesian(-stick.getY(), -stick.getX(), -stick.getZ()); // Polar drive at 45 degrees with no rotation robotDrive.drivePolar(-stick.getY(), Rotation2d.fromDegrees(45), 0); } } ``` -------------------------------- ### Create Benchtop Test Program (C++/Java) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/redirects.txt Guides on creating benchtop test programs for FRC robots using C++ and Java. These examples help in testing robot functionality before deploying to the field. ```cpp #include "Robot.h" void Robot::RobotInit() { // Initialize your subsystems here } void Robot::RobotPeriodic() { // Called every 20ms, regardless of autonomous or teleop } void Robot::AutonomousInit() { // Autonomous code } void Robot::AutonomousPeriodic() { // Autonomous code } void Robot::TeleopInit() { // Teleop code } void Robot::TeleopPeriodic() { // Teleop code } void Robot::TestInit() { // Test code } void Robot::TestPeriodic() { // Test code } ``` ```java import edu.wpi.first.wpilibj.TimedRobot; public class Robot extends TimedRobot { @Override public void robotInit() { // Initialize your subsystems here } @Override public void robotPeriodic() { // Called every 20ms, regardless of autonomous or teleop } @Override public void autonomousInit() { // Autonomous code } @Override public void autonomousPeriodic() { // Autonomous code } @Override public void teleopInit() { // Teleop code } @Override public void teleopPeriodic() { // Teleop code } @Override public void testInit() { // Test code } @Override public void testPeriodic() { // Test code } } ``` -------------------------------- ### Ramsete Controller Example (Java) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/redirects.txt Provides an example of using the RamseteController for autonomous robot path following. It combines feedforward and feedback control to track a trajectory. ```java import edu.wpi.first.math.controller.RamseteController; import edu.wpi.first.math.geometry.Pose2d; import edu.wpi.first.math.trajectory.Trajectory; import edu.wpi.first.math.trajectory.TrajectoryConfig; import edu.wpi.first.math.trajectory.TrajectoryGenerator; import edu.wpi.first.math.trajectory.constraint.DifferentialDriveKinematicsConstraint; import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; public class RamseteExample { // Define robot kinematics (track width) private static final double kTrackwidthMeters = 0.6; private DifferentialDriveKinematics m_kinematics = new DifferentialDriveKinematics(kTrackwidthMeters); // Ramsete controller private RamseteController m_ramseteController = new RamseteController(); // Example trajectory generation public Trajectory generateTrajectory() { TrajectoryConfig config = new TrajectoryConfig( 3.0, // Max velocity (m/s) 2.0 // Max acceleration (m/s^2) ) .setKinematics(m_kinematics); // Add constraints if needed, e.g., DifferentialDriveKinematicsConstraint return TrajectoryGenerator.generateTrajectory( new Pose2d(0, 0, edu.wpi.first.math.geometry.Rotation2d.getDegrees(0)), java.util.List.of(), // Waypoints new Pose2d(1, 0, edu.wpi.first.math.geometry.Rotation2d.getDegrees(0)), config ); } // Example of using the controller in a loop (simplified) public void runRamsete(Trajectory trajectory, Pose2d currentPose) { double currentTimeSeconds = 0.020; // Assume a 20ms loop period var tf = trajectory.sample(currentTimeSeconds); var speeds = m_ramseteController.calculate(currentPose, tf.poseMeters, tf.velocityMetersPerSecond); var wheelSpeeds = m_kinematics.toWheelSpeeds(speeds); // Apply wheelSpeeds to your drivetrain motors System.out.println("Left Speed: " + wheelSpeeds.leftMetersPerSecond); System.out.println("Right Speed: " + wheelSpeeds.rightMetersPerSecond); } public static void main(String[] args) { RamseteExample example = new RamseteExample(); Trajectory trajectory = example.generateTrajectory(); Pose2d startPose = new Pose2d(0, 0, edu.wpi.first.math.geometry.Rotation2d.getDegrees(0)); example.runRamsete(trajectory, startPose); } } ``` -------------------------------- ### Get Help for RobotPy Subcommand (Shell) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/python/subcommands/index.rst Pass the '--help' argument to a specific RobotPy subcommand to view detailed information about its usage and options. This example shows how to get help for the 'sim' subcommand. ```shell py -3 -m robotpy sim --help ``` ```shell python3 -m robotpy sim --help ``` ```shell python3 -m robotpy sim --help ``` -------------------------------- ### Initialize Git Repository and Push (Empty Directory) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/basic-programming/git-getting-started.rst Initializes a new Git repository in an empty directory, adds a README file, creates the first commit, sets the remote origin, and pushes to the remote repository. This is useful for starting a new project from scratch. ```console > cd "C:\Users\ExampleUser9007\Documents\Example Folder" > git init Initialized empty Git repository in C:/Users/ExampleUser9007/Documents/Example Folder/.git/ > echo "# ExampleRepo" >> README.md > git add README.md > git commit -m "First commit" [main (root-commit) fafafa] First commit 1 file changed, 1 insertions(+), 0 deletions(-) create mode 100644 README.md > git remote add origin https://github.com/ExampleUser9007/ExampleRepo.git > git push -u origin main ``` -------------------------------- ### Run Robot Simulation via Gradle (Java/C++) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/wpilib-tools/robot-simulation/introduction.rst You can initiate robot simulation directly from the command line using Gradle. Use `./gradlew simulateJava` for Java projects and `./gradlew simulateNative` for C++ projects. These commands build and run your robot code in a simulated environment. ```bash ./gradlew simulateJava ``` ```bash ./gradlew simulateNative ``` -------------------------------- ### Get Double Topic from NetworkTableInstance and NetworkTable (Java, C++, Python) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/networktables/tables-and-topics.rst Demonstrates how to get a DoubleTopic from a NetworkTableInstance or a NetworkTable. This includes obtaining a type-specific topic directly or converting a generic Topic object. These examples show the preferred method for accessing topics. ```java NetworkTableInstance inst = NetworkTableInstance.getDefault(); NetworkTable table = inst.getTable("datatable"); // get a topic from a NetworkTableInstance // the topic name in this case is the full name DoubleTopic dblTopic = inst.getDoubleTopic("/datatable/X"); // get a topic from a NetworkTable // the topic name in this case is the name within the table; // this line and the one above reference the same topic DoubleTopic dblTopic = table.getDoubleTopic("X"); // get a type-specific topic from a generic Topic Topic genericTopic = inst.getTopic("/datatable/X"); DoubleTopic dblTopic = new DoubleTopic(genericTopic); ``` ```cpp nt::NetworkTableInstance inst = nt::NetworkTableInstance::GetDefault(); std::shared_ptr table = inst.GetTable("datatable"); // get a topic from a NetworkTableInstance // the topic name in this case is the full name nt::DoubleTopic dblTopic = inst.GetDoubleTopic("/datatable/X"); // get a topic from a NetworkTable // the topic name in this case is the name within the table; // this line and the one above reference the same topic nt::DoubleTopic dblTopic = table->GetDoubleTopic("X"); // get a type-specific topic from a generic Topic nt::Topic genericTopic = inst.GetTopic("/datatable/X"); nt::DoubleTopic dblTopic{genericTopic}; ``` ```python import ntcore inst = ntcore.NetworkTableInstance.getDefault() table = inst.getTable("datatable") # get a topic from a NetworkTableInstance # the topic name in this case is the full name dblTopic = inst.getDoubleTopic("/datatable/X") # get a topic from a NetworkTable # the topic name in this case is the name within the table; # this line and the one above reference the same topic dblTopic = table.getDoubleTopic("X") # get a type-specific topic from a generic Topic genericTopic = inst.getTopic("/datatable/X") dblTopic = ntcore.DoubleTopic(genericTopic) ``` -------------------------------- ### PathWeaver: Creating a Project Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/redirects.txt This document guides users through the process of creating a new PathWeaver project. It covers initial setup and configuration. ```rst .. _creating-pathweaver-project: Creating a PathWeaver Project ============================= This document provides a step-by-step guide on how to create a new project within PathWeaver. It covers the initial setup, including defining project properties and selecting the robot configuration. ``` -------------------------------- ### Create Subsystem - C++ Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/commandbased/subsystems.rst Demonstrates creating a simple subsystem by subclassing SubsystemBase in C++. This is the recommended approach for most users. ```c++ #pragma once #include "commands2/SubsystemBase.h" class ExampleSubsystem : public frc2::SubsystemBase { public: ExampleSubsystem(); // Called every time the scheduler runs while the command is scheduled. void periodic() override; // Called once the command ends or is interrupted. void simulationPeriodic() override; // Make this return true when this Command no longer needs to run execute() }; ``` -------------------------------- ### WPILib LabVIEW Dashboard Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/redirects.txt Guides for using the LabVIEW dashboard with WPILib projects. Covers setup, connectivity troubleshooting, and integration with C++ and Java code. ```rst LabVIEW Dashboard ================= .. toctree:: :maxdepth: 2 index driver-station-labview-dashboard using-the-labview-dashboard-with-c++-java-code troubleshooting-dashboard-connectivity ``` -------------------------------- ### Initialize Git Repository and Push (Existing Project) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/basic-programming/git-getting-started.rst Initializes a new Git repository in an existing project directory, stages all files, creates the first commit, sets the remote origin, and pushes to the remote repository. This is suitable for version controlling an ongoing project. ```console > cd "C:\Users\ExampleUser9007\Documents\Example Folder" > git init Initialized empty Git repository in C:/Users/ExampleUser9007/Documents/Example Folder/.git/ > git add . > git commit -m "First commit" [main (root-commit) fafafa] First commit 1 file changed, 1 insertions(+), 0 deletions(-) create mode 100644 README.md > git remote add origin https://github.com/ExampleUser9007/ExampleRepo.git > git push -u origin main ``` -------------------------------- ### Instantiating and Using Non-Static Command Factories (Java) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/commandbased/organizing-command-based.rst Demonstrates how to instantiate a non-static command factory class and use its methods to create various commands. This example shows creating individual commands and combining them into a sequence for autonomous routines. ```java AutoRoutines autoRoutines = new AutoRoutines(this.drivetrain, this.intake); Command driveAndIntake = autoRoutines.driveAndIntake(); Command driveThenIntake = autoRoutines.driveThenIntake(); Command drivingAndIntakingSequence = Commands.sequence( autoRoutines.driveAndIntake(), autoRoutines.driveThenIntake() ); ``` -------------------------------- ### Java Code With Minimal Logging Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/telemetry/robot-telemetry-with-annotations.rst Demonstrates basic logging setup in Java using the @Logged annotation on classes and their members. It shows how default log names are generated and provides an example of the resulting log data structure. ```java @Logged public class Robot extends RobotBase { private final Arm arm; // Anything loggable within the arm object will be logged under an "arm" entry public Robot() { arm = new Arm(); Epilogue.bind(this); } } @Logged class Arm { public final Trigger atLowStop = new Trigger(...); // Logged as a boolean in an "atLowStop" entry public final Trigger atHighStop = new Trigger(...); // Logged as a boolean in an "atHighStop" entry private Rotation2d lastPosition = getPosition(); // Logged as a Rotation2d struct in a "lastPosition" entry // Logged as a Rotation2d struct object in a "getPosition" entry public Rotation2d getPosition() { // ... } // Logged as a double in terms of radians per second in a "getSpeed" entry public Measure> getSpeed() { // ... } } ``` -------------------------------- ### Low-Level CameraServer Object Creation (C++) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/vision-processing/introduction/cameraserver-class.rst This C++ code demonstrates the manual creation of camera and MJPEG server objects using the cscore_oo header. It sets up a UsbCamera and an MjpegServer, then connects the server to the camera. ```c++ #include "cscore_oo.h" // Creates UsbCamera and MjpegServer [1] and connects them cs::UsbCamera usbCamera("USB Camera 0", 0); cs::MjpegServer mjpegServer1("serve_USB Camera 0", 1181); mjpegServer1.SetSource(usbCamera); ``` -------------------------------- ### Create Subsystem - Java Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/commandbased/subsystems.rst Demonstrates creating a simple subsystem by subclassing SubsystemBase in Java. This is the recommended approach for most users. ```java package frc.robot.subsystems; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class ExampleSubsystem extends SubsystemBase { /** Creates a new ExampleSubsystem. */ public ExampleSubsystem() {} @Override public void periodic() { // This method will be called once per scheduler run } @Override public void simulationPeriodic() { // This method will be called once per scheduler run during simulation } } ``` -------------------------------- ### Get Potentiometer Measurement for PIDSubsystem Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/wpilib-tools/robotbuilder/advanced/robotbuilder-writing-pidsubsystem-code.rst This method is responsible for retrieving the current sensor measurement, which is used as feedback for the PID controller. In this example, it reads the voltage from an AnalogPotentiometer. This method is crucial for the PID loop to know the current state. ```java @Override public double getMeasurement() { // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SOURCE return pot.get(); // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SOURCE } ``` ```c++ double Elevator::GetMeasurement() { // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SOURCE return m_pot.Get(); // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SOURCE } ``` -------------------------------- ### Example JVM Runtime Error (Windows Console) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/advanced-gradlerio/jvm-runtime.rst This console output shows a typical 'Invalid MSVC Runtime Detected' error encountered when WPILib's JNI libraries are compiled with a newer MSVC runtime than what the installed JDK provides. It specifies the expected and found runtime versions and provides a link for more information. ```console > Task :simulateJavaRelease FAILED If you receive errors loading the JNI dependencies, make sure you have the latest Visual Studio C++ Redstributable installed. That can be found at https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads Exception in thread "main" edu.wpi.first.util.MsvcRuntimeException: Invalid MSVC Runtime Detected. Expected at least 14.40, but found 14.29 JVM Location: C:\ Program Files\Amazon Corretto\jdk21.0.5_11\bin\java.exe Runtime DLL Location: C:\ Program Files\Amazon Corretto\jdk21.0.5_11\bin\msvcp140.dll See https://wpilib.org/jvmruntime for more information at edu.wpi.first.util.WPIUtilJNI.checkMsvcRuntime(Native Method) at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:470) at frc.robot.Main.main(Main.java:23) FAILURE: Build failed with an exception. ``` -------------------------------- ### Create Commands Using Factory Methods in Java, C++ Source: https://context7.com/wpilibsuite/frc-docs/llms.txt Illustrates how to create commands using factory methods like runOnce, run, and startEnd in Java and C++. These methods allow for inline command creation without separate classes and specify required subsystems. ```java // Java - Command Factories // runOnce: Execute once and finish immediately Command shootOnce = Commands.runOnce(() -> shooter.fire(), shooter); // run: Execute repeatedly until interrupted Command driveCommand = new RunCommand( () -> robotDrive.arcadeDrive(-controller.getLeftY(), controller.getRightX()), robotDrive); // startEnd: Execute start action, then end action when interrupted Command spinUpShooter = Commands.startEnd( () -> shooter.shooterSpeed(0.5), // Start: spin up flywheel () -> shooter.shooterSpeed(0.0), // End: stop flywheel shooter // Required subsystem ); // Command with requirements declared inline Commands.run(intake::activate, intake); ``` ```cpp // C++ - Command Factories // runOnce: Execute once and finish immediately frc2::CommandPtr shootOnce = frc2::cmd::RunOnce([this] { shooter.Fire(); }, {&shooter}); // run: Execute repeatedly until interrupted frc2::RunCommand driveCommand( [this] { m_drive.ArcadeDrive(-m_controller.GetLeftY(), m_controller.GetRightX()); }, {&m_drive}); // startEnd: Execute start action, then end action when interrupted frc2::CommandPtr spinUpShooter = frc2::cmd::StartEnd( [this] { m_shooter.ShooterSpeed(0.5); }, [this] { m_shooter.ShooterSpeed(0.0); }, {&m_shooter}); ``` -------------------------------- ### Creating Benchtop Test Program (LabVIEW) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/redirects.txt Step-by-step guide for creating, building, and loading a benchtop test program using LabVIEW for FRC robots. ```labview VI: Create Benchtop Test Program This VI allows users to create, build, and load a benchtop test program for their FRC robot using LabVIEW. It typically involves configuring robot components and testing their functionality. Dependencies: * LabVIEW Development Environment * WPILib LabVIEW Module Inputs: * Robot configuration settings * Component selection for testing Outputs: * Compiled benchtop test program * Test results Limitations: * Specific to LabVIEW environment. * May require specific hardware configurations. ``` -------------------------------- ### Install RobotPy to User Site-Packages (Windows) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/zero-to-robot/step-2/python-setup.rst Installs RobotPy to the user site-packages directory on Windows, which is useful when administrative rights are not available. This avoids the need for system-wide installation. ```shell py -3 -m pip install --user robotpy ``` -------------------------------- ### Generate Trajectory using Clamped Cubic Splines (Java, C++, Python) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/advanced-controls/trajectories/trajectory-generation.rst This snippet demonstrates generating a trajectory using clamped cubic splines. It takes start and end Pose2d objects and a vector of interior Translation2d waypoints. The headings at interior waypoints are automatically determined for continuous curvature. The Java example uses the Units utility for unit conversions. ```java var start = new Pose2d(3.0, 4.0, Rotation2d.fromDegrees(0.0)); var end = new Pose2d(5.0, 5.0, Rotation2d.fromDegrees(90.0)); var interiorWaypoints = List.of(new Translation2d(3.5, 3.5)); var trajectory = TrajectoryGenerator.generateClampedCubic(start, end, interiorWaypoints); ``` ```c++ auto start = Pose2d(3.0_m, 4.0_m, Rotation2d(0_rad)); auto end = Pose2d(5.0_m, 5.0_m, Rotation2d(90_deg)); auto interiorWaypoints = std::vector{ Translation2d(3.5_m, 3.5_m) }; auto trajectory = frc::TrajectoryGenerator::generateClampedCubic( start, end, interiorWaypoints); ``` ```python start = Pose2d(3, 4, Rotation2d(0)) end = Pose2d(5, 5, Rotation2d(math.radians(90))) interior_waypoints = [ Translation2d(3.5, 3.5) ] trajectory = TrajectoryGenerator.generate_clamped_cubic( start, end, interior_waypoints ) ``` -------------------------------- ### DriveSim Tutorial Overview Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/redirects.txt Overview of the DriveSim tutorial, which focuses on simulating drivetrain behavior in WPILib. It covers setting up a drivetrain model and its integration with simulation tools. ```rst .. _diffdrive-sim-overview: DiffDrive Sim Overview ====================== This tutorial will cover how to use DriveSim to simulate your drivetrain. .. toctree:: :maxdepth: 2 drivetrain-model odometry-simgui simulation-instance updating-drivetrain-model ``` -------------------------------- ### Install RobotPy to User Site-Packages (macOS) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/zero-to-robot/step-2/python-setup.rst Installs RobotPy to the user site-packages directory on macOS, which is a workaround for systems where administrative privileges are restricted. This allows installation without root access. ```shell python3 -m pip install --user robotpy ``` -------------------------------- ### Install RobotPy Core Packages (Windows) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/zero-to-robot/step-2/python-setup.rst Installs the core RobotPy packages on Windows using pip. This command should be run from cmd or PowerShell. Ensure Python is installed and accessible via 'py'. ```shell py -3 -m pip install robotpy ``` -------------------------------- ### Install RobotPy Core Packages (macOS) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/zero-to-robot/step-2/python-setup.rst Installs the core RobotPy packages on macOS using pip. This command requires Python 3 and pip to be installed and accessible via 'python3'. It may require administrator privileges. ```shell python3 -m pip install robotpy ``` -------------------------------- ### Instantiate LinearSystemLoop in Java, C++, and Python Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/advanced-controls/state-space/state-space-flywheel-walkthrough.rst Demonstrates the instantiation of the LinearSystemLoop class, which combines the system, controller, and observer. This constructor also initializes a PlantInversionFeedforward. ```java var plant = new LinearSystem(...); var controller = new LinearFeedforward(...); var observer = new KalmanFilter(...); var loop = new LinearSystemLoop<>(plant, controller, observer, 0.02); var feedforward = new PlantInversionFeedforward<>(plant, controller, 0.02); ``` ```c++ auto plant = LinearSystem<2, 1, 1>(...); auto controller = LinearFeedforward<2, 1>(...); auto observer = KalmanFilter<2, 1, 1>(...); auto loop = LinearSystemLoop<2, 1>(plant, controller, observer, 0.02_s); auto feedforward = PlantInversionFeedforward<2, 1>(plant, controller, 0.02_s); ``` ```python plant = wpilib.LinearSystem(2, 1, [0.01]) controller = wpilib.LinearFeedforward(plant, 0.02) observer = wpilib.KalmanFilter(plant, controller, 0.02) loop = wpilib.LinearSystemLoop(plant, controller, observer, 0.02) ``` -------------------------------- ### Example ReST Article Structure Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/contributing/frc-docs/style-guide.rst Provides a basic example of a ReStructuredText (ReST) article structure, including a title, introductory text, a code block, and a section heading. ```rst # Title This is an example article ```java System.out.println("Hello World"); ``` ## Section This is a section! ``` -------------------------------- ### Use Instance Command Factory Methods in Command Compositions (Java & C++) Source: https://github.com/wpilibsuite/frc-docs/blob/main/source/docs/software/commandbased/organizing-command-based.rst Shows how to utilize the factory methods created within subsystem classes for command compositions, button bindings, and autonomous routines. This allows for expressive and concise command creation. ```java intakeButton.whileTrue(intake.runIntakeCommand()); Command intakeAndShoot = intake.runIntakeCommand().alongWith(new RunShooter(shooter)); Command autonomousCommand = Commands.sequence( intake.runIntakeCommand().withTimeout(5.0), Commands.waitSeconds(3.0), intake.runIntakeCommand().withTimeout(5.0) ); ``` ```c++ intakeButton.WhileTrue(intake.RunIntakeCommand()); frc2::CommandPtr intakeAndShoot = intake.RunIntakeCommand().AlongWith(RunShooter(&shooter).ToPtr()); frc2::CommandPtr autonomousCommand = frc2::cmd::Sequence( intake.RunIntakeCommand().WithTimeout(5.0_s), frc2::cmd::Wait(3.0_s), intake.RunIntakeCommand().WithTimeout(5.0_s) ); ```