2
0
mirror of https://github.com/team2059/Dent synced 2025-01-07 22:14:14 -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() { void AutoDrive::Execute() {
//X axis, Y axis, Z axis, sensitivity, speed threshold (usually throttle) //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() { bool AutoDrive::IsFinished() {
return IsTimedOut(); return IsTimedOut();
} }
void AutoDrive::End() { 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() { void AutoDrive::Interrupted() {
End(); End();

View File

@ -8,14 +8,14 @@ void Turn::Initialize() {
} }
void Turn::Execute() { void Turn::Execute() {
//X axis, Y axis, Z axis, sensitivity, speed threshold (usually throttle) //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() { bool Turn::IsFinished() {
return IsTimedOut(); return IsTimedOut();
} }
void Turn::End() { void Turn::End() {
// Stop driving // 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() { void Turn::Interrupted() {
End(); End();

View File

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

View File

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

View File

@ -9,9 +9,7 @@
*/ */
class Drivetrain: public Subsystem { class Drivetrain: public Subsystem {
private: private:
CANTalon *rightFront, //<! Front right motor CANTalon *rightRear, //<! Back right motor
*leftFront, //<! Front left motor
*rightRear, //<! Back right motor
*leftRear; //<! Back left motor *leftRear; //<! Back left motor
Gyro *gyro; //<! Gyro Gyro *gyro; //<! Gyro
public: public:
@ -23,8 +21,6 @@ class Drivetrain: public Subsystem {
* @brief Current motor to test * @brief Current motor to test
*/ */
enum e_motors { enum e_motors {
FRONTRIGHT, //<! Front right motor
FRONTLEFT, //<! Front left motor
BACKRIGHT, //<! Back right motor BACKRIGHT, //<! Back right motor
BACKLEFT //<! Back left motor BACKLEFT //<! Back left motor
}; };
@ -33,7 +29,7 @@ class Drivetrain: public Subsystem {
*/ */
void InitDefaultCommand(); 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 x Joystick x value (-1.0 to 1.0)
* @param y Joystick y 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 sensitivity Sensitivity (0.0 to 1.0)
* @param driveStraight Overrides z value to correct for motor lag (default: false) * @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 * @brief Tests one motor
* *