DeepSpace  2019
AutoClimbHigh.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
9 #include "Robot.h"
10 
12  Requires(Robot::m_Arm);
13  Requires(Robot::m_Leg);
14  Requires(Robot::m_CrawlDrive);
15  this->pTimer = new frc::Timer();
16  this->stage = S_LOWER_ARM;
17  this->onFloor = true;
18  this->climbing = false;
19 }
20 
22  this->climbing = true;
23  this->stage = S_LOWER_ARM;
24  this->onFloor = true;
25  this->pTimer->Reset();
26  this->pTimer->Start();
27 }
28 
30  // Execute the appropriate function for the current stage of climb
31  switch (this->stage) {
32  case S_LOWER_ARM : this->Execute_LowerArm() ; break;
33  case S_LOWER_LEG : this->Execute_LowerLeg() ; break;
34  case S_CRAWL : this->Execute_Crawl() ; break;
35  case S_DRIVE : this->Execute_Drive() ; break;
36  case S_RAISE_LEG : this->Execute_Raiseleg() ; break;
37  case S_FINISHED : return;
38  default :
39  Log("AutoClimbHigh has an invalid stage") ;
40  this->stage = S_FINISHED ;
41  break;
42  }
43 }
44 
46 
47  // Moves arm from 35% to 100% throughout 2 seconds, then caps at 100%
48  float speed = 0.35 + std::min(this->pTimer->Get(), 2.0) * 0.325 ;
49  Robot::m_Arm->MoveArm(speed);
50 
51  // If arm is lowered or it's been 5 seconds, go to next stage
52  if (Robot::m_Arm->GetSensor()
53  || this->pTimer->Get() > 5.0) {
54  this->stage = S_LOWER_LEG;
55  this->pTimer->Reset();
56  }
57 }
58 
60 
61  Robot::m_Arm->MoveArm(0.75); // Keep arm down
62  Robot::m_Leg->MoveLeg(-1.0); // Bring leg down
63 
64  // If leg is at bottom or it's been 6 seconds, go to the next stage
65  if (Robot::m_Leg->AtBottom()
66  || this->pTimer->Get() > 10.0) {
67  this->stage = S_CRAWL;
68  this->pTimer->Reset();
69  }
70 }
71 
73 
74  Robot::m_Arm->MoveArm(1.0); // Keep arm down
75  Robot::m_Leg->MoveLeg(-1.0); // Keep leg down
76  Robot::m_CrawlDrive->Move(1.0); // Crawl forward
77  Robot::m_DriveTrain->ArcadeDrive(0.6, 0.0); // Drive forward
78 
79  // Get if we are NOW on the floor
80  bool nowOnFloor = Robot::m_CrawlDrive->GetSensor();
81 
82  // If we were in the air and are now on the floor, go to the next stage
83  if (!this->onFloor && nowOnFloor) {
84  this->stage = S_DRIVE;
85  this->pTimer->Reset();
86  } else {
87  // Otherwise update our 'were' with our 'now'
88  this->onFloor = nowOnFloor ;
89  }
90 
91  // Or, if it's been 6 seconds, go to the next stage
92  if (this->pTimer->Get() > 6.0) {
93  this->stage = S_DRIVE;
94  this->pTimer->Reset();
95  }
96 }
97 
99 
100  Robot::m_Arm->MoveArm(-0.2); // Bring arm up slowly
101  Robot::m_Leg->MoveLeg(-1.0); // Keep leg down
102  Robot::m_CrawlDrive->Move(0.0); // Brake the crawlDrive
103 
104  // Drives from 60% to 30% throughout 2 seconds then flatlines at 30%
105  double power = 0.6 - std::min(this->pTimer->Get(), 2.0) * 0.15 ;
106  Robot::m_DriveTrain->ArcadeDrive(power, 0.0);
107 
108  // We do this for only 2 seconds, no sensors for this part
109  if (this->pTimer->Get() > 2.0) {
110  this->stage = S_RAISE_LEG;
111  this->pTimer->Reset();
112  }
113 }
114 
116 
117  Robot::m_Arm->MoveArm(0.0); // Brake
118  Robot::m_DriveTrain->TankDrive(0.0,0.0); // Brake
119  Robot::m_Leg->MoveLeg(1.0); // Bring legs back up
120 
121  // If leg is at top or it's been 3 seconds, we are finished
122  if (Robot::m_Leg->AtTop()
123  || this->pTimer->Get() > 3.0) {
124  this->stage = S_FINISHED ;
125  }
126 }
127 
129 
130  // Stop if we're no longer in auto climb mode
132  return true;
133  }
134 
135  // Stop if we've reached the end of the climb process
136  if (this->stage == S_FINISHED) {
137 
138  // cannot change climbState in above scenario, hence why we change it here and not in End()
140 
141  return true;
142  }
143  return false;
144 }
145 
147  // Brake all subsystems and stop timer
148  Robot::m_Arm->MoveArm(0.0);
149  Robot::m_Leg->MoveLeg(0.0);
150  Robot::m_DriveTrain->TankDrive(0.0, 0.0);
152  this->pTimer->Stop();
153  this->climbing = false;
154 }
155 
157  // Brake all subsystems and stop timer
158  Robot::m_Arm->MoveArm(0.0);
159  Robot::m_Leg->MoveLeg(0.0);
160  Robot::m_DriveTrain->TankDrive(0.0, 0.0);
162  this->pTimer->Stop();
163  this->climbing = false;
164 }
165 
167  return this->climbing;
168 }
void Execute_LowerLeg(void)
Execute stage LOWER_LEG stuff.
static CrawlDrive * m_CrawlDrive
Pointer for the DriveTrain.
Definition: Robot.h:65
void MoveLeg(double Speed)
Move climb leg up or down.
Definition: Leg.cpp:23
frc::Timer * pTimer
Timer for timing out stages if it takes too long.
Definition: AutoClimbHigh.h:42
void Execute_LowerArm(void)
Execute stage LOWER_ARM stuff.
bool GetSensor(void)
Returns true if its on the floor.
Definition: CrawlDrive.cpp:27
static Arm * m_Arm
Pointer for the Arm.
Definition: Robot.h:66
bool IsFinished() override
void Initialize() override
void Log(std::string message)
Main robot class that is called by wpilib.
Definition: logging.cpp:9
void Execute_Drive(void)
Execute stage DRIVE stuff.
void ArcadeDrive(double xSpeed, double zRotation)
Definition: DriveTrain.cpp:53
void TankDrive(double leftSpeed, double rightSpeed)
Definition: DriveTrain.cpp:59
bool IsClimbing()
Returns whether the robot is in the middle of climbing.
void End() override
void Execute_Raiseleg(void)
Execute stage RAISE_LEG stuff.
void Move(double Speed)
Drive, (or crawl), forwards or backwards Moves the wheels attached to the arms. What wheels do...
Definition: CrawlDrive.cpp:32
enum AutoClimbHigh::Stage stage
static DriveTrain * m_DriveTrain
Pointer for the DriveTrain.
Definition: Robot.h:63
void Execute() override
Switch checks the stage and then calls the appropriate Execute_<Stage>() function.
static ClimbState CurrentClimbState
Definition: ClimbManager.h:15
bool climbing
Bool for tracking whether the robot is in the middle of auto climb.
Definition: AutoClimbHigh.h:44
void Interrupted() override
void MoveArm(double Speed)
Move Arm arm up or down.
Definition: Arm.cpp:37
static Leg * m_Leg
Pointer for the Leg.
Definition: Robot.h:67
bool onFloor
Bool for tracking whether the robot is off the floor or not.
Definition: AutoClimbHigh.h:43
void Execute_Crawl(void)
Execute stage CRAWL stuff.