Beginner Programming - TAMSFormers5212/TAMSformers-Database GitHub Wiki
This is a run down of the core functionality that all robot programs are likely to use.
The WPILib API is the standard software library that provides the ability to control and interface with the hardware of the robot. It provides a host of useful classes, functions, and routines that make it possible to program a FRC Robot.
This section is meant to list the core functionality of WPILib that we use.
All robots need a command scheduling system to control what happens and when. WPILib implements a system of subsystems and commands in its "command-based" paradigm.
Robotics programming and really any programming where things are moving will need a good grasp of units. WPILib has a specific library for C++ units that operates differently from the Java units library.
Sensors can send their data to the roborio in a couple of ways. The roborio can use a variety of signal types including analog input, digital input and output, and pwm control. It also has SPI and I2C ports. We use the mxp port that is typically filled by the NavX which also serves as a breakout board, providing more ports to the roborio.
AHRS m_gyro{frc::SPI::Port::kMXP};
frc::AnalogEncoder m_absoluteEncoder;
frc::AnalogInput m_analogInput;
frc::DigitalInput m_beamBreak{4};
frc::DutyCycleEncoder m_absoluteEncoder{encoder};
We typically use REV SparkMaxes which require the REV vendor libarary and are explained later. However, we have other motor controllers for CIMs and 775 motors. These can be controlled with the original Spark which is included in the base wpilib library.
frc::Spark leftone{0};
Other motor controllers usually come with their respective vendor dependencies.
You'd find that showing various information on the dashboard is pretty useful. Generally, we've used shuffleboard. However, it has its own issues and isn't really being maintained, so we might move to something like Elastic. The code shown below should still work regardless of dashboard type as it just gives the dashboard a label and data to display.
frc::SmartDashboard::PutNumber("leds", m_superstructure.m_vision.getLedOn());
frc::SmartDashboard::PutBoolean("toggle offset", m_drive.getOffsetToggle());
Network tables are WPILib's method of sending data between different applications and over the router to the robot. We've generally used it for getting limelight data, but it can be really powerful if you use the full functionality.
std::shared_ptr<nt::NetworkTable> table;
std::vector<double, std::allocator<double>> table2;
table = nt::NetworkTableInstance::GetDefault().GetTable("limelight");
table2 = nt::NetworkTableInstance::GetDefault().GetTable("limelight")->GetNumberArray("tid", std::vector<double>(6));
nt::NetworkTableInstance::GetDefault().GetTable("limelight")->PutNumber("ledMode", ledOn);
double targetOffsetAngle_Vertical = table->GetNumber("ty", 0.0);
You should probably check the wpilib docs or limelight for their stuff first.
Even though WPILib already provides much of the core functionality needed for every robot, there are certain proprietary features or functions that vendors create themselves.
[insert wpilib training materials from other teams and stuff]