Files
allwpilib/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h

85 lines
2.2 KiB
C
Raw Normal View History

/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc/AnalogGyro.h>
#include <frc/AnalogInput.h>
#include <frc/Encoder.h>
#include <frc/Spark.h>
#include <frc/SpeedControllerGroup.h>
#include <frc/commands/Subsystem.h>
#include <frc/drive/DifferentialDrive.h>
namespace frc {
class Joystick;
2017-10-26 19:28:59 -07:00
} // namespace frc
/**
* 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();
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;
2018-05-13 17:09:56 -07:00
/**
* The log method puts interesting information to the SmartDashboard.
*/
void Log();
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);
2018-05-13 17:09:56 -07:00
/**
* @return The robots heading in degrees.
*/
double GetHeading();
2018-05-13 17:09:56 -07:00
/**
* Reset the robots sensors to the zero states.
*/
void Reset();
2018-05-13 17:09:56 -07:00
/**
* @return The distance driven (average of left and right encoders).
*/
double GetDistance();
2018-05-13 17:09:56 -07:00
/**
* @return The distance to the obstacle detected by the rangefinder.
*/
double GetDistanceToObstacle();
2018-05-13 17:09:56 -07:00
private:
frc::Spark m_frontLeft{1};
frc::Spark m_rearLeft{2};
frc::SpeedControllerGroup m_left{m_frontLeft, m_rearLeft};
2017-11-03 13:22:56 -07:00
2018-05-13 17:09:56 -07:00
frc::Spark m_frontRight{3};
frc::Spark m_rearRight{4};
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};
};