2016-01-28 11:33:19 -05:00
|
|
|
/*
|
|
|
|
* TankDrive.h
|
|
|
|
*
|
|
|
|
* Created on: Jan 28, 2016
|
|
|
|
* Author: Jason
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRC_TANKDRIVE_H_
|
|
|
|
#define SRC_TANKDRIVE_H_
|
|
|
|
|
2016-01-28 13:08:37 -05:00
|
|
|
#ifndef DEADZONE_RADIUS
|
|
|
|
#define DEADZONE_RADIUS 0.05
|
|
|
|
#endif // DEADZONE_RADIUS
|
|
|
|
|
2016-01-28 11:33:19 -05:00
|
|
|
#include "WPILib.h"
|
|
|
|
|
2016-02-02 09:46:08 -05:00
|
|
|
/**
|
|
|
|
* Encapsulates two RobotDrive objects and keeps them synced by sending
|
|
|
|
* identical ArcadeDrive calls to each. Also handles massaging of Joystick
|
|
|
|
* data to smooth out drive operations.
|
2016-02-09 19:32:27 -05:00
|
|
|
*
|
|
|
|
* TODO: Make this reflect what this class actually does.
|
2016-02-02 09:46:08 -05:00
|
|
|
*/
|
2016-01-28 11:33:19 -05:00
|
|
|
class TankDrive {
|
2016-01-28 13:08:37 -05:00
|
|
|
|
2016-01-28 11:33:19 -05:00
|
|
|
public:
|
2016-02-02 09:41:15 -05:00
|
|
|
TankDrive(CANTalon *l1, CANTalon *l2, CANTalon* r1, CANTalon *r2) {
|
2016-02-03 07:50:19 -05:00
|
|
|
dt1 = new RobotDrive(l1, r1);
|
2016-02-09 19:32:27 -05:00
|
|
|
|
|
|
|
CANTalon* left1 = l1;
|
|
|
|
CANTalon* right1 = r1;
|
|
|
|
CANTalon* left2 = l2;
|
|
|
|
CANTalon* right2 = r2;
|
|
|
|
|
|
|
|
//dt2 = new RobotDrive(l2, r2);
|
2016-01-28 13:08:37 -05:00
|
|
|
}
|
2016-02-02 09:41:15 -05:00
|
|
|
virtual ~TankDrive() {
|
|
|
|
delete dt1;
|
2016-02-09 19:32:27 -05:00
|
|
|
// delete dt2;
|
2016-02-02 09:41:15 -05:00
|
|
|
}
|
2016-01-28 11:33:19 -05:00
|
|
|
|
2016-02-02 09:46:08 -05:00
|
|
|
/**
|
|
|
|
* Calls ArcadeDrive on the two RobotDrive objects for the TankDrive.
|
|
|
|
* Uses #defined DEADZONE_RADIUS to keep the robot from freaking out.
|
|
|
|
* Some math on the "rot" variable could make the driving smoother, I think.
|
|
|
|
*/
|
2016-02-02 09:41:15 -05:00
|
|
|
void Drive(Joystick *js) {
|
2016-02-09 19:32:27 -05:00
|
|
|
/*float x = js->GetX();
|
2016-02-03 07:50:19 -05:00
|
|
|
float y = js->GetY();
|
|
|
|
float th = -((1.0 - (js->GetThrottle()))
|
2016-02-02 09:41:15 -05:00
|
|
|
/ 2.0);
|
2016-01-28 13:08:37 -05:00
|
|
|
|
|
|
|
// set deadzone
|
2016-02-02 09:41:15 -05:00
|
|
|
if (x > -DEADZONE_RADIUS && x < DEADZONE_RADIUS) {
|
2016-01-28 15:47:56 -05:00
|
|
|
x = 0;
|
2016-01-28 13:08:37 -05:00
|
|
|
}
|
2016-02-02 09:41:15 -05:00
|
|
|
if (y > -DEADZONE_RADIUS && y < DEADZONE_RADIUS) {
|
2016-01-28 15:47:56 -05:00
|
|
|
y = 0;
|
2016-01-28 13:08:37 -05:00
|
|
|
}
|
|
|
|
|
2016-02-02 09:39:51 -05:00
|
|
|
float speed = y * th;
|
2016-02-07 23:05:59 -05:00
|
|
|
// TODO: do some math here to smooth out turning?
|
2016-02-09 19:32:27 -05:00
|
|
|
float rot = x * th;*/
|
|
|
|
dt1->ArcadeDrive(js);
|
|
|
|
left2.Set(left1.Get());
|
|
|
|
right2.Set(right1.Get());
|
|
|
|
|
2016-02-02 09:46:08 -05:00
|
|
|
|
2016-02-09 19:32:27 -05:00
|
|
|
|
|
|
|
// dt2->ArcadeDrive(js);
|
|
|
|
/*
|
2016-02-03 07:50:19 -05:00
|
|
|
dt1->ArcadeDrive(speed, rot, false);
|
2016-02-09 19:32:27 -05:00
|
|
|
dt2->ArcadeDrive(speed, rot, false);*/
|
2016-01-28 13:08:37 -05:00
|
|
|
}
|
|
|
|
|
2016-01-28 11:33:19 -05:00
|
|
|
private:
|
2016-02-09 19:32:27 -05:00
|
|
|
RobotDrive *dt1/*, *dt2*/;
|
|
|
|
|
|
|
|
CANTalon l1, right1, left2, right2;
|
2016-01-28 11:33:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SRC_TANKDRIVE_H_ */
|