2017-10-17 21:37:58 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
2017-10-17 21:37:58 -07:00
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <frc/AnalogGyro.h>
|
|
|
|
|
#include <frc/AnalogInput.h>
|
|
|
|
|
#include <frc/Encoder.h>
|
2018-12-31 13:45:09 -08:00
|
|
|
#include <frc/PWMVictorSPX.h>
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <frc/SpeedControllerGroup.h>
|
|
|
|
|
#include <frc/commands/Subsystem.h>
|
|
|
|
|
#include <frc/drive/DifferentialDrive.h>
|
2017-10-17 21:37:58 -07:00
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
class Joystick;
|
2017-10-26 19:28:59 -07:00
|
|
|
} // namespace frc
|
2017-10-17 21:37:58 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The DriveTrain subsystem incorporates the sensors and actuators attached to
|
|
|
|
|
* the robots chassis. These include four drive motors, a left and right encoder
|
|
|
|
|
* and a gyro.
|
|
|
|
|
*/
|
|
|
|
|
class DriveTrain : public frc::Subsystem {
|
2018-05-13 17:09:56 -07:00
|
|
|
public:
|
|
|
|
|
DriveTrain();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* When no other command is running let the operator drive around
|
|
|
|
|
* using the PS3 joystick.
|
|
|
|
|
*/
|
|
|
|
|
void InitDefaultCommand() override;
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* The log method puts interesting information to the SmartDashboard.
|
|
|
|
|
*/
|
|
|
|
|
void Log();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* Tank style driving for the DriveTrain.
|
|
|
|
|
* @param left Speed in range [-1,1]
|
|
|
|
|
* @param right Speed in range [-1,1]
|
|
|
|
|
*/
|
|
|
|
|
void Drive(double left, double right);
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* @return The robots heading in degrees.
|
|
|
|
|
*/
|
|
|
|
|
double GetHeading();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* Reset the robots sensors to the zero states.
|
|
|
|
|
*/
|
|
|
|
|
void Reset();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* @return The distance driven (average of left and right encoders).
|
|
|
|
|
*/
|
|
|
|
|
double GetDistance();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* @return The distance to the obstacle detected by the rangefinder.
|
|
|
|
|
*/
|
|
|
|
|
double GetDistanceToObstacle();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
private:
|
2018-12-31 13:45:09 -08:00
|
|
|
frc::PWMVictorSPX m_frontLeft{1};
|
|
|
|
|
frc::PWMVictorSPX m_rearLeft{2};
|
2018-05-13 17:09:56 -07:00
|
|
|
frc::SpeedControllerGroup m_left{m_frontLeft, m_rearLeft};
|
2017-11-03 13:22:56 -07:00
|
|
|
|
2018-12-31 13:45:09 -08:00
|
|
|
frc::PWMVictorSPX m_frontRight{3};
|
|
|
|
|
frc::PWMVictorSPX m_rearRight{4};
|
2018-05-13 17:09:56 -07:00
|
|
|
frc::SpeedControllerGroup m_right{m_frontRight, m_rearRight};
|
2017-11-03 13:22:56 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
frc::DifferentialDrive m_robotDrive{m_left, m_right};
|
2017-11-03 13:22:56 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
frc::Encoder m_leftEncoder{1, 2};
|
|
|
|
|
frc::Encoder m_rightEncoder{3, 4};
|
|
|
|
|
frc::AnalogInput m_rangefinder{6};
|
|
|
|
|
frc::AnalogGyro m_gyro{1};
|
2017-10-17 21:37:58 -07:00
|
|
|
};
|