DeepSpace  2019
DriveWithJoystick.cpp
Go to the documentation of this file.
2 #include "Robot.h"
3 
5  // Use Requires() here to declare subsystem dependencies
6  Requires(Robot::m_DriveTrain);
8 }
9 
10 // Called just before this Command runs the first time
11 // aka: every time teleop is enabled
13  // Set magnitude and direction multipliers
14  this->directionMultiplier = 1;
15  this->magnitudeMultiplier = 1;
16 
17  //set magnitude and radial
18  this->magnitude = 0.0;
19  this->radial = 0.0;
20 
21  //driverMenu selection
22  //To use driverMenu, hold a selection button while enabling teleop
23 
24  // Make sure that driveMode is reset each time the bot is enabled
25  // This must be in the Initalize() function, not in the header file
26  this->driveMode = 0;
27 
28  // If X held during teleop enable, use triggerdrive
29  if(this->pJoyDrive->GetYButton()){
30  this->driveMode = 1;
31  }
32 }
33 
35  // magnitude = Right trigger - left trigger
36  this->magnitude = (this->pJoyDrive->GetTriggerAxis(Hand::kRightHand) - this->pJoyDrive->GetTriggerAxis(Hand::kLeftHand));
37 
38  // needed for use in an and statement
39  return true;
40 }
41 
42 // Called repeatedly when this Command is scheduled to run
44  // Deal with reversing and slow mode
45  this->directionMultiplier = (this->pJoyDrive->GetXButtonReleased())? -1 : 1;
46  this->magnitudeMultiplier = (this->pJoyDrive->GetBumper(Hand::kRightHand)) ? 0.5 : 1;
47 
48  // Get movement data form controller
49  this->magnitude = this->pJoyDrive->GetY(Hand::kLeftHand) * -1;
50  this->radial = this->pJoyDrive->GetX(Hand::kLeftHand);
51 
52  // If trigger drive mode was enabled during teleop-init, override magnitude with trigger data
53  // This will only ever be called if a select few people are driving the bot.
54  // It should be as insignifigant as possible when the bot is in normal operation (3 instructions)
55  this->driveMode == 1 && this->getTriggers();
56 
57  // Multiply each value with it's multiplier(s)
58  this->magnitude *= (this->magnitudeMultiplier * this->directionMultiplier);
59  this->radial *= (this->magnitudeMultiplier);// * DRIVEWITHJOYSTICK_ROTATION_LIMITER);
60 
62 
63  // Reset the magnitude and radial
64  // while this does have some negitive side effects while driving,
65  // It is for saftey. (and so we don't have a run-away bot slam into a wall again)
66  this->magnitude = 0.00;
67  this->radial = 0.00;
68 }
69 
70 
71 bool DriveWithJoystick::IsFinished() { return false; }
72 
73 // Called once after isFinished returns true
75 
76 // Called when another command which requires one or more of the same
77 // subsystems is scheduled to run
int directionMultiplier
Can be 1 or -1. Determines the direction the the robot moves in.
frc::XboxController * pJoyDrive
A mnemonic for the driver's controller because we are lazy.
void Initialize() override
Runs once on initalization.
DriveWithJoystick()
Class constructor.
bool getTriggers()
Called only if the drivemode is set to 1.
void End() override
Runs once when IsFinished() returns true.
double radial
radial value that will be passed into DriveTrain::RadialDrive
void ArcadeDrive(double xSpeed, double zRotation)
Definition: DriveTrain.cpp:53
void Interrupted() override
Runs once if the command is forced to stop.
int driveMode
Used to keep track of the drive mode.
double magnitude
magnitude value that will be passed into DriveTrain::RadialDrive
frc::XboxController * GetJoystickDrive(void)
Definition: OI.cpp:10
static OI * m_oi
Pointer for the Operator Interface (OI)
Definition: Robot.h:68
static DriveTrain * m_DriveTrain
Pointer for the DriveTrain.
Definition: Robot.h:63
double magnitudeMultiplier
The magnitude of the robot is multiplied by this number. Used for slowmode.
bool IsFinished() override
void Execute() override
Called in a loop during Teleop.