2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-11-21 23:55:16 -05:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <frc/Encoder.h>
|
|
|
|
|
#include <frc/drive/DifferentialDrive.h>
|
2021-04-17 11:27:16 -07:00
|
|
|
#include <frc/motorcontrol/MotorControllerGroup.h>
|
|
|
|
|
#include <frc/motorcontrol/PWMSparkMax.h>
|
2023-07-14 01:12:01 -04:00
|
|
|
#include <frc2/command/Subsystem.h>
|
2019-11-21 23:55:16 -05:00
|
|
|
|
|
|
|
|
#include "Constants.h"
|
|
|
|
|
|
2023-07-14 01:12:01 -04:00
|
|
|
class DriveSubsystem : public frc2::Subsystem {
|
2019-11-21 23:55:16 -05:00
|
|
|
public:
|
|
|
|
|
DriveSubsystem();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Will be called periodically whenever the CommandScheduler runs.
|
|
|
|
|
*/
|
|
|
|
|
void Periodic() override;
|
|
|
|
|
|
|
|
|
|
// Subsystem methods go here.
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Drives the robot using arcade controls.
|
|
|
|
|
*
|
|
|
|
|
* @param fwd the commanded forward movement
|
|
|
|
|
* @param rot the commanded rotation
|
|
|
|
|
*/
|
|
|
|
|
void ArcadeDrive(double fwd, double rot);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resets the drive encoders to currently read a position of 0.
|
|
|
|
|
*/
|
|
|
|
|
void ResetEncoders();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the average distance of the TWO encoders.
|
|
|
|
|
*
|
|
|
|
|
* @return the average of the TWO encoder readings
|
|
|
|
|
*/
|
|
|
|
|
double GetAverageEncoderDistance();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the left drive encoder.
|
|
|
|
|
*
|
|
|
|
|
* @return the left drive encoder
|
|
|
|
|
*/
|
|
|
|
|
frc::Encoder& GetLeftEncoder();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the right drive encoder.
|
|
|
|
|
*
|
|
|
|
|
* @return the right drive encoder
|
|
|
|
|
*/
|
|
|
|
|
frc::Encoder& GetRightEncoder();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the max output of the drive. Useful for scaling the drive to drive
|
|
|
|
|
* more slowly.
|
|
|
|
|
*
|
|
|
|
|
* @param maxOutput the maximum output to which the drive will be constrained
|
|
|
|
|
*/
|
|
|
|
|
void SetMaxOutput(double maxOutput);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Components (e.g. motor controllers and sensors) should generally be
|
|
|
|
|
// declared private and exposed only through public methods.
|
|
|
|
|
|
|
|
|
|
// The motor controllers
|
2021-02-13 01:14:56 -05:00
|
|
|
frc::PWMSparkMax m_left1;
|
|
|
|
|
frc::PWMSparkMax m_left2;
|
|
|
|
|
frc::PWMSparkMax m_right1;
|
|
|
|
|
frc::PWMSparkMax m_right2;
|
2019-11-21 23:55:16 -05:00
|
|
|
|
|
|
|
|
// The motors on the left side of the drive
|
2021-04-17 11:27:16 -07:00
|
|
|
frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
|
2019-11-21 23:55:16 -05:00
|
|
|
|
|
|
|
|
// The motors on the right side of the drive
|
2021-04-17 11:27:16 -07:00
|
|
|
frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
|
2019-11-21 23:55:16 -05:00
|
|
|
|
|
|
|
|
// The robot's drive
|
|
|
|
|
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
|
|
|
|
|
|
|
|
|
|
// The left-side drive encoder
|
|
|
|
|
frc::Encoder m_leftEncoder;
|
|
|
|
|
|
|
|
|
|
// The right-side drive encoder
|
|
|
|
|
frc::Encoder m_rightEncoder;
|
|
|
|
|
};
|