Insane TankDrive code. NOT FUNCTIONAL

This commit is contained in:
Jason Cox 2016-01-28 15:47:56 -05:00
parent 41aa90f7e2
commit 3d0cb6be07
2 changed files with 57 additions and 26 deletions

View File

@ -7,36 +7,66 @@
* controlled motor. * controlled motor.
* *
*/ */
class Robot : public SampleRobot { class Robot : public IterativeRobot {
CANTalon r1_drive, r2_drive, l1_drive, l2_drive; CANTalon r1_drive;
TankDrive drive; CANTalon r2_drive;
CANTalon l1_drive;
CANTalon l2_drive;
Joystick m_stick; Joystick m_stick;
// update every 0.01 seconds/10 milliseconds. // update every 0.01 seconds/10 milliseconds.
// The talon only receives control packets every 10ms. // The talon only receives control packets every 10ms.
double kUpdatePeriod = 0.010; //double kUpdatePeriod = 0.010;
public: public:
Robot() Robot()
: r1_drive(0), // Initialize the Talon as device 1. Use the roboRIO web : r1_drive(1), // Initialize the Talon as device 1. Use the roboRIO web
r2_drive(1)), // interface to change the device number on the talons. r2_drive(2), // interface to change the device number on the talons.
l1_drive(2), l1_drive(3),
l2_drive(3), l2_drive(4),
drive(new CANTalon[] {&r1_drive,&r2_drive}, new CANTalon[] {&l1_drive, &l2_drive}),
m_stick(0) m_stick(0)
{} {
printf("Initializing Robot...");
printf("Initializing TankDrive");
drive = new TankDrive(&l1_drive, &l2_drive, &r1_drive, &r2_drive);
printf("Ready!");
}
void DisabledInit()
{
}
void TeleopInit()
{
printf("Starting Teleop mode");
r1_drive.Enable();
r2_drive.Enable();
l1_drive.Enable();
l2_drive.Enable();
}
void TeleopPeriodic()
{
printf("Teleop Periodic Start.");
drive->Drive(&m_stick);
printf("~Teleop Periodic End.");
}
/** /**
* Runs the motor from the output of a Joystick. * Runs the motor from the output of a Joystick.
*/ *
void OperatorControl() { void OperatorControl() {
while (IsOperatorControl() && IsEnabled()) { while (IsOperatorControl() && IsEnabled()) {
// Do Drive. // Do Drive.
drive.Drive(&m_stick); std::cerr << "In Operator Control";
drive->Drive(&m_stick);
Wait(kUpdatePeriod); // Wait a bit so that the loop doesn't lock everything up. Wait(kUpdatePeriod); // Wait a bit so that the loop doesn't lock everything up.
} }
} }*/
TankDrive *drive;
}; };
START_ROBOT_CLASS(Robot) START_ROBOT_CLASS(Robot)

View File

@ -18,12 +18,14 @@
class TankDrive { class TankDrive {
public: public:
TankDrive(CANTalon *left[], CANTalon *right[]) TankDrive(CANTalon *l1, CANTalon *l2, CANTalon* r1, CANTalon *r2)
{ {
Left = new CANTalon[] {left[0], left[1]}; this->l1 = l1;
Right = new CANTalon[] {right[0], right[1]}; this->l2 = l2;
this->r1 = r1;
this->r2 = r2;
} }
virtual ~TankDrive() { delete Left[0]; delete Left[1]; delete Right[0]; delete Right[1]; } virtual ~TankDrive() { delete l1; delete l2; delete r1; delete r2; }
void Drive(Joystick *js) void Drive(Joystick *js)
{ {
@ -34,14 +36,14 @@ public:
// set deadzone // set deadzone
if(x > -DEADZONE_RADIUS && x < DEADZONE_RADIUS) if(x > -DEADZONE_RADIUS && x < DEADZONE_RADIUS)
{ {
x = 0f; x = 0;
} }
if(y > -DEADZONE_RADIUS && y < DEADZONE_RADIUS) if(y > -DEADZONE_RADIUS && y < DEADZONE_RADIUS)
{ {
y = 0f; y = 0;
} }
float left=0f, right=0f; float left=0, right=0;
if(x == 0) if(x == 0)
{ {
@ -59,16 +61,15 @@ public:
left = th; left = th;
} }
Left[0]->Set(left); l1->Set(left);
Left[1]->Set(left); l2->Set(left);
Right[0]->Set(right); r1->Set(right);
Right[1]->Set(right); r2->Set(right);
} }
private: private:
CANTalon* Left[]; CANTalon *l1, *l2, *r1, *r2;
CANTalon* Right[];
}; };
#endif /* SRC_TANKDRIVE_H_ */ #endif /* SRC_TANKDRIVE_H_ */