PDA

View Full Version : Programming with CAN Jaguars


ssirovica
01-28-2012, 10:04 PM
We have decided to switch over from PWM control of the Jaguars on our robot to CAN. Unfortunately I have know idea how to program with CAN Jaguars in Java.

Can you please provide some basic sample code with initialization, and a set method?

Thanks,
Sasha

P.S. When we first began with this declaration: CANJaguar motor = new CANJaguar(1); Net beans was giving us an error saying we needed a try catch statement.

ProgrammerMatt
01-29-2012, 01:09 AM
:) id be happy to



CANJaguar motor1, motor2, motor3, motor4;
RobotDrive myrobot;
Joystick left, right;
public void robotInit() {

try {
motor1 = new CANJaguar(1); // ID number of jaguar
motor2 = new CANJaguar(2);
motor3 = new CANJaguar(3);
motor4 = new CANJaguar(4);

} catch (CANTimeoutException ex) {
ex.printStackTrace();
}

myrobot = new RobotDrive(motor1,motor2,motor3,motor4);

left = new JoyStick(1);
right = new JoyStick(2);
}

public void autonomous() {
}

public void operatorControl() {
while(isOperatorControl()) {

myrobot.tankDrive(left.getY(), right.getY());
}


P.S you need the try catch incase it cant find the jaguar id it throws an error

gpetilli
02-06-2012, 12:17 PM
Keep in mind that it is strongly suggested not to use ID = 1 (and I think the max ID is 16 but would have to look it up). You could number your motors 2,3,4,5 for example. The ID numbers need to be set in the jaguars using the BDC-Comm software on a PC with a serial port connected to the input side of a black jaguar.

dyanoshak
02-06-2012, 02:00 PM
Keep in mind that it is strongly suggested not to use ID = 1 (and I think the max ID is 16 but would have to look it up). You could number your motors 2,3,4,5 for example. The ID numbers need to be set in the jaguars using the BDC-Comm software on a PC with a serial port connected to the input side of a black jaguar.

Yes, it is not recommended that you use 1 because it is the default ID.

The maximum ID number is 63.

-David