[examples] Clean up examples (#8674)

Move various "examples" into snippets. Several examples that were less
than a full mechanism or robot were moved to snippets. `arcadedrive` and
`tankdrive` were removed in favor of their Gamepad variants. `hidrumble`
was removed due to being too simple. `potentiometerpid` was removed
because of low utility. `gyromecanum` replaced `mecanumdrive` for
deduplication and because very few teams run holonomic drivetrains
without gyros.
This commit is contained in:
Gold856
2026-03-14 17:13:45 -04:00
committed by GitHub
parent 62ce8944aa
commit f1adce4cf7
78 changed files with 569 additions and 1665 deletions

View File

@@ -0,0 +1,48 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "Robot.hpp"
#include <string>
#include <fmt/format.h>
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/system/Timer.hpp"
void Robot::RobotPeriodic() {
// Creates a string to hold current robot state information, including
// alliance, enabled state, operation mode, and match time. The message
// is sent in format "AEM###" where A is the alliance color, (R)ed or
// (B)lue, E is the enabled state, (E)nabled or (D)isabled, M is the
// operation mode, (A)utonomous or (T)eleop, and ### is the zero-padded
// time remaining in the match.
//
// For example, "RET043" would indicate that the robot is on the red
// alliance, enabled in teleop mode, with 43 seconds left in the match.
std::string allianceString = "U";
auto alliance = wpi::DriverStation::GetAlliance();
if (alliance.has_value()) {
if (alliance == wpi::DriverStation::Alliance::kRed) {
allianceString = "R";
} else {
allianceString = "B";
}
}
auto string =
fmt::format("{}{}{}{:03}", allianceString,
wpi::DriverStation::IsEnabled() ? "E" : "D",
wpi::DriverStation::IsAutonomous() ? "A" : "T",
static_cast<int>(wpi::Timer::GetMatchTime().value()));
arduino.WriteBulk(reinterpret_cast<uint8_t*>(string.data()), string.size());
}
#ifndef RUNNING_WPILIB_TESTS
int main() {
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -0,0 +1,25 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <array>
#include "wpi/framework/TimedRobot.hpp"
#include "wpi/hardware/bus/I2C.hpp"
/**
* This is a sample program demonstrating how to communicate to a light
* controller from the robot code using the roboRIO's I2C port.
*/
class Robot : public wpi::TimedRobot {
public:
void RobotPeriodic() override;
static constexpr wpi::I2C::Port kPort = wpi::I2C::Port::kPort0;
private:
static constexpr int deviceAddress = 4;
wpi::I2C arduino{kPort, deviceAddress};
};