2
0
mirror of https://github.com/team2059/Dent synced 2024-12-18 20:52:29 -05:00

added arcade drive

This commit is contained in:
Adam Long 2015-09-17 19:59:58 +00:00
parent bc7ec90009
commit 7e95ca8469
5 changed files with 17 additions and 30 deletions

View File

@ -14,13 +14,13 @@ void AutoDrive::Initialize() {
}
void AutoDrive::Execute() {
//X axis, Y axis, Z axis, sensitivity, speed threshold (usually throttle)
DentRobot::drivetrain->DriveMecanum(x, y, z, 0.9, gyro);
DentRobot::drivetrain->DriveArcade(x, y, z, 0.9, gyro);
}
bool AutoDrive::IsFinished() {
return IsTimedOut();
}
void AutoDrive::End() {
DentRobot::drivetrain->DriveMecanum(0.0, 0.0, 0.0, 0.9);
DentRobot::drivetrain->DriveArcade(0.0, 0.0, 0.0, 0.9);
}
void AutoDrive::Interrupted() {
End();

View File

@ -8,14 +8,14 @@ void Turn::Initialize() {
}
void Turn::Execute() {
//X axis, Y axis, Z axis, sensitivity, speed threshold (usually throttle)
DentRobot::drivetrain->DriveMecanum(0.0, 0.0, 0.6, 0.9);
DentRobot::drivetrain->DriveArcade(0.0, 0.0, 0.6, 0.9);
}
bool Turn::IsFinished() {
return IsTimedOut();
}
void Turn::End() {
// Stop driving
DentRobot::drivetrain->DriveMecanum(0.0, 0.0, 0.0, 0.9);
DentRobot::drivetrain->DriveArcade(0.0, 0.0, 0.0, 0.9);
}
void Turn::Interrupted() {
End();

View File

@ -22,11 +22,7 @@ void Drive::Execute() {
x = -x;
y = -y;
}
if(DentRobot::oi->GetLeftStick()->GetRawButton(7)) {
DentRobot::drivetrain->DriveMecanum(0.0, 0.0, 0.0, 0.9);
} else {
DentRobot::drivetrain->DriveMecanum(x, y, z, 0.9);
}
DentRobot::drivetrain->DriveArcade(x, y, z, 0.9);
}
bool Drive::IsFinished() {
return IsTimedOut();

View File

@ -3,8 +3,6 @@
#include "../Commands/Drivetrain/Drive.h"
Drivetrain::Drivetrain(): Subsystem("Drivetrain") {
rightFront = new CANTalon(DRIVE_FRONT_RIGHT_CAN);
leftFront = new CANTalon(DRIVE_FRONT_LEFT_CAN);
rightRear = new CANTalon(DRIVE_BACK_RIGHT_CAN);
leftRear = new CANTalon(DRIVE_BACK_LEFT_CAN);
gyro = new Gyro(DRIVE_GYRO_ANALOG);
@ -12,34 +10,31 @@ Drivetrain::Drivetrain(): Subsystem("Drivetrain") {
void Drivetrain::InitDefaultCommand() {
SetDefaultCommand(new Drive());
}
void Drivetrain::DriveMecanum(double x, double y, double z, double sensitivity, bool driveStraight) {
void Drivetrain::DriveArcade(double x, double y, double z, double sensitivity, bool driveStraight) {
double kP = SmartDashboard::GetNumber("Gyro kP");
double correctX = -(sensitivity*(pow(x, 3))+(1-sensitivity)*x);
double correctY = -(sensitivity*(pow(y, 3))+(1-sensitivity)*y);
double correctZ;
double correctZ = z;
if(driveStraight) {
printf("Driving straight at: %f\n", -gyro->GetAngle()*kP);
correctZ = -gyro->GetAngle()*kP;
} else {
correctZ = -z * 0.5;
}
if(DentRobot::oi->GetLeftStick()->GetRawButton(9)) {
correctY /= 2.0;
}
rightFront->Set((-correctX + correctY - correctZ));
leftFront->Set((correctX + correctY + correctZ)*-1);
rightRear->Set((correctX + correctY - correctZ));
leftRear->Set((-correctX + correctY + correctZ)*-1);
int leftPower=((correctY+(correctX+correctZ))/2+1)*127+1;
int rightPower=((correctY-(correctX+correctZ))/2+1)*127+1;
printf("rightPower:%d\n",rightPower);
printf("leftPower:%d\n",leftPower);
leftRear->Set(leftPower);
rightRear->Set(rightPower);
}
//Used in pretest
void Drivetrain::TestMotor(e_motors motor, double power) {
switch(motor) {
case FRONTRIGHT:
rightFront->Set(power);
break;
case FRONTLEFT:
leftFront->Set(power);
break;
case BACKRIGHT:
rightRear->Set(power);
break;

View File

@ -9,9 +9,7 @@
*/
class Drivetrain: public Subsystem {
private:
CANTalon *rightFront, //<! Front right motor
*leftFront, //<! Front left motor
*rightRear, //<! Back right motor
CANTalon *rightRear, //<! Back right motor
*leftRear; //<! Back left motor
Gyro *gyro; //<! Gyro
public:
@ -23,8 +21,6 @@ class Drivetrain: public Subsystem {
* @brief Current motor to test
*/
enum e_motors {
FRONTRIGHT, //<! Front right motor
FRONTLEFT, //<! Front left motor
BACKRIGHT, //<! Back right motor
BACKLEFT //<! Back left motor
};
@ -33,7 +29,7 @@ class Drivetrain: public Subsystem {
*/
void InitDefaultCommand();
/**
* @brief Drives the robot with mecanum
* @brief Drives the robot with arcade
*
* @param x Joystick x value (-1.0 to 1.0)
* @param y Joystick y value (-1.0 to 1.0)
@ -41,7 +37,7 @@ class Drivetrain: public Subsystem {
* @param sensitivity Sensitivity (0.0 to 1.0)
* @param driveStraight Overrides z value to correct for motor lag (default: false)
*/
void DriveMecanum(double x, double y, double z, double sensitivity, bool driveStraight = false);
void DriveArcade(double x, double y, double z, double sensitivity, bool driveStraight = false);
/**
* @brief Tests one motor
*