2015-01-16 19:29:55 -05:00
|
|
|
#include "Drivetrain.h"
|
|
|
|
#include "../RobotMap.h"
|
2015-02-03 15:55:11 -05:00
|
|
|
#include "../Commands/Drivetrain/Drive.h"
|
2015-01-16 19:29:55 -05:00
|
|
|
|
2015-07-31 12:52:15 -04:00
|
|
|
Drivetrain::Drivetrain(): Subsystem("Drivetrain") {
|
2015-02-02 19:56:27 -05:00
|
|
|
rightRear = new CANTalon(DRIVE_BACK_RIGHT_CAN);
|
|
|
|
leftRear = new CANTalon(DRIVE_BACK_LEFT_CAN);
|
2015-03-10 20:14:38 -04:00
|
|
|
gyro = new Gyro(DRIVE_GYRO_ANALOG);
|
2015-01-16 19:29:55 -05:00
|
|
|
}
|
2015-07-31 12:52:15 -04:00
|
|
|
void Drivetrain::InitDefaultCommand() {
|
2015-01-17 12:55:51 -05:00
|
|
|
SetDefaultCommand(new Drive());
|
2015-01-16 19:29:55 -05:00
|
|
|
}
|
2015-09-17 15:59:58 -04:00
|
|
|
void Drivetrain::DriveArcade(double x, double y, double z, double sensitivity, bool driveStraight) {
|
2015-03-23 10:52:02 -04:00
|
|
|
double kP = SmartDashboard::GetNumber("Gyro kP");
|
2015-02-27 15:44:18 -05:00
|
|
|
double correctX = -(sensitivity*(pow(x, 3))+(1-sensitivity)*x);
|
2015-02-27 16:42:11 -05:00
|
|
|
double correctY = -(sensitivity*(pow(y, 3))+(1-sensitivity)*y);
|
2015-09-17 15:59:58 -04:00
|
|
|
double correctZ = z;
|
2015-07-31 12:52:15 -04:00
|
|
|
if(driveStraight) {
|
2015-03-10 20:49:32 -04:00
|
|
|
printf("Driving straight at: %f\n", -gyro->GetAngle()*kP);
|
2015-03-10 20:14:38 -04:00
|
|
|
correctZ = -gyro->GetAngle()*kP;
|
2015-07-31 12:52:15 -04:00
|
|
|
} else {
|
2015-03-10 20:14:38 -04:00
|
|
|
correctZ = -z * 0.5;
|
|
|
|
}
|
2015-09-18 16:34:20 -04:00
|
|
|
double leftPower=(y-x);
|
|
|
|
double rightPower=(y+x);
|
|
|
|
leftRear->Set((correctX + correctY + correctZ));
|
|
|
|
rightRear->Set((correctX + correctY - correctZ));
|
2015-01-17 10:34:08 -05:00
|
|
|
}
|
2015-02-07 09:17:20 -05:00
|
|
|
//Used in pretest
|
2015-07-31 12:52:15 -04:00
|
|
|
void Drivetrain::TestMotor(e_motors motor, double power) {
|
|
|
|
switch(motor) {
|
2015-02-07 09:17:20 -05:00
|
|
|
case BACKRIGHT:
|
|
|
|
rightRear->Set(power);
|
|
|
|
break;
|
|
|
|
case BACKLEFT:
|
|
|
|
leftRear->Set(power);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-31 12:52:15 -04:00
|
|
|
void Drivetrain::ResetGyro() {
|
2015-03-10 20:14:38 -04:00
|
|
|
gyro->Reset();
|
|
|
|
}
|
2015-02-08 12:26:15 -05:00
|
|
|
// vim: ts=2:sw=2:et
|