mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-24 01:31:44 +00:00
Upgrade to Gradle 7.2 and WPILib 2022 (#316)
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest;
|
||||
|
||||
import edu.wpi.first.wpilibj.RobotBase;
|
||||
|
||||
@@ -14,17 +14,16 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest.robot;
|
||||
|
||||
import edu.wpi.first.math.controller.RamseteController;
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import edu.wpi.first.math.geometry.Rotation2d;
|
||||
import edu.wpi.first.math.kinematics.ChassisSpeeds;
|
||||
import edu.wpi.first.math.trajectory.Trajectory;
|
||||
import edu.wpi.first.math.trajectory.TrajectoryConfig;
|
||||
import edu.wpi.first.math.trajectory.TrajectoryGenerator;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.controller.RamseteController;
|
||||
import edu.wpi.first.wpilibj.geometry.Pose2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds;
|
||||
import edu.wpi.first.wpilibj.trajectory.Trajectory;
|
||||
import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig;
|
||||
import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -34,7 +33,6 @@ import java.util.List;
|
||||
* thinks it ought to be.
|
||||
*/
|
||||
public class AutoController {
|
||||
|
||||
private Trajectory trajectory;
|
||||
|
||||
private RamseteController ramsete = new RamseteController();
|
||||
@@ -46,7 +44,6 @@ public class AutoController {
|
||||
Trajectory.State desiredDtState;
|
||||
|
||||
public AutoController() {
|
||||
|
||||
// Change this trajectory if you need the robot to follow different paths.
|
||||
trajectory =
|
||||
TrajectoryGenerator.generateTrajectory(
|
||||
@@ -83,7 +80,6 @@ public class AutoController {
|
||||
* @return The commanded drivetrain motion
|
||||
*/
|
||||
public ChassisSpeeds getCurMotorCmds(Pose2d curEstPose) {
|
||||
|
||||
if (isRunning) {
|
||||
double elapsed = timer.get();
|
||||
desiredDtState = trajectory.sample(elapsed);
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest.robot;
|
||||
|
||||
import edu.wpi.first.wpilibj.geometry.Pose2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Transform2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Translation2d;
|
||||
import edu.wpi.first.wpilibj.util.Units;
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import edu.wpi.first.math.geometry.Rotation2d;
|
||||
import edu.wpi.first.math.geometry.Transform2d;
|
||||
import edu.wpi.first.math.geometry.Translation2d;
|
||||
import edu.wpi.first.math.util.Units;
|
||||
import org.photonvision.SimVisionTarget;
|
||||
|
||||
/**
|
||||
@@ -31,7 +30,6 @@ import org.photonvision.SimVisionTarget;
|
||||
* at the field drawings 3) Match with how your vision coprocessor is configured.
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Drivetrain Physical
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -14,18 +14,17 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest.robot;
|
||||
|
||||
import edu.wpi.first.math.controller.PIDController;
|
||||
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import edu.wpi.first.math.kinematics.ChassisSpeeds;
|
||||
import edu.wpi.first.math.kinematics.DifferentialDriveKinematics;
|
||||
import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.PWMVictorSPX;
|
||||
import edu.wpi.first.wpilibj.SpeedControllerGroup;
|
||||
import edu.wpi.first.wpilibj.controller.PIDController;
|
||||
import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward;
|
||||
import edu.wpi.first.wpilibj.geometry.Pose2d;
|
||||
import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds;
|
||||
import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics;
|
||||
import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX;
|
||||
|
||||
/**
|
||||
* Implements a controller for the drivetrain. Converts a set of chassis motion commands into motor
|
||||
@@ -33,15 +32,14 @@ import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds;
|
||||
* speed.
|
||||
*/
|
||||
public class Drivetrain {
|
||||
|
||||
// PWM motor controller output definitions
|
||||
PWMVictorSPX leftLeader = new PWMVictorSPX(Constants.kDtLeftLeaderPin);
|
||||
PWMVictorSPX leftFollower = new PWMVictorSPX(Constants.kDtLeftFollowerPin);
|
||||
PWMVictorSPX rightLeader = new PWMVictorSPX(Constants.kDtRightLeaderPin);
|
||||
PWMVictorSPX rightFollower = new PWMVictorSPX(Constants.kDtRightFollowerPin);
|
||||
|
||||
SpeedControllerGroup leftGroup = new SpeedControllerGroup(leftLeader, leftFollower);
|
||||
SpeedControllerGroup rightGroup = new SpeedControllerGroup(rightLeader, rightFollower);
|
||||
MotorControllerGroup leftGroup = new MotorControllerGroup(leftLeader, leftFollower);
|
||||
MotorControllerGroup rightGroup = new MotorControllerGroup(rightLeader, rightFollower);
|
||||
|
||||
// Drivetrain wheel speed sensors
|
||||
// Used both for speed control and pose estimation.
|
||||
|
||||
@@ -14,21 +14,20 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest.robot;
|
||||
|
||||
import edu.wpi.first.math.Matrix;
|
||||
import edu.wpi.first.math.VecBuilder;
|
||||
import edu.wpi.first.math.estimator.DifferentialDrivePoseEstimator;
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import edu.wpi.first.math.geometry.Transform2d;
|
||||
import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds;
|
||||
import edu.wpi.first.math.numbers.N1;
|
||||
import edu.wpi.first.math.numbers.N3;
|
||||
import edu.wpi.first.math.numbers.N5;
|
||||
import edu.wpi.first.math.util.Units;
|
||||
import edu.wpi.first.wpilibj.AnalogGyro;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.estimator.DifferentialDrivePoseEstimator;
|
||||
import edu.wpi.first.wpilibj.geometry.Pose2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Transform2d;
|
||||
import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds;
|
||||
import edu.wpi.first.wpilibj.util.Units;
|
||||
import edu.wpi.first.wpiutil.math.Matrix;
|
||||
import edu.wpi.first.wpiutil.math.VecBuilder;
|
||||
import edu.wpi.first.wpiutil.math.numbers.N1;
|
||||
import edu.wpi.first.wpiutil.math.numbers.N3;
|
||||
import edu.wpi.first.wpiutil.math.numbers.N5;
|
||||
import org.photonvision.PhotonCamera;
|
||||
|
||||
/**
|
||||
@@ -37,7 +36,6 @@ import org.photonvision.PhotonCamera;
|
||||
* filter. This in turn creates a best-guess at a Pose2d of where our drivetrain is currently at.
|
||||
*/
|
||||
public class DrivetrainPoseEstimator {
|
||||
|
||||
// Sensors used as part of the Pose Estimation
|
||||
private final AnalogGyro gyro = new AnalogGyro(Constants.kGyroPin);
|
||||
private PhotonCamera cam = new PhotonCamera(Constants.kCamName);
|
||||
@@ -75,7 +73,6 @@ public class DrivetrainPoseEstimator {
|
||||
*/
|
||||
public void update(
|
||||
DifferentialDriveWheelSpeeds actWheelSpeeds, double leftDist, double rightDist) {
|
||||
|
||||
m_poseEstimator.update(gyro.getRotation2d(), actWheelSpeeds, leftDist, rightDist);
|
||||
|
||||
var res = cam.getLatestResult();
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest.robot;
|
||||
|
||||
import edu.wpi.first.wpilibj.GenericHID;
|
||||
import edu.wpi.first.wpilibj.SlewRateLimiter;
|
||||
import edu.wpi.first.math.filter.SlewRateLimiter;
|
||||
import edu.wpi.first.wpilibj.XboxController;
|
||||
|
||||
public class OperatorInterface {
|
||||
@@ -34,7 +32,7 @@ public class OperatorInterface {
|
||||
public double getFwdRevSpdCmd() {
|
||||
// Get the x speed. We are inverting this because Xbox controllers return
|
||||
// negative values when we push forward.
|
||||
return -speedLimiter.calculate(opCtrl.getY(GenericHID.Hand.kLeft)) * Constants.kMaxSpeed;
|
||||
return -speedLimiter.calculate(opCtrl.getLeftY()) * Constants.kMaxSpeed;
|
||||
}
|
||||
|
||||
public double getRotateSpdCmd() {
|
||||
@@ -42,7 +40,7 @@ public class OperatorInterface {
|
||||
// positive value when we pull to the left (remember, CCW is positive in
|
||||
// mathematics). Xbox controllers return positive values when you pull to
|
||||
// the right by default.
|
||||
return -rotLimiter.calculate(opCtrl.getX(GenericHID.Hand.kRight)) * Constants.kMaxAngularSpeed;
|
||||
return -rotLimiter.calculate(opCtrl.getRightX()) * Constants.kMaxAngularSpeed;
|
||||
}
|
||||
|
||||
public boolean getSimKickCmd() {
|
||||
|
||||
@@ -14,16 +14,14 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest.robot;
|
||||
|
||||
import edu.wpi.first.wpilibj.geometry.Pose2d;
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.Field2d;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
/** Reports our expected, desired, and actual poses to dashboards */
|
||||
public class PoseTelemetry {
|
||||
|
||||
Field2d field = new Field2d();
|
||||
|
||||
Pose2d actPose = new Pose2d();
|
||||
|
||||
@@ -14,16 +14,14 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest.robot;
|
||||
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import edu.wpi.first.math.kinematics.ChassisSpeeds;
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
import edu.wpi.first.wpilibj.geometry.Pose2d;
|
||||
import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds;
|
||||
import org.photonlib.examples.simposeest.sim.DrivetrainSim;
|
||||
|
||||
public class Robot extends TimedRobot {
|
||||
|
||||
AutoController autoCtrl = new AutoController();
|
||||
Drivetrain dt = new Drivetrain();
|
||||
OperatorInterface opInf = new OperatorInterface();
|
||||
|
||||
@@ -14,23 +14,22 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonlib.examples.simposeest.sim;
|
||||
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import edu.wpi.first.math.geometry.Rotation2d;
|
||||
import edu.wpi.first.math.geometry.Transform2d;
|
||||
import edu.wpi.first.math.geometry.Translation2d;
|
||||
import edu.wpi.first.math.numbers.N2;
|
||||
import edu.wpi.first.math.system.LinearSystem;
|
||||
import edu.wpi.first.math.system.plant.DCMotor;
|
||||
import edu.wpi.first.math.system.plant.LinearSystemId;
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
import edu.wpi.first.wpilibj.RobotController;
|
||||
import edu.wpi.first.wpilibj.geometry.Pose2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Transform2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Translation2d;
|
||||
import edu.wpi.first.wpilibj.simulation.AnalogGyroSim;
|
||||
import edu.wpi.first.wpilibj.simulation.DifferentialDrivetrainSim;
|
||||
import edu.wpi.first.wpilibj.simulation.EncoderSim;
|
||||
import edu.wpi.first.wpilibj.simulation.PWMSim;
|
||||
import edu.wpi.first.wpilibj.system.LinearSystem;
|
||||
import edu.wpi.first.wpilibj.system.plant.DCMotor;
|
||||
import edu.wpi.first.wpilibj.system.plant.LinearSystemId;
|
||||
import edu.wpi.first.wpiutil.math.numbers.N2;
|
||||
import org.photonlib.examples.simposeest.robot.Constants;
|
||||
import org.photonvision.SimVisionSystem;
|
||||
|
||||
@@ -42,7 +41,6 @@ import org.photonvision.SimVisionSystem;
|
||||
* real motors/sensors/physics are used instead.
|
||||
*/
|
||||
public class DrivetrainSim {
|
||||
|
||||
// Simulated Sensors
|
||||
AnalogGyroSim gyroSim = new AnalogGyroSim(Constants.kGyroPin);
|
||||
EncoderSim leftEncoderSim = EncoderSim.createForChannel(Constants.kDtLeftEncoderPinA);
|
||||
@@ -100,11 +98,10 @@ public class DrivetrainSim {
|
||||
* physics forward by a single 20ms step.
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
double leftMotorCmd = 0;
|
||||
double rightMotorCmd = 0;
|
||||
|
||||
if (DriverStation.getInstance().isEnabled() && !RobotController.isBrownedOut()) {
|
||||
if (DriverStation.isEnabled() && !RobotController.isBrownedOut()) {
|
||||
// If the motor controllers are enabled...
|
||||
// Roughly model the effect of leader and follower motor pushing on the same
|
||||
// gearbox.
|
||||
|
||||
Reference in New Issue
Block a user