forked from FRCTeam422/2012RobotCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeam422RobotTesting.cpp
More file actions
189 lines (160 loc) · 6.08 KB
/
Copy pathTeam422RobotTesting.cpp
File metadata and controls
189 lines (160 loc) · 6.08 KB
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
#include "WPILib.h"
//cRIO Modules
const int DIGITAL_SIDECAR_PORT = 1;
const int ANALOG_MODULE_PORT = 1;
const int SOLENOID_MODULE_PORT = 1;
//Joystick Ports
const int JOYSTICK_0_PORT = 1;
const int JOYSTICK_1_PORT = 2;
const int JOYSTICK_2_PORT = 3;
//Motor Channels
const int LEFT_DRIVE_0_CHANNEL = 1;
const int LEFT_DRIVE_1_CHANNEL = 2;
const int RIGHT_DRIVE_0_CHANNEL = 3;
const int RIGHT_DRIVE_1_CHANNEL = 4;
const int LEFT_SHIFTER_CHANNEL = 9;
const int RIGHT_SHIFTER_CHANNEL = 19; //TODO: Get actual port number
const int TOP_LAUNCHER_CHANNEL = 7;
const int BOTTOM_LAUNCHER_CHANNEL = 8;
const int CONVEYOR_0_CHANNEL = 6;
const int CONVEYOR_1_CHANNEL = 9;
//Digital Channels
const int LAUNCH_ENCODER_TOP_CHANNEL_A = 7;
const int LAUNCH_ENCODER_TOP_CHANNEL_B = 5;
const int LAUNCH_ENCODER_BOTTOM_CHANNEL = 8;
//Other Constants
const int MAX_MOTOR_RPM = 200; //TODO: Get actual value for the maximum RPM
const float SHIFT_SERVO_MIN = 0.0;
const float SHIFT_SERVO_MAX = 1.0;
const float SHIFT_SERVO_ERROR = 0.5;
class MainRobot : public IterativeRobot {
//TODO: Change Jaguars to Victors
/*Victor *leftDrive0;
Victor *leftDrive1;
Victor *rightDrive0;
Victor *rightDrive1;*/
Servo *leftShifter;
//Servo *rightShifter;
Jaguar *topLauncher;
Jaguar *bottomLauncher;
/*Victor *conveyor0;
Victor *conveyor1;*/
Encoder *launchEncoderTop;
//PIDController *shooterControl;
//Encoder *launchEncoderBottom;
Joystick *stick0;
Joystick *stick1;
Joystick *stick2;
DriverStationLCD *dashboardLCD;
Dashboard *dashboard;
AnalogChannel *ultrasonic;
int test;
DigitalInput *switch0;
public:
MainRobot(void) {
/*leftDrive0 = new Victor(DIGITAL_SIDECAR_PORT,LEFT_DRIVE_0_CHANNEL);
leftDrive1 = new Victor(DIGITAL_SIDECAR_PORT,LEFT_DRIVE_1_CHANNEL);
rightDrive0 = new Victor(DIGITAL_SIDECAR_PORT,RIGHT_DRIVE_0_CHANNEL);
rightDrive1 = new Victor(DIGITAL_SIDECAR_PORT,RIGHT_DRIVE_1_CHANNEL);*/
leftShifter = new Servo(DIGITAL_SIDECAR_PORT,LEFT_SHIFTER_CHANNEL);
//rightShifter = new Servo(DIGITAL_SIDECAR_PORT,RIGHT_SHIFTER_CHANNEL);
topLauncher = new Jaguar(DIGITAL_SIDECAR_PORT,TOP_LAUNCHER_CHANNEL);
//bottomLauncher = new Jaguar(DIGITAL_SIDECAR_PORT,BOTTOM_LAUNCHER_CHANNEL);
/*conveyor0 = new Victor(DIGITAL_SIDECAR_PORT,CONVEYOR_0_CHANNEL);
conveyor1 = new Victor(DIGITAL_SIDECAR_PORT,CONVEYOR_1_CHANNEL);*/
launchEncoderTop = new Encoder(LAUNCH_ENCODER_TOP_CHANNEL_A, LAUNCH_ENCODER_TOP_CHANNEL_B, false, Encoder::k1X);
//launchEncoderBottom = new Encoder(LAUNCH_ENCODER_BOTTOM_CHANNEL);
stick0 = new Joystick(JOYSTICK_0_PORT);
stick1 = new Joystick(JOYSTICK_1_PORT);
stick2 = new Joystick(JOYSTICK_2_PORT);
ultrasonic = new AnalogChannel(7);
dashboardLCD = DriverStationLCD::GetInstance();
//shooterControl = new PIDController(1.0f,0.000f,0.0f,launchEncoderTop,topLauncher);
SetPeriod( 0.0 );
launchEncoderTop->SetDistancePerPulse(1.0);
launchEncoderTop->SetPIDSourceParameter(Encoder::kRate);
test = 0;
switch0 = new DigitalInput(1);
}
//New Methods
//Update the drive motor speeds on the robot from stick0 and stick1 positions
void Drive(void) {
float left = stick0->GetY();
topLauncher->Set(left);
//float right = stick1->GetY();
/*leftDrive0->Set(left);
leftDrive1->Set(left);
rightDrive0->Set(right);
rightDrive1->Set(right);*/
}
//Sets the gear shifting servos to the values that they currently aren't
void ShiftGear() {
/*leftDrive0->Set(0.0);
leftDrive1->Set(0.0);*/
//rightDrive0->Set(0.0);
//rightDrive1->Set(0.0);
topLauncher->Set(0.0);
Wait(0.25); //wait for a quarter of a second to let the drive motors stop
if ((((SHIFT_SERVO_MIN + SHIFT_SERVO_ERROR) > leftShifter->Get()) && (leftShifter->Get() > (SHIFT_SERVO_MIN - SHIFT_SERVO_ERROR)))) {//&& ((SHIFT_SERVO_MIN + SHIFT_SERVO_ERROR) > rightShifter->Get() > (SHIFT_SERVO_MIN - SHIFT_SERVO_ERROR))) {
// are the two servos between the error threshold of where they would be if they were in MIN state? if so, set to MAX state.
leftShifter->Set(SHIFT_SERVO_MAX);
//rightShifter->Set(SHIFT_SERVO_MAX);
}
else if ((((SHIFT_SERVO_MAX + SHIFT_SERVO_ERROR) > leftShifter->Get()) && (leftShifter->Get()) > (SHIFT_SERVO_MAX - SHIFT_SERVO_ERROR))) {//&& ((SHIFT_SERVO_MAX + SHIFT_SERVO_ERROR) > rightShifter->Get() > (SHIFT_SERVO_MAX - SHIFT_SERVO_ERROR))) {
// are the two servos between the error threshold of where they would be if they were in MAX state? if so, set to MIN state.
leftShifter->Set(SHIFT_SERVO_MIN);
//rightShifter->Set(SHIFT_SERVO_MIN);
}
}
//Update speed of the launcher from the throttle on stick2
void SetLauncherSpeed() {
double throttle = stick2->GetThrottle();
if(stick2->GetRawButton(2)) {
if(throttle != launchEncoderTop->GetRate()) {//TODO: Add in bottomLauncher
topLauncher->Set(throttle);
}
}
else {
topLauncher->Set(0.0);
}
}
//Required Methods
void AutonomousInit(void){
;
}
void AutonomousPeriodic(void) {
;
}
void AutonomousContinuous(void) {
;
}
void TeleopInit(void) {
launchEncoderTop->Start();
launchEncoderTop->Reset();
//shooterControl->Enable();
}
void TeleopPeriodic(void) {
//dashboard->Printf("EncoderRate: %d", launchEncoderTop->GetRate()); //TEST CODE REMOVE
dashboardLCD->Clear();
//dashboardLCD->Printf( DriverStationLCD::kUser_Line1, 1, "Encoder Rate: %g",launchEncoderTop->Get() );
dashboardLCD->Printf(DriverStationLCD::kUser_Line1, 1, "Encoder Count: %d",launchEncoderTop->Get());
dashboardLCD->Printf(DriverStationLCD::kUser_Line2, 1, "Switch: %d",switch0->Get());
dashboardLCD->Printf(DriverStationLCD::kUser_Line3,1, "Ultrasonic: %d",ultrasonic->GetValue());
dashboardLCD->UpdateLCD();
topLauncher->Set(stick0->GetY());
//topLauncher->Set(0.25);
}
void TeleopContinuous(void) {
//Drive();
//shooterControl->SetSetpoint(stick2->GetY());
//regulateMotorSpeed( launchEncoderTop, topLauncher, stick2->GetY() );
//topLauncher->Set(stick2->GetY());
/*if(stick1->GetRawButton(2)) topLauncher->Set(0.25);
else topLauncher->Set(0);*/
if(stick1->GetRawButton(2)) ShiftGear();
//Drive();
//topLauncher->Set(stick2->GetY());
//BottomLauncher->Set(stick2->GetY());
}
};
START_ROBOT_CLASS(MainRobot);