2023-10-09 19:55:54 -04: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.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/hardware/rotation/Encoder.hpp"
|
|
|
|
|
#include "wpi/drive/DifferentialDrive.hpp"
|
|
|
|
|
#include "wpi/xrp/XRPGyro.hpp"
|
|
|
|
|
#include "wpi/xrp/XRPMotor.hpp"
|
|
|
|
|
#include "wpi/commands2/SubsystemBase.hpp"
|
|
|
|
|
#include "wpi/units/acceleration.hpp"
|
|
|
|
|
#include "wpi/units/angle.hpp"
|
|
|
|
|
#include "wpi/units/length.hpp"
|
2023-10-09 19:55:54 -04:00
|
|
|
|
|
|
|
|
class Drivetrain : public frc2::SubsystemBase {
|
|
|
|
|
public:
|
|
|
|
|
static constexpr double kGearRatio =
|
|
|
|
|
(30.0 / 14.0) * (28.0 / 16.0) * (36.0 / 9.0) * (26.0 / 8.0); // 48.75:1
|
|
|
|
|
static constexpr double kCountsPerMotorShaftRev = 12.0;
|
|
|
|
|
static constexpr double kCountsPerRevolution =
|
|
|
|
|
kCountsPerMotorShaftRev * kGearRatio; // 585.0
|
|
|
|
|
static constexpr units::meter_t kWheelDiameter = 60_mm;
|
|
|
|
|
|
|
|
|
|
Drivetrain();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Will be called periodically whenever the CommandScheduler runs.
|
|
|
|
|
*/
|
|
|
|
|
void Periodic() override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Drives the robot using arcade controls.
|
|
|
|
|
*
|
|
|
|
|
* @param xaxisSpeed the commanded forward movement
|
|
|
|
|
* @param zaxisRotate the commanded rotation
|
|
|
|
|
*/
|
|
|
|
|
void ArcadeDrive(double xaxisSpeed, double zaxisRotate);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resets the drive encoders to currently read a position of 0.
|
|
|
|
|
*/
|
|
|
|
|
void ResetEncoders();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the left drive encoder count.
|
|
|
|
|
*
|
|
|
|
|
* @return the left drive encoder count
|
|
|
|
|
*/
|
|
|
|
|
int GetLeftEncoderCount();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the right drive encoder count.
|
|
|
|
|
*
|
|
|
|
|
* @return the right drive encoder count
|
|
|
|
|
*/
|
|
|
|
|
int GetRightEncoderCount();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the left distance driven.
|
|
|
|
|
*
|
|
|
|
|
* @return the left-side distance driven
|
|
|
|
|
*/
|
|
|
|
|
units::meter_t GetLeftDistance();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the right distance driven.
|
|
|
|
|
*
|
|
|
|
|
* @return the right-side distance driven
|
|
|
|
|
*/
|
|
|
|
|
units::meter_t GetRightDistance();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the average distance traveled by the left and right encoders.
|
|
|
|
|
*
|
|
|
|
|
* @return The average distance traveled by the left and right encoders.
|
|
|
|
|
*/
|
|
|
|
|
units::meter_t GetAverageDistance();
|
|
|
|
|
|
|
|
|
|
/**
|
2024-11-16 10:24:21 -05:00
|
|
|
* Current angle of the XRP around the X-axis.
|
|
|
|
|
*
|
|
|
|
|
* @return The current angle of the XRP.
|
2023-10-09 19:55:54 -04:00
|
|
|
*/
|
2024-11-08 23:24:13 -05:00
|
|
|
units::radian_t GetGyroAngleX();
|
2023-10-09 19:55:54 -04:00
|
|
|
|
|
|
|
|
/**
|
2024-11-16 10:24:21 -05:00
|
|
|
* Current angle of the XRP around the Y-axis.
|
|
|
|
|
*
|
|
|
|
|
* @return The current angle of the XRP.
|
2023-10-09 19:55:54 -04:00
|
|
|
*/
|
2024-11-08 23:24:13 -05:00
|
|
|
units::radian_t GetGyroAngleY();
|
2023-10-09 19:55:54 -04:00
|
|
|
|
|
|
|
|
/**
|
2024-11-16 10:24:21 -05:00
|
|
|
* Current angle of the XRP around the Z-axis.
|
|
|
|
|
*
|
|
|
|
|
* @return The current angle of the XRP.
|
2023-10-09 19:55:54 -04:00
|
|
|
*/
|
2024-11-08 23:24:13 -05:00
|
|
|
units::radian_t GetGyroAngleZ();
|
2023-10-09 19:55:54 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset the gyro.
|
|
|
|
|
*/
|
|
|
|
|
void ResetGyro();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
frc::XRPMotor m_leftMotor{0};
|
|
|
|
|
frc::XRPMotor m_rightMotor{1};
|
|
|
|
|
|
|
|
|
|
frc::Encoder m_leftEncoder{4, 5};
|
|
|
|
|
frc::Encoder m_rightEncoder{6, 7};
|
|
|
|
|
|
2024-01-01 13:37:51 -08:00
|
|
|
frc::DifferentialDrive m_drive{
|
|
|
|
|
[&](double output) { m_leftMotor.Set(output); },
|
|
|
|
|
[&](double output) { m_rightMotor.Set(output); }};
|
2023-10-09 19:55:54 -04:00
|
|
|
|
|
|
|
|
frc::XRPGyro m_gyro;
|
|
|
|
|
};
|