Skip to content

Commit aa5c2e3

Browse files
author
Tom Lazar
committed
Monday Night
1 parent 83d3710 commit aa5c2e3

File tree

9 files changed

+134
-112
lines changed

9 files changed

+134
-112
lines changed

Debug/src/IControl.o

252 Bytes
Binary file not shown.

src/Drive/Drive.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Drive::Drive(Motor *motor, IXbox *xbox, ISensorControl *nav) {
2020
state = nav->running;
2121
requestedState = nav->running;
2222
userControl = false;
23+
direction = true;
2324

2425
left = new Encoder(2, 3);
2526
right = new Encoder(4, 5);
@@ -59,6 +60,7 @@ void Drive::TeleopInit() {
5960
SmartDashboard::PutNumber("Accel", 0.1); //Acceleration curve Value 0.1 - 0.05 is good
6061

6162
userControl = true; //Start with user control
63+
direction = true;
6264
state = nav->running;
6365
requestedState = nav->running;
6466
}
@@ -69,12 +71,18 @@ void Drive::TeleopPeriodic() {
6971
navSpeed = nav->UpdateMotorSpeeds(leftSpeed, rightSpeed); //nav returns speed it wants (corrected or wehen nav is controlling)
7072
updateMotors();
7173

72-
if (Global::telemetry <= 1) { //Normal
74+
if (Global::telemetry >= 1) { //Normal
7375
SmartDashboard::PutNumber("Drive Left", leftSpeed);
7476
SmartDashboard::PutNumber("Drive Right", rightSpeed);
75-
} else if (Global::telemetry <= 2) { //debug
77+
if (direction)
78+
SmartDashboard::PutString("Direction", "Forward");
79+
else
80+
SmartDashboard::PutString("Direction", "Reverse");
81+
} else if (Global::telemetry >= 2) { //debug
7682

77-
} else if (Global::telemetry <= 3) { //advanced debug
83+
} else if (Global::telemetry >= 3) { //advanced debug
84+
SmartDashboard::PutNumber("X Value", xbox->getAxisLeftX());
85+
SmartDashboard::PutNumber("Y Value", xbox->getAxisLeftY());
7886
SmartDashboard::PutNumber("Left Raw", left->Get());
7987
SmartDashboard::PutNumber("Right RAW", right->Get());
8088
SmartDashboard::PutNumber("Left2 Raw", left2->Get());
@@ -109,6 +117,10 @@ void Drive::readXboxArcadeT() { // Doesn't work with NAV right now
109117
void Drive::readXboxArcadeD() {
110118
float x, y;
111119

120+
if (xbox->getYPressed()) {
121+
direction = !direction;
122+
}
123+
112124
if (requestedState == nav->running) { //When the state is running xbox controls other wise start to stop
113125
x = xbox->getAxisLeftX();
114126
y = xbox->getAxisLeftY();
@@ -117,8 +129,6 @@ void Drive::readXboxArcadeD() {
117129
x = 0.0;
118130
y = 0.0;
119131
}
120-
//SmartDashboard::PutNumber("X Value", x);
121-
//SmartDashboard::PutNumber("Y Value", y);
122132

123133
//x*x + y*y is >= 1
124134
if (y > 0)
@@ -143,13 +153,17 @@ void Drive::readXboxArcadeD() {
143153
} else
144154
state = nav->running;
145155

146-
if (state == nav->running || state == nav->stopping) { //If running or stopping update speeds here
147-
leftSpeed = acceleration(y + x, leftSpeed);
148-
rightSpeed = acceleration(y - x, rightSpeed);
156+
if (direction) {
157+
if (state == nav->running || state == nav->stopping) { //If running or stopping update speeds here
158+
leftSpeed = acceleration(y + x, leftSpeed);
159+
rightSpeed = acceleration(y - x, rightSpeed);
160+
}
161+
} else {
162+
if (state == nav->running || state == nav->stopping) { //If running or stopping update speeds here
163+
leftSpeed = acceleration2(-(y + x), leftSpeed);
164+
rightSpeed = acceleration2(-(y - x), rightSpeed);
165+
}
149166
}
150-
151-
//SmartDashboard::PutNumber("RightOut Value", rightSpeed);
152-
//SmartDashboard::PutNumber("LeftOut Value", leftSpeed);
153167
}
154168
//Compare requested speed with last speed, if difference greater than accel value only change by accel value
155169
float Drive::acceleration(float newS, float oldS) {
@@ -165,6 +179,19 @@ float Drive::acceleration(float newS, float oldS) {
165179
return newS;
166180
}
167181

182+
float Drive::acceleration2(float newS, float oldS) {
183+
float accel = SmartDashboard::GetNumber("Accel", 0.0);
184+
185+
if (fabs(newS - oldS) < accel) {
186+
if (oldS < newS)
187+
return oldS + accel;
188+
else
189+
return oldS - accel;
190+
}
191+
192+
return newS;
193+
}
194+
168195
void Drive::updateMotors() {
169196
if (requestedState == nav->stopped && state == nav->stopped) { //Update speeds here if nav is controlling
170197
leftSpeed = navSpeed->leftMotorSpeed;

src/Drive/Drive.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Drive: public IDrive, public IControl {
3636

3737
//Acceleration for the drives
3838
float acceleration(float newS, float oldS);
39+
float acceleration2(float newS, float oldS);
3940

4041
Motor *motor;
4142
IXbox *xbox;
@@ -52,6 +53,7 @@ class Drive: public IDrive, public IControl {
5253
float leftSpeed, rightSpeed;
5354

5455
bool userControl; //True if using xbox or decelerating, false if under nav control
56+
bool direction;
5557
};
5658

5759
#endif /* SRC_DRIVE_H_ */

src/Robot.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class Robot: public IterativeRobot {
1414
Arm *arm;
1515
CommandListMaker *clMaker;
1616
RelayController* rc;
17-
CustomUSBCamera* camera;
18-
1917

2018
bool DEBUG = false;
2119

@@ -35,8 +33,6 @@ class Robot: public IterativeRobot {
3533
master->addNode(xbox, "Xbox");
3634

3735
if (robot.compare("PROTO") == 0) {
38-
camera = new CustomUSBCamera();
39-
4036
//master->addNode(camera, "camera");
4137

4238
} else if (robot.compare("TIM") == 0) {
@@ -129,7 +125,7 @@ class Robot: public IterativeRobot {
129125

130126

131127
// Turn???
132-
NavxSensorControl::AutonomousPeriodic(turn);
128+
//NavxSensorControl::AutonomousPeriodic(turn);
133129

134130
}
135131

src/SensorControl/NavxSensorControl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ void NavxSensorControl::TargetingStateMachine() {
8080
float motorSpeed = 0;
8181
switch (targetState) {
8282
case TargetingState::waitForButtonPress:
83-
if ((xbox->getLeftTriggerPressed() && !comp)
84-
|| (xbox->getLeftBumperPressed() && comp)) {
83+
if ( (xbox->getLeftBumperPressed() && comp)) {
8584
commandDriveState = DriveSystemState::stopped;
8685
targetState = TargetingState::waitForStopped;
8786
}

0 commit comments

Comments
 (0)