-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobot.cpp
More file actions
executable file
·177 lines (161 loc) · 4.03 KB
/
Copy pathRobot.cpp
File metadata and controls
executable file
·177 lines (161 loc) · 4.03 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
//Robot.cpp
//Includes
#include "WPILib.h"
#include <cmath>
#include <string>
#include "Mecanum.h"
#include "Values.h"
using namespace std;
//Main Class
class Robot : public SimpleRobot {
private:
Joystick rJoy;
Joystick lJoy;
Joystick liftJoy;
Talon frMotor;
Talon flMotor;
Talon brMotor;
Talon blMotor;
Encoder frEnc;
Encoder flEnc;
Encoder brEnc;
Encoder blEnc;
PIDMotor fr;
PIDMotor fl;
PIDMotor br;
PIDMotor bl;
Mecanum drive;
double forward;
double right;
double clockwise;
double scalar;
RobotDrive rawDrive;
bool useDriveEncoders;
Talon liftMotor;
Relay claw;
Relay minibot;
public:
Robot(): rJoy(RIGHT_JOYSTICK),
lJoy(LEFT_JOYSTICK),
liftJoy(LIFT_JOYSTICK),
frMotor(FR_DRIVE_TALON),
flMotor(FL_DRIVE_TALON),
brMotor(BR_DRIVE_TALON),
blMotor(BL_DRIVE_TALON),
frEnc(FR_DRIVE_ENCODER_A, FR_DRIVE_ENCODER_B, FR_DRIVE_ENCODER_REVERSE),
flEnc(FL_DRIVE_ENCODER_A, FL_DRIVE_ENCODER_B, FL_DRIVE_ENCODER_REVERSE),
brEnc(BR_DRIVE_ENCODER_A, BR_DRIVE_ENCODER_B, BR_DRIVE_ENCODER_REVERSE),
blEnc(BL_DRIVE_ENCODER_A, BL_DRIVE_ENCODER_B, BL_DRIVE_ENCODER_REVERSE),
fr("FR", frMotor, frEnc, DRIVE_PID),
fl("FL", flMotor, flEnc, DRIVE_PID),
br("BR", brMotor, brEnc, DRIVE_PID),
bl("BL", blMotor, blEnc, DRIVE_PID),
drive(fr, fl, br, bl),
forward(0.0),
right(0.0),
clockwise(0.0),
scalar(1.0),
rawDrive(flMotor, blMotor, frMotor, brMotor),
useDriveEncoders(false),
liftMotor(LIFT_TALON),
claw(CLAW_RELAY),
minibot(MINIBOT_RELAY)
{
rawDrive.SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);
rawDrive.SetInvertedMotor(RobotDrive::kRearLeftMotor, true);
rawDrive.SetSafetyEnabled(false);
frEnc.SetDistancePerPulse(FR_DRIVE_ENCODER_DISTANCE_PER_PULSE);
flEnc.SetDistancePerPulse(FL_DRIVE_ENCODER_DISTANCE_PER_PULSE);
brEnc.SetDistancePerPulse(BR_DRIVE_ENCODER_DISTANCE_PER_PULSE);
blEnc.SetDistancePerPulse(BL_DRIVE_ENCODER_DISTANCE_PER_PULSE);
}
/**
* Print a message stating that the robot has been initialized.
*/
void RobotInit() {
printf("Robot initialized!\n");
}
/**
* Print a message stating that the robot is disabled.
*/
void Disabled() {
printf("Robot is disabled!\n");
}
/**
* Print a message stating that the robot is in autonomous mode.
*/
void Autonomous() {
printf("Autonomous mode enabled!\n");
}
/**
* Run PID Mecanum drive and shooter controls.
*/
void OperatorControl() {
printf("Operator control enabled!\n");
while(IsEnabled() && IsOperatorControl()) {
if(fabs(rJoy.GetRawAxis(2)) < 0.2) {
forward = 0.0;
} else {
forward = rJoy.GetRawAxis(2);
forward *= fabs(forward);
forward *= scalar;
}
if(fabs(rJoy.GetRawAxis(1)) < 0.2) {
right = 0.0;
} else {
right = rJoy.GetRawAxis(1);
right *= fabs(right);
right *= scalar;
}
if(fabs(lJoy.GetRawAxis(1)) < 0.2) {
clockwise = 0.0;
} else {
clockwise = lJoy.GetRawAxis(1);
clockwise *= fabs(clockwise);
clockwise *= scalar;
}
if(rJoy.GetRawButton(1) || lJoy.GetRawButton(1)) {
forward = 0.0;
right = 0.0;
clockwise = 0.0;
}
if(rJoy.GetRawButton(2) && lJoy.GetRawButton(2)) {
useDriveEncoders = true;
}
if(rJoy.GetRawButton(3) && lJoy.GetRawButton(3)) {
useDriveEncoders = false;
}
if(useDriveEncoders) {
drive.update(forward, right, clockwise);
//Forward Right Clockwise
} else {
rawDrive.MecanumDrive_Cartesian(right, forward, clockwise);
}
liftMotor.Set(liftJoy.GetRawAxis(2));
if(liftJoy.GetRawButton(1)) {
claw.Set(Relay::kForward);
} else if(liftJoy.GetRawButton(3)) {
claw.Set(Relay::kReverse);
} else {
claw.Set(Relay::kOff);
}
if(liftJoy.GetRawButton(4)) {
minibot.Set(Relay::kForward);
} else if(liftJoy.GetRawButton(5)) {
minibot.Set(Relay::kReverse);
} else {
minibot.Set(Relay::kOff);
}
Wait(0.005);
}
}
/**
* Print a message stating that the robot is in test mode.
*/
void Test() {
printf("Test mode enabled!\n");
while(IsTest()) {
}
}
};
START_ROBOT_CLASS(Robot);