View Single Post
  #1   Spotlight this post!  
Unread 31-01-2015, 19:40
1452-Leo 1452-Leo is offline
Registered User
FRC #1452 (Omnicats)
Team Role: Alumni
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Los Angeles
Posts: 44
1452-Leo is an unknown quantity at this point
[C++] Use CAN Talons in RobotDrive

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!