-
Notifications
You must be signed in to change notification settings - Fork 2
/
robot3238.cpp
220 lines (184 loc) · 7.68 KB
/
robot3238.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include <WPILib.h>
#include "robot3238.h"
#include "Settings.h"
robot3238::robot3238(void) : DS(DriverStation::GetInstance()),DSEIO(DS->GetEnhancedIO()), insight(FOUR_ZONES){
theSwag = new Swag(1, SwagArduinoNum);
driveJoystick = new Joystick (DriveJoystickPort);
shootJoystick = new Joystick (ShootJoystickPort);
theChassis = new Chassis(ChassisLeftMtr, ChassisRightMtr, ChassisTiltMtr);
theClimber = new Climber(ClimberLeftMtr, ClimberRightMtr, ClimberLeftEncoder, ClimberRightEncoder, ClimberDeployerLeftPort, ClimberDeployerRightPort);
theCollector = new Collector(theSwag, FloorOpenSwitchPort, FloorCloseSwitchPort, BucketSwitchPort);
theShooter = new Shooter(theSwag, ShooterShooterMtr, ShooterTiltMtr, ShooterTach);
dropTimer = new Timer();
}
void robot3238::RobotInit(void) {
SmartDashboard::init();
theChassis->Init();
theClimber->Init();
theShooter->Init();
insight_shootRPM.setHeader("RPM:");
insight_shootAngle.setHeader("Ang:");
insight.registerData(insight_shootRPM, 1);
insight.registerData(insight_shootAngle, 2);
insight.startDisplay();
DriverStationLCD::GetInstance()->PrintfLine(DriverStationLCD::kUser_Line1, __DATE__ " " __TIME__);
printf("RobotInit() Completed\n");
}
void robot3238::DisabledInit(void) {
theChassis->Init();
theChassis->SetBrake();
theCollector->Disable();
}
void robot3238::AutonomousInit(void) {
theChassis->Init();
theCollector->Init();
theChassis->SetBrake();
dropTimer->Start();
AutonomousState = preparingToShoot;
}
void robot3238::TeleopInit(void) {
theChassis->Init();
theCollector->Init();
teleopMode = TM::NORMAL;
}
void robot3238::DisabledPeriodic(void) {
Periodic();
Settings.rehash();
theChassis->SetBrake();
}
bool robot3238::IsReadyToFire() {
return theShooter->ShooterUpToSpeed() && theShooter->DoneShooting() && theCollector->isFrisbeeReady();
}
void robot3238::AutonomousPeriodic(void) {
Periodic();
AutonomousAngle = Settings.getLong("AutonomousAngle", AutonomousAngle, true);
AutonomousRPM = Settings.getLong("AutonomousRPM", AutonomousRPM, true);
theChassis->SetBrake();
theChassis->TankDrive(0, 0, 0);
theShooter->SetRPM(AutonomousRPM);
switch (AutonomousState){
case preparingToShoot:
if(IsReadyToFire()) {
theCollector->dropDisc();
AutonomousState = droppingDisc;
}
break;
case droppingDisc:
if(theCollector->doneDropping()){
dropTimer->Reset();
AutonomousState = settlingDisc;
}
break;
case settlingDisc:
if(dropTimer->Get() > 0.5){
AutonomousState = shooting;
}
break;
case shooting:
theShooter->Shoot();
AutonomousState = preparingToShoot;
break;
}
}
void robot3238::TeleopPeriodic(void) {
Periodic();
static TM::TeleopMode lastMode = TM::NORMAL;
if (!DS->GetDigitalIn(2)) teleopMode = TM::NORMAL;
else teleopMode = TM::CLIMB;
//if (teleopMode == TM::CLIMB && lastMode != TM::CLIMB) {
if (teleopMode != lastMode) {
theSwag->StartClimb(teleopMode == TM::CLIMB);
lastMode = teleopMode;
}
if (driveJoystick->GetRawButton(4)) theSwag->DoneClimb();
if (driveJoystick->GetRawButton(12)) theSwag->ResetSwag();
bool raiseHooks = driveJoystick->GetRawButton(3);
theClimber->RaiseHooks(raiseHooks);
float driveForward = driveJoystick->GetRawAxis(2);
float shootForward = shootJoystick->GetRawAxis(6);
float driveTwist = driveJoystick->GetRawAxis(3);
float driveThrottle = -(driveJoystick->GetRawAxis(4)/2 - .5);
float chassisForward = 0, chassisTwist = 0, chassisThrottle = 0;
float shootTiltPwr = shootForward;
switch (teleopMode) {
case TM::NORMAL:
if (driveJoystick->GetRawButton(2))
chassisThrottle = driveThrottle/2;
else chassisThrottle = driveThrottle;
chassisForward = -driveForward;
chassisTwist = -driveTwist;
break;
case TM::CLIMB:
theClimber->ManualClimb(driveForward);
break;
// case TM::CLIMB_MAN:
// //theClimber->ManualClimb(shootForward, driveForward);
// theClimber->ManualClimb(driveForward, driveForward);
// shootTiltPwr = 0;
// break;
}
bool chassisInvert = driveJoystick->GetRawButton(2);
theChassis->ArcadeDrive(chassisForward, chassisTwist, chassisThrottle, chassisInvert);
theShooter->ManualTilt(shootTiltPwr);
bool deployClimber = driveJoystick->GetRawButton(1);
theClimber->Deploy(deployClimber);
bool shoot = shootJoystick->GetRawButton(1);
if (shoot) theShooter->Shoot();
static TwoButtonToggle collectortoggle;
theCollector->manualMode(collectortoggle.Set(shootJoystick->GetRawButton(11), shootJoystick->GetRawButton(12)));
theCollector->manualFloorControl((int)shootJoystick->GetRawAxis(5));
bool dropFrisbee = shootJoystick->GetRawButton(2);
if (dropFrisbee) theCollector->dropDisc();
bool collectorReInit = shootJoystick->GetRawButton(3);
if (collectorReInit) theCollector->Init();
// SmartDashboard::PutBoolean("Ds digital 4", DS->GetDigitalIn(4));
if(shootJoystick->GetRawButton(7)){
theShooter->SetRawPower(-1.0);
}
else{
if (!DS->GetDigitalIn(4)) theShooter->SetRPM(2800); //theShooter->RampUpToValue(0.75);
else if (!DS->GetDigitalIn(6)) theShooter->SetRPM(3300); //theShooter->RampUpToValue(0.875);
else if (!DS->GetDigitalIn(8)) theShooter->SetRPM(10000); //theShooter->RampUpToValue(1);
else theShooter->SetRPM(0); //theShooter->RampUpToValue(0);
}
// static Toggle shootSpeedToggle;
// if(shootSpeedToggle.Set(shootJoystick->GetRawButton(7))) theShooter->SetRPM(3500);
// else theShooter->SetRPM(0);
theChassis->ManualTilt(driveJoystick->GetRawAxis(6));
}
// Put things that should be done periodically in any mode here
void robot3238::Periodic(void) {
int shootRPM = (int)theShooter->GetRPM();
SmartDashboard::PutNumber("ShooterRPM", shootRPM);
insight_shootRPM.setData(shootRPM);
int shootAngle = (int)theShooter->GetAngle();
SmartDashboard::PutNumber("ShooterTilt", shootAngle);
insight_shootAngle.setData(shootAngle);
static bool hadFrisbeeReady = false;
bool haveFrisbeeReady = theCollector->isFrisbeeReady();
if (hadFrisbeeReady != haveFrisbeeReady) {
theSwag->HaveFrisbee(haveFrisbeeReady);
hadFrisbeeReady = haveFrisbeeReady;
}
SmartDashboard::PutBoolean("hadfrisbee", hadFrisbeeReady);
SmartDashboard::PutBoolean("havefrisbee", haveFrisbeeReady);
// SmartDashboard::PutBoolean("CollectorfloorClosed", theCollector->isFloorClosed());
// SmartDashboard::PutBoolean("CollectorfloorOpened", theCollector->isFloorOpen());
// SmartDashboard::PutBoolean("CollectorhaveFrisbee", theCollector->isFrisbeeReady());
// SmartDashboard::PutBoolean("CollectorReadyToFire", theCollector->doneDropping());
// SmartDashboard::PutString("CollectorState", theCollector->getState());
// SmartDashboard::PutBoolean("ShooterUpToSpeed", theShooter->ShooterUpToSpeed());
// SmartDashboard::PutBoolean("AngleSet", theShooter->IsAngleSet());
// SmartDashboard::PutBoolean("DoneShooting", theShooter->DoneShooting());
// SmartDashboard::PutNumber("AutonomousState", (int)AutonomousState);
// static int numLoops;
// SmartDashboard::PutNumber("Num Loops", numLoops++);
// SmartDashboard::PutNumber("DSEIO.GetButtons", DSEIO.GetButtons());
SmartDashboard::PutBoolean("IsReadyToFire", IsReadyToFire());
theChassis->Idle();
theClimber->Idle();
theCollector->Idle();
theShooter->Idle();
DriverStationLCD::GetInstance()->UpdateLCD();
}
START_ROBOT_CLASS(robot3238);