@@ -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
109117void 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
155169float 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+
168195void Drive::updateMotors () {
169196 if (requestedState == nav->stopped && state == nav->stopped ) { // Update speeds here if nav is controlling
170197 leftSpeed = navSpeed->leftMotorSpeed ;
0 commit comments