DeepSpace  2019
TriggerDrive.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 speed and direction multipliers
14  this->directionMultiplier = 1;
15  this->speedMultiplier = 1;
16 
17  //set Speed and Rotation
18  this->speed = 0.0;
19  this->rotation = 0.0;
20  this->rotationOutput = 0.0;
21  this->speedOutput = 0.0;
22 }
23 
24 // Called repeatedly when this Command is scheduled to run
26 
27  // Deal with reversing and slow mode
28  this->directionMultiplier *= (this->pJoyDrive->GetXButtonReleased())? -1 : 1;
29  this->speedMultiplier = (this->pJoyDrive->GetBumper(Hand::kRightHand)) ? 0.6 : 1;
30 
31  // Get movement data form controller
32  // Speed = Right trigger - left trigger
33  this->speed = (this->pJoyDrive->GetTriggerAxis(Hand::kRightHand) - this->pJoyDrive->GetTriggerAxis(Hand::kLeftHand));
34  this->rotation = this->pJoyDrive->GetX(Hand::kLeftHand);
35 
36  // Multiply each value with it's multiplier(s)
37  this->speed *= (this->speedMultiplier * this->directionMultiplier);
39 
40  // Breaks
41  if (this->pJoyDrive->GetBumperPressed(Hand::kLeftHand)){
43  Log("Coasting");
44  }else if (this->pJoyDrive->GetBumperReleased(Hand::kLeftHand)){
46  };
47 
48  // Slew limit the joystick
49 
50  double change = this->speed - this->speedOutput;
51  if (change > SLEW_LIMIT) {
52  change = SLEW_LIMIT;
53  }else if(change < (-SLEW_LIMIT)){
54  change = -SLEW_LIMIT;
55  };
56  this->speedOutput += change;
57 
58  // // Rotation slew
59  // double rchange = this->rotation - this->rotationOutput;
60  // if (change > R_SLEW_LIMIT) {
61  // rchange = R_SLEW_LIMIT;
62  // }else if(change < (-R_SLEW_LIMIT)){
63  // rchange = -R_SLEW_LIMIT;
64  // };
65  // this->rotationOutput += rchange;
66 
67  Robot::m_DriveTrain->ArcadeDrive(this->speedOutput, this->rotation);
68 
69  // Reset the speed and rotation
70  // while this does have some negitive side effects while driving,
71  // It is for saftey. (and so we don't have a run-away bot slam into a wall again)
72  this->speed = 0.00;
73  // this->speedOutput = 0.0;
74  this->rotation = 0.00;
75 }
76 
77 
79  // Stop if in Auto climb, we still need to drive in kActive mode though
80  return (ClimbManager::CurrentClimbState == ClimbManager::ClimbState::kAuto);
81 }
82 
83 // Called once after isFinished returns true
85 
86 // Called when another command which requires one or more of the same
87 // subsystems is scheduled to run
int directionMultiplier
Can be 1 or -1. Determines the direction the the robot moves in.
Definition: TriggerDrive.h:30
void End() override
Runs once when IsFinished() returns true.
void Interrupted() override
Runs once if the command is forced to stop.
TriggerDrive()
Class constructor.
Definition: TriggerDrive.cpp:4
void Execute() override
Called in a loop during Teleop.
double speed
Speed value that will be passed into DriveTrain::ArcadeDrive.
Definition: TriggerDrive.h:33
void Log(std::string message)
Main robot class that is called by wpilib.
Definition: logging.cpp:9
void Initialize() override
Runs once on initalization.
double rotation
Rotation value that will be passed into DriveTrain::ArcadeDrive.
Definition: TriggerDrive.h:34
void ArcadeDrive(double xSpeed, double zRotation)
Definition: DriveTrain.cpp:53
#define SLEW_LIMIT
Definition: RobotMap.h:42
#define DRIVEWITHJOYSTICK_ROTATION_LIMITER
Definition: RobotMap.h:103
frc::XboxController * GetJoystickDrive(void)
Definition: OI.cpp:10
static OI * m_oi
Pointer for the Operator Interface (OI)
Definition: Robot.h:68
double speedOutput
Definition: TriggerDrive.h:35
bool IsFinished() override
static DriveTrain * m_DriveTrain
Pointer for the DriveTrain.
Definition: Robot.h:63
void Coast()
Definition: DriveTrain.cpp:88
static ClimbState CurrentClimbState
Definition: ClimbManager.h:15
frc::XboxController * pJoyDrive
A mnemonic for the driver&#39;s controller because we are lazy.
Definition: TriggerDrive.h:38
double rotationOutput
Definition: TriggerDrive.h:36
double speedMultiplier
The speed of the robot is multiplied by this number. Used for slowmode.
Definition: TriggerDrive.h:31
void Break()
Definition: DriveTrain.cpp:96