Auto-generate packet dataclasses with Jinja (#1374)

This commit is contained in:
Matt
2024-08-31 13:44:19 -04:00
committed by GitHub
parent c19d54c633
commit 169595e56e
140 changed files with 4445 additions and 2097 deletions

View File

@@ -26,6 +26,22 @@
#include <photon/PhotonUtils.h>
#include <frc/Timer.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include <units/time.h>
void Robot::RobotPeriodic() {
photon::PhotonCamera::SetVersionCheckEnabled(false);
auto start = frc::Timer::GetFPGATimestamp();
photon::PhotonPipelineResult result = camera.GetLatestResult();
auto end = frc::Timer::GetFPGATimestamp();
std::printf("DT is %.2f uS for %i targets\n",
units::microsecond_t(end - start).to<double>(),
result.GetTargets().size());
}
void Robot::TeleopPeriodic() {
double forwardSpeed = -xboxController.GetRightY();
double rotationSpeed;
@@ -33,7 +49,10 @@ void Robot::TeleopPeriodic() {
if (xboxController.GetAButton()) {
// Vision-alignment mode
// Query the latest result from PhotonVision
auto start = frc::Timer::GetFPGATimestamp();
photon::PhotonPipelineResult result = camera.GetLatestResult();
auto end = frc::Timer::GetFPGATimestamp();
frc::SmartDashboard::PutNumber("decode_dt", (end - start).to<double>());
if (result.HasTargets()) {
// Rotation speed is the output of the PID controller

View File

@@ -37,10 +37,11 @@
class Robot : public frc::TimedRobot {
public:
void TeleopPeriodic() override;
void RobotPeriodic() override;
private:
// Change this to match the name of your camera as shown in the web UI
photon::PhotonCamera camera{"YOUR_CAMERA_NAME_HERE"};
photon::PhotonCamera camera{"WPI2024"};
// PID constants should be tuned per robot
frc::PIDController controller{.1, 0, 0};