WPILib Örnek Projeler

Uyarı

WPILib örneklerini işlevsel tutmak için her girişimde bulunulsa da, “olduğu gibi” kullanılması amaçlanmamıştır. Kodun bir kullanıcı robotunda çalışması için en azından robota özgü sabitlerin değiştirilmesi gerekecektir. Birçok ampirik sabitin değerleri, gösterim amacıyla “sahte” hale getirilmiştir. Kullanıcıların, örnek kodu kopyalamak yerine kendi kodlarını (sıfırdan veya mevcut bir şablondan) yazmaları şiddetle tavsiye edilir.

WPILib örnek projeleri, çok sayıda kitaplık özelliği ve kullanım desenleri gösterir. Projeler, tek bir işlevin basit gösterimlerinden eksiksiz, rekabete uygun robot programlarına kadar çeşitlilik gösterir. Bu örneklerin tümü VS Code’da şu şekilde kullanılabilir Ctrl+Shift+P, ardından WPILib: Create a new project ve örnek seçilerek.

../../../_images/create-new-project.png

Temel Örnekler

Bu örnekler, temel / minimum robot işlevselliğini gösterir. Robot programlamaya ilk aşina olan, ancak işlevsellik açısından oldukça sınırlı olan yeni başlayan ekipler için kullanışlıdır.

  • Arcade Drive (Java, C++, Python): Demonstrates a simple differential drive implementation using “arcade”-style controls through the DifferentialDrive class.

  • Getting Started (Java, C++, Python): Demonstrates a simple autonomous routine that drives forwards for two seconds at half speed.

  • Mecanum Drive (Java, C++, Python): Demonstrates a simple mecanum drive implementation using the MecanumDrive class.

  • TankDrive (Java, C++, Python): Demonstrates a simple differential drive implementation using “tank”-style controls through the DifferentialDrive class.

Kontrol Örnekleri

Bu örnekler, yaygın robot kontrollerinin WPILib uygulamalarını gösterir. Sensörler mevcut olabilir, ancak bu örneklerin vurgulanan konsepti değildir.

  • DifferentialDriveBot (Java, C++, Python): Demonstrates an advanced differential drive implementation, including encoder-and-gyro odometry through the DifferentialDriveOdometry class, and composition with PID velocity control through the DifferentialDriveKinematics and PIDController classes.

  • DifferentialDrivePoseEstimator (Java, C++): Demonstrates an advanced differential drive implementation with all the features of DifferentialDriveBot. In addition this example uses DifferentialDrivePoseEstimator to track the robots position on the field. It demonstrates these features by using WPILib Simulation.

  • Elevator with Profiled PID Controller (Java, C++, Python): Demonstrates the use of the ProfiledPIDController class to control the position of an elevator mechanism.

  • Elevator with Trapezoid Profiled PID (Java, C++, Python): Demonstrates the use of the TrapezoidProfile class in conjunction with a “smart motor controller” to control the position of an elevator mechanism.

  • Elevator with Exponential Profiled PID (Java, C++): Demonstrates the use of the ExponentialProfile class in conjunction with a “smart motor controller” to control the position of an elevator mechanism.

  • MecanumBot (Java, C++, Python): Demonstrates an advanced mecanum drive implementation, including encoder-and-gyro odometry through the MecanumDriveOdometry class, and composition with PID velocity control through the MecanumDriveKinematics and PIDController classes.

  • Mecanum Drive PoseEstimator (Java, C++): Demonstrates an advanced mecanum drive implementation with all the features of MecanumBot. In addition this example uses MecanumDrivePoseEstimator to track the robots position on the field.

  • SwerveBot (Java, C++, Python): Demonstrates an advanced swerve drive implementation, including encoder-and-gyro odometry through the SwerveDriveOdometry class, and composition with PID position and velocity control through the SwerveDriveKinematics and PIDController classes.

  • Swerve Drive PoseEstimator (Java, C++): Demonstrates an advanced swerve drive implementation with all the features of SwerveBot. In addition this example uses SwerveDrivePoseEstimator to track the robots position on the field.

Sensör Örnekleri

Bu örnekler, WPILib kullanarak sensör okumayı ve veri işlemeyi gösterir. Mekanizma kontrolü mevcut olabilir, ancak bu örneklerin vurgulanan konsepti değildir.

  • Duty Cycle Encoder (Java, C++, Python): Demonstrates the use of the DutyCycleEncoder class to read values from a PWM-type absolute encoder.

  • Encoder (Java, C++, Python): Demonstrates the use of the Encoder class to read values from a quadrature encoder.

  • Gyro (Java, C++, Python): Demonstrates the use of the AnalogGyro class to measure robot heading and stabilize driving.

  • SysIdRoutine (Java, C++, Python): Demonstrates the use of the SysIdRoutine API to gather characterization data for a differential drivetrain.

Komut-Tabanlı Örnekler

These examples demonstrate the use of the Command-Based framework.

  • DriveDistanceOffboard (Java, C++, Python): Demonstrates the use of a TrapezoidProfileCommand in conjunction with a “smart motor controller” to drive forward by a set distance with a trapezoidal motion profile.

  • Rapid React Command Bot (Java, C++): This project uses the latest command based best practices and the Epilogue logging system. It is capable of playing the FRC 2022 game Rapid React.

  • Inlined Hatchbot (Java, C++, Python): A complete set of robot code for a simple hatch-delivery bot typical of the 2019 FRC game Destination: Deep Space. Commands are written in an “inline” style, in which explicit subclassing of Command is avoided.

  • Traditional Hatchbot (Java, C++, Python): A complete set of robot code for a simple hatch-delivery bot typical of the 2019 FRC game Destination: Deep Space. Commands are written in a “traditional” style, in which subclasses of Command are written for each robot action.

State-Space Durum Uzayı Örnekleri

Bu örnekler, State-Space Control. ‘ın kullanımını gösterir.

  • StateSpaceFlywheel (Java, C++, Python): Demonstrates state-space control of a flywheel.

  • StateSpaceFlywheelSysId (Java, C++, Python): Demonstrates state-space control using SysId’s System Identification for controlling a flywheel.

  • StateSpaceElevator (Java, C++, Python): Demonstrates state-space control of an elevator.

  • StateSpaceArm (Java, C++, Python): Demonstrates state-space control of an Arm.

Simülasyon Fiziği Örnekleri

Bu örnekler, fizik simülasyonunun kullanımını göstermektedir.

  • ElevatorSimulation (Java, C++, Python): Demonstrates the use of physics simulation with a simple elevator.

  • ElevatorSimulation with Exponential PID (Java, C++): Demonstrates the use of physics simulation of an elevator being controlled with exponential profiled PID.

  • ArmSimulation (Java, C++, Python): Demonstrates the use of physics simulation with a simple single-jointed arm.

  • SimpleDifferentialDriveSimulation (Java, C++): A barebones example of a basic drivetrain that can be used in simulation.

Çeşitli Örnekler

Bu örnekler, yukarıdaki kategorilerin hiçbirine uymayan çeşitli WPILib işlevselliğini gösterir.

  • HAL (C++): Demonstrates the use of HAL (Hardware Abstraction Layer) without the use of the rest of WPILib. This example is for advanced users (C++ only).

  • RomiReference (Java, C++, Python): A command based example of how to run the Romi robot.

  • XRPReference (Java, C++): A command based example of how to run the XRP robot.

  • Mechanism2d (Java, C++, Python): A simple example of using Mechanism2d.

  • UnitTest (Java, C++): Shows how to do Unit Testing. The test files need to be in a separate Test directory (Java, C++).

Snippets

These examples demonstrate a single item.

  • Addressable LED (Java, C++, Python): Demonstrates the use of the AddressableLED class to control RGB LEDs for robot decoration and/or driver feedback.

  • AprilTagsVision (Java, C++, Python): Demonstrates on-roboRIO detection of AprilTags using an attached USB camera.

  • Digital Communication (Java, C++, Python): This is a sample program demonstrating how to communicate to a light controller from the robot code using the roboRIO’s DIO ports.

  • DutyCycleInput (Java, C++, Python): Demonstrates the use of the DutyCycleInput class to read the frequency and fractional duty cycle of a PWM input.

  • EventLoop (Java, C++): Demonstrates the use of the EventLoop class that allows code to be called based on a boolean condition in the event-driven programming style.

  • Flywheel Bang-Bang Controller (Java, C++, [Python](https://github.com/robotpy/mostrobotpy/tree/main/snippets/robot/FlywheelBangBangController )): Uses the BangBangController class to simply yet effectively control a flywheel.

  • HTTP Camera (Java, C++): Demonstrates the use of OpenCV and a HTTP Camera to overlay a rectangle on a captured video feed and stream it to the dashboard.

  • I2C Communication (Java, C++, Python): This is a sample program demonstrating how to communicate to a light controller from the robot code using the roboRIO’s I2C port.

  • Intermediate Vision (Java, C++, Python): Demonstrates the use of OpenCV and a USB camera to overlay a rectangle on a captured video feed and stream it to the dashboard.

  • Motor Controller (Java, C++, Python): Demonstrates how to control the output of a motor with a joystick with an encoder to read motor position.

  • Power Distribution CAN Monitoring (Java, C++, Python): Demonstrates obtaining sensor information from a Power Distribution module over CAN using the PowerDistribution class.

  • Select Command Example (Java, C++, Python): Demonstrates the use of the SelectCommand class to run one of a selection of commands depending on a runtime-evaluated condition.

  • Simple Vision (Java, C++, Python): Demonstrates how to stream video from a USB camera to the dashboard.

  • Solenoids (Java, C++, Python): Demonstrates the use of the Solenoid and DoubleSolenoid classes to control solenoid outputs with a set of joystick buttons.