mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Standardize on PWMVictorSPX in examples (#2104)
This commit is contained in:
committed by
Peter Johnson
parent
8c4d9f5415
commit
c0e36df9d8
@@ -30,12 +30,12 @@ class SpeedController;
|
||||
* @code{.cpp}
|
||||
* class Robot {
|
||||
* public:
|
||||
* frc::Spark m_frontLeft{1};
|
||||
* frc::Spark m_rearLeft{2};
|
||||
* frc::PWMVictorSPX m_frontLeft{1};
|
||||
* frc::PWMVictorSPX m_rearLeft{2};
|
||||
* frc::SpeedControllerGroup m_left{m_frontLeft, m_rearLeft};
|
||||
*
|
||||
* frc::Spark m_frontRight{3};
|
||||
* frc::Spark m_rearRight{4};
|
||||
* frc::PWMVictorSPX m_frontRight{3};
|
||||
* frc::PWMVictorSPX m_rearRight{4};
|
||||
* frc::SpeedControllerGroup m_right{m_frontRight, m_rearRight};
|
||||
*
|
||||
* frc::DifferentialDrive m_drive{m_left, m_right};
|
||||
@@ -46,14 +46,14 @@ class SpeedController;
|
||||
* @code{.cpp}
|
||||
* class Robot {
|
||||
* public:
|
||||
* frc::Spark m_frontLeft{1};
|
||||
* frc::Spark m_midLeft{2};
|
||||
* frc::Spark m_rearLeft{3};
|
||||
* frc::PWMVictorSPX m_frontLeft{1};
|
||||
* frc::PWMVictorSPX m_midLeft{2};
|
||||
* frc::PWMVictorSPX m_rearLeft{3};
|
||||
* frc::SpeedControllerGroup m_left{m_frontLeft, m_midLeft, m_rearLeft};
|
||||
*
|
||||
* frc::Spark m_frontRight{4};
|
||||
* frc::Spark m_midRight{5};
|
||||
* frc::Spark m_rearRight{6};
|
||||
* frc::PWMVictorSPX m_frontRight{4};
|
||||
* frc::PWMVictorSPX m_midRight{5};
|
||||
* frc::PWMVictorSPX m_rearRight{6};
|
||||
* frc::SpeedControllerGroup m_right{m_frontRight, m_midRight, m_rearRight};
|
||||
*
|
||||
* frc::DifferentialDrive m_drive{m_left, m_right};
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <frc/AnalogGyro.h>
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/Spark.h>
|
||||
#include <frc/PWMVictorSPX.h>
|
||||
#include <frc/SpeedControllerGroup.h>
|
||||
#include <frc/controller/PIDController.h>
|
||||
#include <frc/kinematics/DifferentialDriveKinematics.h>
|
||||
@@ -57,10 +57,10 @@ class Drivetrain {
|
||||
static constexpr double kWheelRadius = 0.0508; // meters
|
||||
static constexpr int kEncoderResolution = 4096;
|
||||
|
||||
frc::Spark m_leftMaster{1};
|
||||
frc::Spark m_leftFollower{2};
|
||||
frc::Spark m_rightMaster{3};
|
||||
frc::Spark m_rightFollower{4};
|
||||
frc::PWMVictorSPX m_leftMaster{1};
|
||||
frc::PWMVictorSPX m_leftFollower{2};
|
||||
frc::PWMVictorSPX m_rightMaster{3};
|
||||
frc::PWMVictorSPX m_rightFollower{4};
|
||||
|
||||
frc::SpeedControllerGroup m_leftGroup{m_leftMaster, m_leftFollower};
|
||||
frc::SpeedControllerGroup m_rightGroup{m_rightMaster, m_rightFollower};
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <frc/AnalogGyro.h>
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/Spark.h>
|
||||
#include <frc/PWMVictorSPX.h>
|
||||
#include <frc/controller/PIDController.h>
|
||||
#include <frc/geometry/Translation2d.h>
|
||||
#include <frc/kinematics/MecanumDriveKinematics.h>
|
||||
@@ -45,10 +45,10 @@ class Drivetrain {
|
||||
wpi::math::pi}; // 1/2 rotation per second
|
||||
|
||||
private:
|
||||
frc::Spark m_frontLeftMotor{1};
|
||||
frc::Spark m_frontRightMotor{2};
|
||||
frc::Spark m_backLeftMotor{3};
|
||||
frc::Spark m_backRightMotor{4};
|
||||
frc::PWMVictorSPX m_frontLeftMotor{1};
|
||||
frc::PWMVictorSPX m_frontRightMotor{2};
|
||||
frc::PWMVictorSPX m_backLeftMotor{3};
|
||||
frc::PWMVictorSPX m_backRightMotor{4};
|
||||
|
||||
frc::Encoder m_frontLeftEncoder{0, 1};
|
||||
frc::Encoder m_frontRightEncoder{2, 3};
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/Spark.h>
|
||||
#include <frc/PWMVictorSPX.h>
|
||||
#include <frc/controller/PIDController.h>
|
||||
#include <frc/controller/ProfiledPIDController.h>
|
||||
#include <frc/kinematics/SwerveModuleState.h>
|
||||
@@ -34,8 +34,8 @@ class SwerveModule {
|
||||
kModuleMaxAngularAcceleration = units::meters_per_second_squared_t(
|
||||
wpi::math::pi * 2.0); // radians per second squared
|
||||
|
||||
frc::Spark m_driveMotor;
|
||||
frc::Spark m_turningMotor;
|
||||
frc::PWMVictorSPX m_driveMotor;
|
||||
frc::PWMVictorSPX m_turningMotor;
|
||||
|
||||
frc::Encoder m_driveEncoder{0, 1};
|
||||
frc::Encoder m_turningEncoder{2, 3};
|
||||
|
||||
@@ -31,12 +31,12 @@ import edu.wpi.first.wpiutil.math.MathUtils;
|
||||
* <p>Four motor drivetrain:
|
||||
* <pre><code>
|
||||
* public class Robot {
|
||||
* Spark m_frontLeft = new Spark(1);
|
||||
* Spark m_rearLeft = new Spark(2);
|
||||
* SpeedController m_frontLeft = new PWMVictorSPX(1);
|
||||
* SpeedController m_rearLeft = new PWMVictorSPX(2);
|
||||
* SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_rearLeft);
|
||||
*
|
||||
* Spark m_frontRight = new Spark(3);
|
||||
* Spark m_rearRight = new Spark(4);
|
||||
* SpeedController m_frontRight = new PWMVictorSPX(3);
|
||||
* SpeedController m_rearRight = new PWMVictorSPX(4);
|
||||
* SpeedControllerGroup m_right = new SpeedControllerGroup(m_frontRight, m_rearRight);
|
||||
*
|
||||
* DifferentialDrive m_drive = new DifferentialDrive(m_left, m_right);
|
||||
@@ -46,14 +46,14 @@ import edu.wpi.first.wpiutil.math.MathUtils;
|
||||
* <p>Six motor drivetrain:
|
||||
* <pre><code>
|
||||
* public class Robot {
|
||||
* Spark m_frontLeft = new Spark(1);
|
||||
* Spark m_midLeft = new Spark(2);
|
||||
* Spark m_rearLeft = new Spark(3);
|
||||
* SpeedController m_frontLeft = new PWMVictorSPX(1);
|
||||
* SpeedController m_midLeft = new PWMVictorSPX(2);
|
||||
* SpeedController m_rearLeft = new PWMVictorSPX(3);
|
||||
* SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_midLeft, m_rearLeft);
|
||||
*
|
||||
* Spark m_frontRight = new Spark(4);
|
||||
* Spark m_midRight = new Spark(5);
|
||||
* Spark m_rearRight = new Spark(6);
|
||||
* SpeedController m_frontRight = new PWMVictorSPX(4);
|
||||
* SpeedController m_midRight = new PWMVictorSPX(5);
|
||||
* SpeedController m_rearRight = new PWMVictorSPX(6);
|
||||
* SpeedControllerGroup m_right = new SpeedControllerGroup(m_frontRight, m_midRight, m_rearRight);
|
||||
*
|
||||
* DifferentialDrive m_drive = new DifferentialDrive(m_left, m_right);
|
||||
|
||||
@@ -9,7 +9,8 @@ package edu.wpi.first.wpilibj.examples.differentialdrivebot;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogGyro;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Spark;
|
||||
import edu.wpi.first.wpilibj.PWMVictorSPX;
|
||||
import edu.wpi.first.wpilibj.SpeedController;
|
||||
import edu.wpi.first.wpilibj.SpeedControllerGroup;
|
||||
import edu.wpi.first.wpilibj.controller.PIDController;
|
||||
import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
@@ -29,10 +30,10 @@ public class Drivetrain {
|
||||
private static final double kWheelRadius = 0.0508; // meters
|
||||
private static final int kEncoderResolution = 4096;
|
||||
|
||||
private final Spark m_leftMaster = new Spark(1);
|
||||
private final Spark m_leftFollower = new Spark(2);
|
||||
private final Spark m_rightMaster = new Spark(3);
|
||||
private final Spark m_rightFollower = new Spark(4);
|
||||
private final SpeedController m_leftMaster = new PWMVictorSPX(1);
|
||||
private final SpeedController m_leftFollower = new PWMVictorSPX(2);
|
||||
private final SpeedController m_rightMaster = new PWMVictorSPX(3);
|
||||
private final SpeedController m_rightFollower = new PWMVictorSPX(4);
|
||||
|
||||
private final Encoder m_leftEncoder = new Encoder(0, 1);
|
||||
private final Encoder m_rightEncoder = new Encoder(2, 3);
|
||||
|
||||
@@ -9,7 +9,8 @@ package edu.wpi.first.wpilibj.examples.elevatorprofiledpid;
|
||||
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.Spark;
|
||||
import edu.wpi.first.wpilibj.PWMVictorSPX;
|
||||
import edu.wpi.first.wpilibj.SpeedController;
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
|
||||
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
|
||||
@@ -19,7 +20,7 @@ public class Robot extends TimedRobot {
|
||||
|
||||
private final Joystick m_joystick = new Joystick(1);
|
||||
private final Encoder m_encoder = new Encoder(1, 2);
|
||||
private final Spark m_motor = new Spark(1);
|
||||
private final SpeedController m_motor = new PWMVictorSPX(1);
|
||||
|
||||
// Create a PID controller whose setpoint's change is subject to maximum
|
||||
// velocity and acceleration constraints.
|
||||
|
||||
@@ -9,7 +9,8 @@ package edu.wpi.first.wpilibj.examples.elevatortrapezoidprofile;
|
||||
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.Spark;
|
||||
import edu.wpi.first.wpilibj.PWMVictorSPX;
|
||||
import edu.wpi.first.wpilibj.SpeedController;
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
import edu.wpi.first.wpilibj.controller.PIDController;
|
||||
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
|
||||
@@ -19,7 +20,7 @@ public class Robot extends TimedRobot {
|
||||
|
||||
private final Joystick m_joystick = new Joystick(1);
|
||||
private final Encoder m_encoder = new Encoder(1, 2);
|
||||
private final Spark m_motor = new Spark(1);
|
||||
private final SpeedController m_motor = new PWMVictorSPX(1);
|
||||
private final PIDController m_controller = new PIDController(1.3, 0.0, 0.7, kDt);
|
||||
|
||||
private final TrapezoidProfile.Constraints m_constraints =
|
||||
|
||||
@@ -9,7 +9,8 @@ package edu.wpi.first.wpilibj.examples.mecanumbot;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogGyro;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Spark;
|
||||
import edu.wpi.first.wpilibj.PWMVictorSPX;
|
||||
import edu.wpi.first.wpilibj.SpeedController;
|
||||
import edu.wpi.first.wpilibj.controller.PIDController;
|
||||
import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Translation2d;
|
||||
@@ -26,10 +27,10 @@ public class Drivetrain {
|
||||
public static final double kMaxSpeed = 3.0; // 3 meters per second
|
||||
public static final double kMaxAngularSpeed = Math.PI; // 1/2 rotation per second
|
||||
|
||||
private final Spark m_frontLeftMotor = new Spark(1);
|
||||
private final Spark m_frontRightMotor = new Spark(2);
|
||||
private final Spark m_backLeftMotor = new Spark(3);
|
||||
private final Spark m_backRightMotor = new Spark(4);
|
||||
private final SpeedController m_frontLeftMotor = new PWMVictorSPX(1);
|
||||
private final SpeedController m_frontRightMotor = new PWMVictorSPX(2);
|
||||
private final SpeedController m_backLeftMotor = new PWMVictorSPX(3);
|
||||
private final SpeedController m_backRightMotor = new PWMVictorSPX(4);
|
||||
|
||||
private final Encoder m_frontLeftEncoder = new Encoder(0, 1);
|
||||
private final Encoder m_frontRightEncoder = new Encoder(2, 3);
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
package edu.wpi.first.wpilibj.examples.swervebot;
|
||||
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Spark;
|
||||
import edu.wpi.first.wpilibj.PWMVictorSPX;
|
||||
import edu.wpi.first.wpilibj.SpeedController;
|
||||
import edu.wpi.first.wpilibj.controller.PIDController;
|
||||
import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
|
||||
import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
@@ -23,8 +24,8 @@ public class SwerveModule {
|
||||
private static final double kModuleMaxAngularAcceleration
|
||||
= 2 * Math.PI; // radians per second squared
|
||||
|
||||
private final Spark m_driveMotor;
|
||||
private final Spark m_turningMotor;
|
||||
private final SpeedController m_driveMotor;
|
||||
private final SpeedController m_turningMotor;
|
||||
|
||||
private final Encoder m_driveEncoder = new Encoder(0, 1);
|
||||
private final Encoder m_turningEncoder = new Encoder(2, 3);
|
||||
@@ -42,8 +43,8 @@ public class SwerveModule {
|
||||
* @param turningMotorChannel ID for the turning motor.
|
||||
*/
|
||||
public SwerveModule(int driveMotorChannel, int turningMotorChannel) {
|
||||
m_driveMotor = new Spark(driveMotorChannel);
|
||||
m_turningMotor = new Spark(turningMotorChannel);
|
||||
m_driveMotor = new PWMVictorSPX(driveMotorChannel);
|
||||
m_turningMotor = new PWMVictorSPX(turningMotorChannel);
|
||||
|
||||
// Set the distance per pulse for the drive encoder. We can simply use the
|
||||
// distance traveled for one rotation of the wheel divided by the encoder
|
||||
|
||||
Reference in New Issue
Block a user