This repository has been archived on 2020-09-21. You can view files and clone it, but cannot push or open issues or pull requests.
FRC2016-old/DriveBase/src/TankDrive.h

54 lines
914 B
C
Raw Normal View History

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"
class TankDrive {
2016-01-28 13:08:37 -05:00
2016-01-28 11:33:19 -05:00
public:
2016-01-28 15:47:56 -05:00
TankDrive(CANTalon *l1, CANTalon *l2, CANTalon* r1, CANTalon *r2)
2016-01-28 13:08:37 -05:00
{
dt1 = RobotDrive(l1, r1);
dt2 = RobotDrive(l2, r2);
2016-01-28 13:08:37 -05:00
}
2016-01-28 15:47:56 -05:00
virtual ~TankDrive() { delete l1; delete l2; delete r1; delete r2; }
2016-01-28 11:33:19 -05:00
2016-01-28 13:08:37 -05:00
void Drive(Joystick *js)
{
float x = js->GetX(),
y = js->GetY(),
th = ((1.0 - (js.GetThrottle()))/2.0);
2016-01-28 13:08:37 -05:00
// set deadzone
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
}
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
}
float speed = y * th;
float rot = y;
dt1.ArcadeDrive(speed, rot, false);
dt2.ArcadeDrive(speed, rot, false);
2016-01-28 13:08:37 -05:00
}
2016-01-28 11:33:19 -05:00
private:
RobotDrive dt1, dt2;
2016-01-28 11:33:19 -05:00
};
#endif /* SRC_TANKDRIVE_H_ */