mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
Upgrade to Gradle 7.2 and WPILib 2022 (#316)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020 Photon Vision.
|
||||
/*
|
||||
* Copyright (C) Photon Vision.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -26,24 +26,24 @@ void Robot::TeleopPeriodic() {
|
||||
if (xboxController.GetAButton()) {
|
||||
// Vision-alignment mode
|
||||
// Query the latest result from PhotonVision
|
||||
const auto &result = camera.GetLatestResult();
|
||||
const auto& result = camera.GetLatestResult();
|
||||
|
||||
if (result.HasTargets()) {
|
||||
// First calculate range
|
||||
units::meter_t range =
|
||||
photonlib::PhotonUtils::CalculateDistanceToTarget(
|
||||
CAMERA_HEIGHT, TARGET_HEIGHT, CAMERA_PITCH,
|
||||
units::degree_t{result.GetBestTarget().GetPitch()});
|
||||
units::meter_t range = photonlib::PhotonUtils::CalculateDistanceToTarget(
|
||||
CAMERA_HEIGHT, TARGET_HEIGHT, CAMERA_PITCH,
|
||||
units::degree_t{result.GetBestTarget().GetPitch()});
|
||||
|
||||
// Use this range as the measurement we give to the PID controller.
|
||||
// -1.0 required to ensure positive PID controller effort _increases_ range
|
||||
forwardSpeed = -1.0* forwardController.Calculate(
|
||||
range.to<double>(), GOAL_RANGE_METERS.to<double>());
|
||||
// -1.0 required to ensure positive PID controller effort _increases_
|
||||
// range
|
||||
forwardSpeed = -forwardController.Calculate(range.value(),
|
||||
GOAL_RANGE_METERS.value());
|
||||
|
||||
// Also calculate angular power
|
||||
// -1.0 required to ensure positive PID controller effort _increases_ yaw
|
||||
rotationSpeed = -1.0 * turnController.Calculate(
|
||||
result.GetBestTarget().GetYaw(), 0);
|
||||
rotationSpeed =
|
||||
-turnController.Calculate(result.GetBestTarget().GetYaw(), 0);
|
||||
} else {
|
||||
// If we have no targets, stay still.
|
||||
forwardSpeed = 0;
|
||||
@@ -51,10 +51,8 @@ void Robot::TeleopPeriodic() {
|
||||
}
|
||||
} else {
|
||||
// Manual Driver Mode
|
||||
forwardSpeed =
|
||||
-1.0 * xboxController.GetY(frc::GenericHID::JoystickHand::kRightHand);
|
||||
rotationSpeed =
|
||||
xboxController.GetX(frc::GenericHID::JoystickHand::kLeftHand);
|
||||
forwardSpeed = -xboxController.GetRightY();
|
||||
rotationSpeed = xboxController.GetLeftX();
|
||||
}
|
||||
|
||||
// Use our forward/turn speeds to control the drivetrain
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020 Photon Vision.
|
||||
/*
|
||||
* Copyright (C) Photon Vision.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,19 +19,19 @@
|
||||
|
||||
#include <photonlib/PhotonCamera.h>
|
||||
|
||||
#include <frc/PWMVictorSPX.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/XboxController.h>
|
||||
#include <frc/controller/PIDController.h>
|
||||
#include <frc/drive/DifferentialDrive.h>
|
||||
#include <frc/motorcontrol/PWMVictorSPX.h>
|
||||
#include <units/angle.h>
|
||||
#include <units/length.h>
|
||||
|
||||
class Robot : public frc::TimedRobot {
|
||||
public:
|
||||
public:
|
||||
void TeleopPeriodic() override;
|
||||
|
||||
private:
|
||||
private:
|
||||
// Constants such as camera and target height stored. Change per robot and
|
||||
// goal!
|
||||
const units::meter_t CAMERA_HEIGHT = 24_in;
|
||||
|
||||
Reference in New Issue
Block a user