We are using CAN for the first time and after a few hours of learning how to do it, wiring, and formatting the Talons, our drive code didn't work. I tried controlling each motor individually and it works perfectly, but we would like to use RobotDrive because we are using Mecanum wheels with a gyro. Here is the non-working code:
Code:
class Robot: public SampleRobot {
Joystick driveStick;
CANTalon leftFront;
CANTalon leftBack;
CANTalon rightFront;
CANTalon rightBack;
RobotDrive drive;
Gyro gyro;
public:
Robot() :
driveStick(1),
leftFront(1),
leftBack(5),
rightFront(2),
rightBack(6),
drive(leftFront, leftBack, rightFront, rightBack),
gyro(0)
{}
void OperatorControl() {
gyro.InitGyro();
gyro.Reset();
while (IsOperatorControl() && IsEnabled()) {
drive.MecanumDrive_Cartesian(driveStick.GetX(),driveStick.GetY(),driveStick.GetThrottle(),gyro.GetAngle());
}
}
};
And here is the working code (I used tank drive to make it easier):
Code:
class Robot: public SampleRobot {
Joystick driveStick;
CANTalon leftFront;
CANTalon leftBack;
CANTalon rightFront;
CANTalon rightBack;
Gyro gyro;
public:
Robot() :
driveStick(1),
leftFront(1),
leftBack(5),
rightFront(2),
rightBack(6),
gyro(0)
{}
void OperatorControl() {
gyro.InitGyro();
gyro.Reset();
while (IsOperatorControl() && IsEnabled()) {
leftFront.Set(-driveStick.GetY());
leftBack.Set(-driveStick.GetY());
rightFront.Set(driveStick.GetThrottle());
rightBack.Set(driveStick.GetThrottle());
}
}
};
Does anyone know why this doesn't work? Thanks!