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

75 lines
1.1 KiB
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"
2016-01-28 14:08:18 -05:00
#include <math.h>
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-01-28 13:08:37 -05:00
TankDrive(CANTalon *left[], CANTalon *right[])
{
Left = new CANTalon[] {left[0], left[1]};
Right = new CANTalon[] {right[0], right[1]};
}
2016-01-28 11:33:19 -05:00
virtual ~TankDrive() { delete Left[0]; delete Left[1]; delete Right[0]; delete Right[1]; }
2016-01-28 13:08:37 -05:00
void Drive(Joystick *js)
{
float x = js->GetX(),
y = js->GetY(),
th = js->GetThrottle();
// set deadzone
if(x > -DEADZONE_RADIUS && x < DEADZONE_RADIUS)
{
x = 0f;
}
if(y > -DEADZONE_RADIUS && y < DEADZONE_RADIUS)
{
y = 0f;
}
float left=0f, right=0f;
if(x == 0)
{
left = th * y;
right = left;
}
2016-01-28 14:08:18 -05:00
else if(x < 0)
{
right = th;
left = th * cos(x);
}
2016-01-28 13:08:37 -05:00
else
{
2016-01-28 14:08:18 -05:00
right = th * cos(x);
left = th;
2016-01-28 13:08:37 -05:00
}
Left[0]->Set(left);
Left[1]->Set(left);
Right[0]->Set(right);
Right[1]->Set(right);
}
2016-01-28 11:33:19 -05:00
private:
2016-01-28 13:08:37 -05:00
CANTalon* Left[];
CANTalon* Right[];
2016-01-28 11:33:19 -05:00
};
#endif /* SRC_TANKDRIVE_H_ */