Files
RiseOfRidgebotics2020/src/main/java/frc4388/robot/subsystems/Drive.java
T

112 lines
3.7 KiB
Java
Raw Normal View History

2020-01-09 23:55:46 +00:00
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc4388.robot.subsystems;
import com.ctre.phoenix.motorcontrol.InvertType;
import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
2020-01-09 18:05:16 -07:00
import com.ctre.phoenix.sensors.PigeonIMU;
2020-01-09 23:55:46 +00:00
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
2020-01-10 21:29:45 -07:00
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile.State;
import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
2020-01-09 23:55:46 +00:00
import edu.wpi.first.wpilibj2.command.SubsystemBase;
2020-01-10 21:29:45 -07:00
import edu.wpi.first.wpilibj2.command.ProfiledPIDSubsystem;
2020-01-09 23:55:46 +00:00
import frc4388.robot.Constants.DriveConstants;
/**
* Add your docs here.
*/
2020-01-10 21:29:45 -07:00
public class Drive extends ProfiledPIDSubsystem {
2020-01-09 23:55:46 +00:00
// Put methods for controlling this subsystem
// here. Call these from Commands.
public static WPI_TalonSRX m_leftFrontMotor = new WPI_TalonSRX(DriveConstants.DRIVE_LEFT_FRONT_CAN_ID);
public static WPI_TalonSRX m_rightFrontMotor = new WPI_TalonSRX(DriveConstants.DRIVE_RIGHT_FRONT_CAN_ID);
public static WPI_TalonSRX m_leftBackMotor = new WPI_TalonSRX(DriveConstants.DRIVE_LEFT_BACK_CAN_ID);
public static WPI_TalonSRX m_rightBackMotor = new WPI_TalonSRX(DriveConstants.DRIVE_RIGHT_BACK_CAN_ID);
2020-01-09 18:05:16 -07:00
public static PigeonIMU m_pigeon = new PigeonIMU(DriveConstants.PIGEON_ID);
2020-01-09 23:55:46 +00:00
public static DifferentialDrive m_driveTrain = new DifferentialDrive(m_leftFrontMotor, m_rightFrontMotor);
/**
* Add your docs here.
*/
2020-01-10 21:29:45 -07:00
public Drive() {
/* */
super(new ProfiledPIDController(0, 0, 0, new TrapezoidProfile.Constraints(0, 0)), 0);
2020-01-09 23:55:46 +00:00
/* factory default values */
m_leftFrontMotor.configFactoryDefault();
m_rightFrontMotor.configFactoryDefault();
m_leftBackMotor.configFactoryDefault();
m_rightBackMotor.configFactoryDefault();
2020-01-09 18:05:16 -07:00
m_pigeon.configFactoryDefault();
2020-01-09 23:55:46 +00:00
/* set back motors as followers */
m_leftBackMotor.follow(m_leftFrontMotor);
m_rightBackMotor.follow(m_rightFrontMotor);
/* set neutral mode */
m_leftFrontMotor.setNeutralMode(NeutralMode.Brake);
m_rightFrontMotor.setNeutralMode(NeutralMode.Brake);
m_leftFrontMotor.setNeutralMode(NeutralMode.Brake);
m_rightFrontMotor.setNeutralMode(NeutralMode.Brake);
/* flip input so forward becomes back, etc */
m_leftFrontMotor.setInverted(false);
m_rightFrontMotor.setInverted(false);
m_leftBackMotor.setInverted(InvertType.FollowMaster);
m_rightBackMotor.setInverted(InvertType.FollowMaster);
}
/**
* Add your docs here.
*/
public void driveWithInput(double move, double steer){
m_driveTrain.arcadeDrive(move, steer);
}
2020-01-09 18:05:16 -07:00
public double getGyroYaw() {
double[] ypr = new double[3];
m_pigeon.getYawPitchRoll(ypr);
return ypr[0];
}
public double getGyroPitch() {
double[] ypr = new double[3];
m_pigeon.getYawPitchRoll(ypr);
return ypr[1];
}
2020-01-10 21:29:45 -07:00
2020-01-09 18:05:16 -07:00
public double getGyroRoll() {
double[] ypr = new double[3];
m_pigeon.getYawPitchRoll(ypr);
return ypr[2];
}
public void resetGyroYaw() {
m_pigeon.setYaw(0);
m_pigeon.setAccumZAngle(0);
}
2020-01-10 21:29:45 -07:00
@Override
protected void useOutput(double output, TrapezoidProfile.State setpoint) {
// TODO Auto-generated method stub
}
@Override
protected double getMeasurement() {
// TODO Auto-generated method stub
return 0;
}
2020-01-09 23:55:46 +00:00
}