|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
CANJaguar
Hello,
I am not new to Java, but I am new to the code for the wpi, so I was looking at the API and was especially looking at CANJaguar. My question is that in order to use CAN, do I make an instance of CANJaguar for each jaguar used, or is it only one instance, and I make an instance of Jaguar for the amount used? Also would I need to use it within the drive train? In the end, I am pretty much asking how to set up CAN withing Java. |
|
#2
|
||||
|
||||
|
Re: CANJaguar
The CANJaguar class represents a jaguar. So yes, you need one for each physical jaguar. To set up the drive train, you create all of the jaguars needed and then call the robotDrive constructor with each of the jaguars.
For programming, the only practical difference between CANJaguar and Jaguar is that CANJaguar has more methods (for things like setting PID constants), so if you find a tutorial on how to set things up with normal Jaguars, you just replace the class names with CANJaguar and you should be set. |
|
#3
|
||||
|
||||
|
Re: CANJaguar
Awesome, that makes it much simpler, also on the ID, its the id you issue the Jaguar when you update the firmware correct? or is in in order they are setup along the CAN
|
|
#4
|
||||
|
||||
|
Re: CANJaguar
It's the one where you set the number and then press the button on the jaguar (the ID). The order makes absolutely no difference (except for the whole "wire can't be too long" thing)
|
|
#5
|
||||
|
||||
|
Re: CANJaguar
Ha, how can the wire be too long? on such a short distance with data flying at 1mbs and the Jaguars acting as switches. Also I would like your input on this, for Joystick input, would it be best on Periodic or Continuous?
|
|
#6
|
||||
|
||||
|
Re: CANJaguar
Quote:
Read joystick should probably go in Periodic. Continuous will read the joystick as fast as possible. Periodic will read the joystick at precise intervals (200Hz I think). Honestly, in reference to the system response time of "Joystick moved -> Joystick value read -> Joystick value interpreted -> Motor value sent -> Motor starts moving", the moving of the motor is the longest part (by quite a bit). Running in continuous only makes more requests and sends more control packets (unnecessarily) utilizing more system bandwidth. - Bryce |
|
#7
|
||||
|
||||
|
Re: CANJaguar
Quote:
|
|
#8
|
|||
|
|||
|
Re: CANJaguar
Quote:
Quote:
Quote:
This 20' limitation does have to do with the CAN driver: When all the Jaguars are responding at the same time to broadcast messages they drive the bus slightly higher than a single Jag would. It takes longer for the bus to return to 'zero' and therefor some Jaguars may not read the bit correctly if the bit hasn't had time to settle. The time from high to low depends on the termination resistance as well. This is the reason why we also specify a 100 ohm termination resistor. It helps snap the bus back to zero quickly so there aren't any bit timing errors. We found that 20' of cable, 100 ohm termination resistors, and ~16 Jags on a bus is a good limit for reliable operation. It may be possible to get more Jags, but the cable lengths will have to be shorter. -David |
|
#9
|
||||
|
||||
|
Re: CANJaguar
Quote:
|
|
#10
|
|||
|
|||
|
Re: CANJaguar
How do we know if we have regular jaguars or CAN jaguars? Also, if we use jaguars does this mean we actually need to declare 4 jaguar instances to drive the robot? Can we do something like
Code:
public void robotInit() {
RobotDrive robot = new RobotDrive(1,2,3,4);
Joystick left = new Joystick(1);
Joystick right = new Joystick(2);
}
public void teleopPeriodic() {
robot.tankDrive(left.getThrottle(),(-1*right.getThrottle()));
}
|
|
#11
|
||||
|
||||
|
Re: CANJaguar
Quote:
And what I did with the jaguar is create an instance for each jaguar outside of any of the Init's. Then on the RobotInit(), I initialized them along with the drive train. Code:
public class Team3325 extends IterativeRobot {
CANJaguar leftCANJaguarTop;
CANJaguar leftCANJaguarBottom;
CANJaguar rightCANJaguarTop;
CANJaguar rightCANJaguarBottom;
Joystick inputJoystick;
int leftCanTop = 1;
int leftCanBot = 2;
int rightCanTop = 3;
int rightCanBot = 4;
RobotDrive mechanumDrive;
public void robotInit() {
try {
leftCANJaguarTop = new CANJaguar(leftCanTop);
leftCANJaguarBottom = new CANJaguar(leftCanBot);
rightCANJaguarBottom = new CANJaguar(rightCanBot);
rightCANJaguarTop = new CANJaguar(rightCanTop);
inputJoystick = new Joystick(1);
mechanumDrive = new RobotDrive(leftCANJaguarTop, leftCANJaguarBottom, rightCANJaguarTop, rightCANJaguarBottom);
} catch (Exception e) {
System.out.println(e);
}
}
public void teleopPeriodic() {
try {
mechanumDrive.mecanumDrive_Cartesian(inputJoystick.getX(), inputJoystick.getY(), inputJoystick.getThrottle(), 0.0); //TODO <-- Fix Gyro to proper Param.
} catch (Exception e) {
System.out.println(e);
}
}
}
Last edited by Kodiak : 20-01-2012 at 19:13. |
|
#12
|
||||
|
||||
|
Re: CANJaguar
Besides variables going out of scope, the code you have posed there would do ok. To answer your question about creating Jaguar instances, you can create a RobotDrive both ways
Code:
RobotDrive(int frontLeftMotor, int rearLeftMotor, int frontRightMotor, int rearRightMotor); /* OR */ RobotDrive(SpeedController frontLeftMotor, SpeedController rearLeftMotor, SpeedController frontRightMotor, SpeedController rearRightMotor); EDIT: Also, its more common to use the y axis of each joystick to control motor speeds than it is the throttle, but obviously you can do whatever you wish. |
|
#13
|
||||
|
||||
|
Re: CANJaguar
Quote:
I have to disagree with you on this. According to CAN spec IS0 11898:1993(E) Table 15, the maximum cable distance for 1Mbit/second is 40 Meters not 20 feet. We have also tested at distances much greater than 20 feet without issue using 120 Ohm's of termination on each end of the BUS. FYI a termination resistor of 100 ohms is outside of the spec. Teams using 120 ohms resistors should have no issues related to signal reflection. |
|
#14
|
||||
|
||||
|
Re: CANJaguar
Quote:
Total Cable Length (maximum) 20 ft / 6.1m Tip: Start with this length of bulk cable and cut all segments from it to ensure compliance. Termination Resistance 100 At each end of the network. Just quoting specs. - Bryce |
|
#15
|
||||
|
||||
|
Re: CANJaguar
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|