Go to Post Celebrate your failures as well as your successes. - Taylor [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 20-01-2012, 15:12
Kodiak's Avatar
Kodiak Kodiak is offline
Registered User
AKA: Boston
FRC #3325 (Chaos Order)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Texas
Posts: 13
Kodiak is an unknown quantity at this point
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 20-01-2012, 15:17
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 20-01-2012, 15:22
Kodiak's Avatar
Kodiak Kodiak is offline
Registered User
AKA: Boston
FRC #3325 (Chaos Order)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Texas
Posts: 13
Kodiak is an unknown quantity at this point
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
Reply With Quote
  #4   Spotlight this post!  
Unread 20-01-2012, 15:52
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
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)
Reply With Quote
  #5   Spotlight this post!  
Unread 20-01-2012, 16:35
Kodiak's Avatar
Kodiak Kodiak is offline
Registered User
AKA: Boston
FRC #3325 (Chaos Order)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Texas
Posts: 13
Kodiak is an unknown quantity at this point
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?
Reply With Quote
  #6   Spotlight this post!  
Unread 20-01-2012, 17:37
Bryscus's Avatar
Bryscus Bryscus is offline
EE, CpE
AKA: Bryce B.
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Jan 2009
Rookie Year: 1999
Location: Jupiter, FL
Posts: 173
Bryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud of
Re: CANJaguar

Quote:
Originally Posted by Kodiak View Post
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?
It possibly has to do with loading down the CAN cable driver. I think the total cable length is something like 20' if I remember right. One suggestion was to buy a 20' cable and use it. If you need more, you've used too much.

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
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.
Reply With Quote
  #7   Spotlight this post!  
Unread 20-01-2012, 17:49
Kodiak's Avatar
Kodiak Kodiak is offline
Registered User
AKA: Boston
FRC #3325 (Chaos Order)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Texas
Posts: 13
Kodiak is an unknown quantity at this point
Re: CANJaguar

Quote:
Originally Posted by Bryscus View Post
It possibly has to do with loading down the CAN cable driver. I think the total cable length is something like 20' if I remember right. One suggestion was to buy a 20' cable and use it. If you need more, you've used too much.

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
I agree, and I was looking at the code, and its at 50hz, just in case you where curious, and about the CAN, I guess it can be looked at it just like in Networking, but what I think they may mean about being too long is the distance of wire used between one Jaguar to the next and maybe not meant in total distance, which sounds the same but its not, lol.
Reply With Quote
  #8   Spotlight this post!  
Unread 20-01-2012, 18:26
dyanoshak dyanoshak is offline
Registered User
AKA: David Yanoshak
FRC #2158 (ausTIN CANs)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Austin, TX
Posts: 189
dyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond repute
Re: CANJaguar

Quote:
Originally Posted by Kodiak View Post
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?
Quote:
Originally Posted by Kodiak View Post
I guess it can be looked at it just like in Networking, but what I think they may mean about being too long is the distance of wire used between one Jaguar to the next and maybe not meant in total distance, which sounds the same but its not, lol.
Bryscus is correct:

Quote:
Originally Posted by Bryscus View Post
It possibly has to do with loading down the CAN cable driver. I think the total cable length is something like 20' if I remember right. One suggestion was to buy a 20' cable and use it. If you need more, you've used too much.
It is in fact 20' total, not the maximum between each Jaguar. The Jaguars aren't switches or repeaters, the left and right CAN ports are wired directly to each other on the Jaguar circuit board.

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
Reply With Quote
  #9   Spotlight this post!  
Unread 20-01-2012, 18:30
Kodiak's Avatar
Kodiak Kodiak is offline
Registered User
AKA: Boston
FRC #3325 (Chaos Order)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Texas
Posts: 13
Kodiak is an unknown quantity at this point
Re: CANJaguar

Quote:
Originally Posted by dyanoshak View Post
Bryscus is correct:



It is in fact 20' total, not the maximum between each Jaguar. The Jaguars aren't switches or repeaters, the left and right CAN ports are wired directly to each other on the Jaguar circuit board.

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
Awesome, great information! thanks for the clarification.
Reply With Quote
  #10   Spotlight this post!  
Unread 20-01-2012, 18:59
kingkurry kingkurry is offline
Registered User
FRC #4067
 
Join Date: Jan 2012
Location: Maryland
Posts: 20
kingkurry is an unknown quantity at this point
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())); 

}
or do we need to actually need to create jaguar instances and use them to drive the robot. If so, how would we do this?
Reply With Quote
  #11   Spotlight this post!  
Unread 20-01-2012, 19:08
Kodiak's Avatar
Kodiak Kodiak is offline
Registered User
AKA: Boston
FRC #3325 (Chaos Order)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Texas
Posts: 13
Kodiak is an unknown quantity at this point
Re: CANJaguar

Quote:
Originally Posted by kingkurry View Post
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())); 

}
or do we need to actually need to create jaguar instances and use them to drive the robot. If so, how would we do this?
All jaguars both gray and black can use CAN, it is a diffrent way of sending information to them, instead of using the PWM cables you use a phone like cable. Both get the job done, just more accuracy and additional information about the controller while its running comes with the CAN.

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);
        }
    }
}
The code is a little dirty, but it works for testing purposes and can hopefully help you. In your case, if you didn't use CAN, you would have to replace CANJaguar with Jaguar and fix a few of the params respectively.

Last edited by Kodiak : 20-01-2012 at 19:13.
Reply With Quote
  #12   Spotlight this post!  
Unread 20-01-2012, 19:08
CodeYeti's Avatar
CodeYeti CodeYeti is offline
FRC Addict
AKA: Matt Coffin
FRC #0662 (Rocky Mountain Robotics)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Colorado
Posts: 81
CodeYeti is an unknown quantity at this point
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);
And whether you have CANJaguars or regular Jaguars all depends on how you have them hooked up. chances are, you have normal Jaguars. If you are using a PWM cable to hook the Jaguars to the digital module/sidecar, then you have regular Jaguars for sure.

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.
Reply With Quote
  #13   Spotlight this post!  
Unread 20-01-2012, 19:16
Kodiak's Avatar
Kodiak Kodiak is offline
Registered User
AKA: Boston
FRC #3325 (Chaos Order)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Texas
Posts: 13
Kodiak is an unknown quantity at this point
Re: CANJaguar

Quote:
Originally Posted by CodeYeti View Post
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);
And whether you have CANJaguars or regular Jaguars all depends on how you have them hooked up. chances are, you have normal Jaguars. If you are using a PWM cable to hook the Jaguars to the digital module/sidecar, then you have regular Jaguars for sure.

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.
I agree, just threw this code together to please the Electrical crew, I planed to correctly do it being that I have more time
Reply With Quote
  #14   Spotlight this post!  
Unread 20-01-2012, 19:49
kingkurry kingkurry is offline
Registered User
FRC #4067
 
Join Date: Jan 2012
Location: Maryland
Posts: 20
kingkurry is an unknown quantity at this point
Re: CANJaguar

Thank you for your replies. No matter what we try we cannot seem to get our robot to move. This is the code I have been trying:
Code:
package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Watchdog;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Jaguar;

public class RobotTemplate extends IterativeRobot {
    RobotDrive robot;
    Joystick left;
    Joystick right; 
    
    public void robotInit() {
 
  
        robot = new RobotDrive(1,2,3,4);
        left = new Joystick(1);
        right = new Joystick(2);
        System.out.println("RobotInit() completed.");
    }

    public void autonomousPeriodic() {

    }

    public void teleopPeriodic() {
        //robot.tankDrive(left.getThrottle(),(-1*right.getThrottle()));
        //robot.tankDrive(left, right);

        robot.tankDrive(2,2);
        
        //System.out.println("left:"+left.getThrottle());
        //System.out.println("right:"+right.getThrottle());
        //System.out.println("LMAG:"+ left.getMagnitude());
        //System.out.println("RMAG:"+ right.getMagnitude());

    }
    
}
the getThrottle() method always returns a 0 regardless of what we do to the joystick. The getMagnitude() method show change as we move the joystick. However, what worries me is that the robot doesn't seem to move even if i input doubles into the tankDrive() method. The jaguars lights should stop blinking and become solid when they are receiving a signal right? They never seem to do this and stay blinking no matter what.
Reply With Quote
  #15   Spotlight this post!  
Unread 20-01-2012, 20:24
Kodiak's Avatar
Kodiak Kodiak is offline
Registered User
AKA: Boston
FRC #3325 (Chaos Order)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Texas
Posts: 13
Kodiak is an unknown quantity at this point
Re: CANJaguar

Quote:
The jaguars lights should stop blinking and become solid when they are receiving a signal right?
Yes that is correct. What if you where to make an instance of the Jaguars with their Channel and the location of the module, and place that inside of the drive train, is it the same result?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:18.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi