Exemples fournis de Projets WPILib

Avertissement

Bien qu’on ne ménage aucun effort pour maintenir les exemples WPILib fonctionnels, ils ne sont pas destinés à être utilisés « tel quel ». À tout le moins, les valeurs constantes spécifiques aux robots devront être modifiées pour que le code fonctionne sur le robot de l’utilisateur. Beaucoup de constantes empiriques ont des valeurs « factices » à des fins de démonstration. Les utilisateurs sont fortement encouragés à écrire leur propre code (à partir de zéro ou à partir d’un modèle existant) plutôt que de copier le code d’exemple et de l’utiliser tel quel.

Les exemples de projets WPILib illustrent un grand nombre de fonctionnalités de bibliothèque et de modèles d’utilisation. Les projets vont de la simple démonstration d’une seule fonctionnalité à des programmes robotiques complets et compétitifs. Tous ces exemples sont disponibles dans VS Code en entrant Ctrl+Shift+P, puis en sélectionnant WPILib: Create a new project et en choisissant l’exemple.

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

Exemples de base

Ces exemples démontrent la fonctionnalité de base/minimale du robot. Ils sont utiles pour des équipes recrues qui s’initient à la programmation de robots, mais sont grandement limités en terme de fonctionnalité.

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

  • Arcade Drive Xbox Controller (Java, C++, Python): Demonstrates the same functionality seen in the previous example, except using an XboxController instead of an ordinary joystick.

  • 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.

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

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

  • Relay (Java, C++, Python): Demonstrates the use of the Relay class to control a relay output with a set of joystick buttons.

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

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

  • Tank Drive Xbox Controller (Java, C++, Python): Demonstrates the same functionality seen in the previous example, except using an XboxController instead of an ordinary joystick.

Exemples de contrôle (commande)

Ces exemples illustrent les implémentations dans la WPILib de contrôles de robot courants. Les capteurs peuvent être présents, mais ils ne constituent pas le point focal dans ces exemples.

  • 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.

  • Flywheel Bang-Bang Controller (Java, C++, Python): Uses the BangBangController class to simply yet effectively control a flywheel.

  • Gyro Mecanum (Java, C++, Python): Demonstrates field-oriented control of a mecanum robot through the MecanumDrive class in conjunction with a gyro.

  • 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.

  • PotentiometerPID (Java, C++, Python): Demonstrates the use of the PIDController class and a potentiometer to control the position of an elevator mechanism.

  • 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.

  • UltrasonicPID (Java, C++, Python): Demonstrates the use of the PIDController class in conjunction with an ultrasonic sensor to drive to a set distance from an object.

Exemples de programmation de capteurs

Ces exemples démontrent la lecture de signaux à partir des capteurs et le traitement des données à l’aide de WPILib. Le contrôle des mécanismes peut être présent, mais ce n’est pas le point focal de ces exemples.

  • 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.

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

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

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

  • 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.

  • 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.

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

  • Ultrasonic (Java, C++, Python): Demonstrates the use of the Ultrasonic class to read data from an ultrasonic sensor in conjunction with the MedianFilter class to reduce signal noise.

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

Exemples de programmes basés sur l’architecture orientée Commande

Ces exemples démontrent l’utilisation du cadre de développement orienté Commande.

  • 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.

  • MecanumControllerCommand (Java, C++): Demonstrates trajectory generation and following with a mecanum drive using the TrajectoryGenerator and MecanumControllerCommand classes.

  • 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.

  • SwerveControllerCommand (Java, C++): Demonstrates trajectory generation and following with a swerve drive using the TrajectoryGenerator and SwerveControllerCommand classes.

Exemples d’espace d’état

Ces exemples illustrent l’utilisation de la commande espace-d’état.

  • 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.

Exemples de physique de simulation

Ces exemples démontrent l’utilisation de la simulation physique.

  • 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.

Exemples divers

Ces exemples illustrent une variété de fonctionnalités WPILib qui ne s’inscrivent dans aucune des catégories ci-dessus.

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

  • 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.

  • 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.

  • DMA (Java, C++): Demonstrates the use of DMA (Direct Memory Access) to read from sensors without using the RoboRIO’s CPU.

  • 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).

  • HID Rumble (Java, C++, Python): Demonstrates the use of the « rumble » functionality for tactile feedback on supported HIDs (such as XboxControllers).

  • Shuffleboard (Java, C++, Python): Demonstrates configuring tab/widget layouts on the « Shuffleboard » dashboard from robot code through the Shuffleboard class’s fluent builder API.

  • 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.

  • 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.

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