DeepSpace  2019
DriveTrain.cpp
Go to the documentation of this file.
2 
3 DriveTrain::DriveTrain() : frc::Subsystem("DriveTrain") {
4  // Initialize the motors
5  this->pLeftFrontMotor = new can::WPI_TalonSRX(DRIVETRAIN_LEFT_FRONT_MOTOR);
6  this->pLeftRearMotor = new can::WPI_TalonSRX(DRIVETRAIN_LEFT_REAR_MOTOR);
7  this->pLeftRearMotor->Follow(*pLeftFrontMotor);
8 
9  // this->pLeftFrontMotor->SetInverted(true);
10  // this->pLeftRearMotor->SetInverted(true);
11 
12 
13  this->pRightFrontMotor = new can::WPI_TalonSRX(DRIVETRAIN_RIGHT_FRONT_MOTOR);
14  this->pRightRearMotor = new can::WPI_TalonSRX(DRIVETRAIN_RIGHT_REAR_MOTOR);
15  this->pRightRearMotor->Follow(*pRightFrontMotor);
16 
17  // this->pRightFrontMotor->SetInverted(true); // change this based on test or production robot
18  // this->pRightRearMotor->SetInverted(true); // change this based on test or production robot
19 
20  this->pLeftFrontMotor->SetNeutralMode(NeutralMode::Brake);
21  this->pLeftRearMotor->SetNeutralMode(NeutralMode::Brake);
22 
23  this->pRightFrontMotor->SetNeutralMode(NeutralMode::Brake);
24  this->pRightRearMotor->SetNeutralMode(NeutralMode::Brake);
25 
26  // Create a DifferentialDrive class using our motors
27  this->pRobotDrive = new frc::DifferentialDrive(*pLeftFrontMotor, *pRightFrontMotor);
28 
29  // Disable saftey modes
30  // Sounds like a bad idea, but this prevents the robot from locking up if we take too long on a loop
31  // this->pLeftFrontMotor->SetSafetyEnabled(false);
32  // this->pLeftRearMotor->SetSafetyEnabled(false);
33  // this->pRightFrontMotor->SetSafetyEnabled(false);
34  // this->pRightRearMotor->SetSafetyEnabled(false);
35  this->pRobotDrive->SetSafetyEnabled(false);
36 
37  // Configure encoders
38  this->pLeftFrontMotor->ConfigFactoryDefault();
39  this->pRightFrontMotor->ConfigFactoryDefault();
40 
41  this->pLeftFrontMotor->SetSensorPhase(true);
42  this->pRightFrontMotor->SetSensorPhase(true);
43 
44  // Create the Arcade controller
46 
47 }
48 
50  SetDefaultCommand(new DriveWithJoystick());
51 }
52 
53 void DriveTrain::ArcadeDrive(double xSpeed, double zRotation) {
54  // double speed = this->pArcadeController->Feed(xSpeed, (this->pLeftFrontMotor->GetSelectedSensorVelocity()));
55  this->pRobotDrive->ArcadeDrive(xSpeed, zRotation);
56  return;
57 }
58 
59 void DriveTrain::TankDrive(double leftSpeed, double rightSpeed) {
60  this->pRobotDrive->TankDrive(leftSpeed, rightSpeed);
61  return;
62 }
63 
64 void DriveTrain::RadialDrive(double magnitude, double radial){
65  // set the speeds
66  double leftSpeed, rightSpeed = 0;
67 
68  // asign the right motor speed
69  rightSpeed = magnitude;
70 
71  // Calculate the radial
72  radial += (radial > 1)? 1 : -1;
74 
75  // calculate left speed
76  leftSpeed = rightSpeed * radial;
77 
78  // pass to tankdrive
79  this->pRobotDrive->TankDrive(leftSpeed, rightSpeed);
80  return;
81 }
82 
83 void DriveTrain::RawDrive(double l, double r){
84  this->pLeftFrontMotor->Set(l);
85  this->pRightFrontMotor->Set(r);
86 }
87 
89  this->pLeftFrontMotor->SetNeutralMode(NeutralMode::Coast);
90  this->pLeftRearMotor->SetNeutralMode(NeutralMode::Coast);
91 
92  this->pRightFrontMotor->SetNeutralMode(NeutralMode::Coast);
93  this->pRightRearMotor->SetNeutralMode(NeutralMode::Coast);
94 }
95 
97  this->pLeftFrontMotor->SetNeutralMode(NeutralMode::Brake);
98  this->pLeftRearMotor->SetNeutralMode(NeutralMode::Brake);
99 
100  this->pRightFrontMotor->SetNeutralMode(NeutralMode::Brake);
101  this->pRightRearMotor->SetNeutralMode(NeutralMode::Brake);
102 }
void RadialDrive(double magnitude, double radial)
Definition: DriveTrain.cpp:64
rr::PIDController * pArcadeController
Definition: DriveTrain.h:52
frc::DifferentialDrive * pRobotDrive
Pointer for a differential drivebase made up of 2 motor pairs.
Definition: DriveTrain.h:54
#define ARCADE_KI
Definition: RobotMap.h:39
#define DRIVETRAIN_LEFT_REAR_MOTOR
Definition: RobotMap.h:31
can::WPI_TalonSRX * pRightRearMotor
Pointer for right rear motor.
Definition: DriveTrain.h:50
void RawDrive(double l, double r)
Definition: DriveTrain.cpp:83
#define ARCADE_KP
Definition: RobotMap.h:38
#define DRIVETRAIN_RIGHT_FRONT_MOTOR
Definition: RobotMap.h:32
void ArcadeDrive(double xSpeed, double zRotation)
Definition: DriveTrain.cpp:53
can::WPI_TalonSRX * pLeftRearMotor
Pointer for left rear motor.
Definition: DriveTrain.h:48
#define DRIVEWITHJOYSTICK_ROTATION_LIMITER
Definition: RobotMap.h:103
void TankDrive(double leftSpeed, double rightSpeed)
Definition: DriveTrain.cpp:59
An interface command for driving the robot with an xbox controller.
#define DRIVETRAIN_RIGHT_REAR_MOTOR
Definition: RobotMap.h:33
#define ARCADE_KD
Definition: RobotMap.h:40
can::WPI_TalonSRX * pRightFrontMotor
Pointer for right front motor.
Definition: DriveTrain.h:49
can::WPI_TalonSRX * pLeftFrontMotor
Pointer for left front motor.
Definition: DriveTrain.h:47
DriveTrain()
Class constructor.
Definition: DriveTrain.cpp:3
void InitDefaultCommand() override
Initalizes the default command for this subsystem (DriveWithJoystick)
Definition: DriveTrain.cpp:49
void Coast()
Definition: DriveTrain.cpp:88
#define DRIVETRAIN_RADIAL_SENSITIVITY_CUTOFF
Definition: RobotMap.h:65
void Break()
Definition: DriveTrain.cpp:96
#define DRIVETRAIN_LEFT_FRONT_MOTOR
Definition: RobotMap.h:30