Go to Post If you want to make change, you have to know what you're trying to change. - [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, 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
  #2   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
  #3   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
  #4   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
  #5   Spotlight this post!  
Unread 20-01-2012, 21:06
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

Yes I tried that as well. I declared 4 of them. Something along the lines of

SpeedController frontLeft = new Jaguar(1,1);
SpeedController rearLeft = new Jaguar(1,2);
SpeedController frontRight = new Jaguar(1,3);
SpeedController rearRight = new Jaguar(1,4);

To be honest, I am not entirely sure what the slot number on the chassis is supposed to signify, so i just used 1 because that seems to be what everyone used in the examples i have seen. For the channel number, I used the PWM slot number i connected each jaguar to on the digital side car.

Then I used the set method, passing in the throttle value from a joystick, to set the speeds. Then I passed the speed controllers into the tankDrive() method.

One more thing that i have noticed is that the the green diagnostic light in the driver station diagnostic console doesnt change color to blue when i move the sticks. It does, however, change color when i press buttons on the stick. Does this have any significance?
Reply With Quote
  #6   Spotlight this post!  
Unread 20-01-2012, 21:17
nickpeq nickpeq is offline
Turing-complete
FRC #1255 (Blarglefish)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Baytown, TX
Posts: 60
nickpeq is an unknown quantity at this point
Re: CANJaguar

Quote:
Originally Posted by kingkurry View Post
Yes I tried that as well. I declared 4 of them. Something along the lines of

SpeedController frontLeft = new Jaguar(1,1);
SpeedController rearLeft = new Jaguar(1,2);
SpeedController frontRight = new Jaguar(1,3);
SpeedController rearRight = new Jaguar(1,4);

To be honest, I am not entirely sure what the slot number on the chassis is supposed to signify, so i just used 1 because that seems to be what everyone used in the examples i have seen. For the channel number, I used the PWM slot number i connected each jaguar to on the digital side car.

Then I used the set method, passing in the throttle value from a joystick, to set the speeds. Then I passed the speed controllers into the tankDrive() method.

One more thing that i have noticed is that the the green diagnostic light in the driver station diagnostic console doesnt change color to blue when i move the sticks. It does, however, change color when i press buttons on the stick. Does this have any significance?
If the code isn't working, try removing the slot number. Instantiate your Jaguars with only the PWM number. Also, I've never used "SpeedController x = new Jaguar(etc)". I believe I always use "Jaguar x = new Jaguar(blah)"... If that makes any difference.
And the dashboard is just like that. No real significance. It changes color only for button-presses.
Reply With Quote
  #7   Spotlight this post!  
Unread 20-01-2012, 21: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

Quote:
Originally Posted by nickpeq View Post
If the code isn't working, try removing the slot number. Instantiate your Jaguars with only the PWM number. Also, I've never used "SpeedController x = new Jaguar(etc)". I believe I always use "Jaguar x = new Jaguar(blah)"... If that makes any difference.
And the dashboard is just like that. No real significance. It changes color only for button-presses.
I do what nick does, works just fine for me, and for Java I think the Digital Side car module is on the second slot and for Labview the 4th one, maybe you have one of the modules wrong?
Reply With Quote
  #8   Spotlight this post!  
Unread 22-01-2012, 15:20
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

Quote:
Originally Posted by nickpeq View Post
If the code isn't working, try removing the slot number. Instantiate your Jaguars with only the PWM number. Also, I've never used "SpeedController x = new Jaguar(etc)". I believe I always use "Jaguar x = new Jaguar(blah)"... If that makes any difference.
And the dashboard is just like that. No real significance. It changes color only for button-presses.
I just tried instantiating the jaguars without a slot number. This didn't work either. This is the code I have been trying. I have also tried all the code that I commented out, still without results

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; 
    Jaguar leftFront;
    Jaguar leftRear;
    Jaguar rightFront;
    Jaguar rightRear;
    
    public void robotInit() {
        Jaguar leftFront = new Jaguar(1);
        Jaguar leftRear= new Jaguar(2);
        Jaguar rightFront= new Jaguar(3);
        Jaguar rightRear= new Jaguar(4);
        
        robot = new RobotDrive(leftFront,leftRear,rightFront,rightRear);
  
        //robot = new RobotDrive(1,2,3,4);
        left = new Joystick(1);
        right = new Joystick(2);
        System.out.println("RobotInit() completed.\n");
    }
    
    public void disabledContinuous(){
        leftFront.set(1);
        //robot.tankDrive(1,1);
        
        
    }
    
    public void disabledPeriodic(){
        leftFront.set(1);
        //robot.tankDrive(1,1);
    }

    public void autonomousPeriodic() {
        leftFront.set(1);
        //robot.tankDrive(1,1);

    }
    
    public void teleopContinuous(){
        leftFront.set(1);
        //robot.tankDrive(1,1);
    }

    public void teleopPeriodic() {
        //robot.tankDrive(left.getThrottle(),(-1*right.getThrottle()));
        leftFront.set(1);
        //rightFront.set(right.getMagnitude());
        //robot.tankDrive(leftFront.get(), rightFront.get());
        
        //robot.tankDrive(left, right);
        //robot.tankDrive(1,1);
       
        
        //System.out.println("left:"+left.getThrottle());
        //System.out.println("right:"+right.getThrottle());
        //System.out.println("LMAG:"+ left.getMagnitude());
        //System.out.println("RMAG:"+ right.getMagnitude());
        //System.out.println("LRAD"+left.getDirectionDegrees());
        //System.out.println("RRAD"+right.getDirectionDegrees());
        
        System.out.println("Tank Drive");
    }
    
}
As you can see, I have tried to create a robot drive specifying the pwm outputs, then driving it with tankDrive(2,2)

I have also tried creating jaguar objects and setting their speed manually. Again this did not work.

I even took a multimeter to my sidecar, testing each of the signal pins in both the 3 pin PWM and the 3 pin Digital I/O. No matter what code I tried, the signal pins never presented any current.

What do you guys think the problem could be? My code looks fine right? Could it be the ribbon cable connecting the cRIO to the sidecar?
Reply With Quote
  #9   Spotlight this post!  
Unread 23-01-2012, 01:19
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: CANJaguar

Quote:
Originally Posted by kingkurry View Post
I just tried instantiating the jaguars without a slot number. This didn't work either. This is the code I have been trying. I have also tried all the code that I commented out, still without results

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; 
    Jaguar leftFront;
    Jaguar leftRear;
    Jaguar rightFront;
    Jaguar rightRear;
    
    public void robotInit() {
        Jaguar leftFront = new Jaguar(1);
        Jaguar leftRear= new Jaguar(2);
        Jaguar rightFront= new Jaguar(3);
        Jaguar rightRear= new Jaguar(4);
        
        robot = new RobotDrive(leftFront,leftRear,rightFront,rightRear);
  
        //robot = new RobotDrive(1,2,3,4);
        left = new Joystick(1);
        right = new Joystick(2);
        System.out.println("RobotInit() completed.\n");
    }
I believe you have a scope problem.
You instantiate your jaguars as class variables (green lines), then create four new jaguar variables within the robotInit() method (red lines). You're not initializing the class variables as you may think. Basically you're telling the program that within the robotInit() class it should use the local copies of those Jag variables (red), instead of the ones the rest of the program knows about (green). Any reference to the Jag variables outside of the robotInit() method will refer to the ones that aren't initialized (green), and since they aren't initialized they won't be sending commands to any motor controllers.

Remove the "Jaguar" text thats highlighted red and that should fix your problem.

Read up on scope: http://sip.clarku.edu/tutorials/java/java.html#scope
__________________
http://team2168.org
Reply With Quote
  #10   Spotlight this post!  
Unread 23-01-2012, 02:11
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 otherguy View Post
I believe you have a scope problem.
You instantiate your jaguars as class variables (green lines), then create four new jaguar variables within the robotInit() method (red lines). You're not initializing the class variables as you may think. Basically you're telling the program that within the robotInit() class it should use the local copies of those Jag variables (red), instead of the ones the rest of the program knows about (green). Any reference to the Jag variables outside of the robotInit() method will refer to the ones that aren't initialized (green), and since they aren't initialized they won't be sending commands to any motor controllers.

Remove the "Jaguar" text thats highlighted red and that should fix your problem.

Read up on scope: http://sip.clarku.edu/tutorials/java/java.html#scope
Yup, he is right, you having that is like pretty much trying to make two jaguars of the same variable name, and in any programming language you can't simply do that.
Reply With Quote
  #11   Spotlight this post!  
Unread 24-01-2012, 00:09
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: CANJaguar

Quote:
Originally Posted by Kodiak View Post
Yup, he is right, you having that is like pretty much trying to make two jaguars of the same variable name, and in any programming language you can't simply do that.
Just to be clear, you CAN do that in java, you're just not going to be referring to the same variable throughout the program. If every variable name had to be completely unique, you wouldn't be able to use the same variable names as any of the variables used in the classes you import. For any large scale program it would get difficult pretty quickly to keep track of what variable names were used where.

His code will compile and run as it was, it's just not going to do what he expected it to.
__________________
http://team2168.org
Reply With Quote
  #12   Spotlight this post!  
Unread 24-01-2012, 09:55
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 otherguy View Post
Just to be clear, you CAN do that in java, you're just not going to be referring to the same variable throughout the program. If every variable name had to be completely unique, you wouldn't be able to use the same variable names as any of the variables used in the classes you import. For any large scale program it would get difficult pretty quickly to keep track of what variable names were used where.

His code will compile and run as it was, it's just not going to do what he expected it to.
True, I did not clarify correctly, I have a problem of doing that, my bad, haha
Reply With Quote
  #13   Spotlight this post!  
Unread 25-01-2012, 14:39
emusteve's Avatar
emusteve emusteve is offline
Registered User
AKA: Steve Martin
#0470 (Alpha Omega)
 
Join Date: Jan 2004
Location: Ypsilanti
Posts: 66
emusteve is just really niceemusteve is just really niceemusteve is just really niceemusteve is just really nice
Re: CANJaguar

Could someone kindly tell me where you found documentation on using CAN under Java? I've searched in the "Getting Started with JAVA", "WPI Robotics Library User’s Guide", and "WPI Library Cookbook" publications, but have somehow missed it if it is in there. Went back to First Forge, but couldn't locate any additional documentation that seemed like it would point me in the right direction.

If anyone knows of an example project, that would be appreciated as well.

Thanks,
Steve
Reply With Quote
  #14   Spotlight this post!  
Unread 21-01-2012, 00:31
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

We had some problems with things getting initiated at the beginning of the year because some standards have changed with regards to the numbering of the modules. Your digital module should be in slot 2, and then you should just remove the slot number from the lines that instantiate the motors. Also, how to OTHER things connected to the sidecar work? I saw a person earlier today that had a faulty ribbon cable.
Reply With Quote
  #15   Spotlight this post!  
Unread 22-01-2012, 13:15
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: CANJaguar

Quote:
Originally Posted by kingkurry View Post
To be honest, I am not entirely sure what the slot number on the chassis is supposed to signify, so i just used 1 because that seems to be what everyone used in the examples i have seen. For the channel number, I used the PWM slot number i connected each jaguar to on the digital side car.
For 2012 I believe the Java methods referring to "Slot" numbers essentially mean the instance of the particular card you are trying to access. I think the same is true for how LabVIEW is identifying the modules. For example: in the 8 or 4 slot cRIO chassis the DIO module in slot position two would be identified to the program as "Slot" 1. A second DIO module in slot position 4 (on the cRIO II) or slot position 6 (on the cRIO) would be identified to the program as "Slot" 2.

I think this deviates from what "Slot" meant in the past: the actual physical position the card was at (i.e. slot 4 of 8 for previous years was the slot for the first DIO module)

Again this is just what I remember from beta test, and what I've observed from my testing. If I'm wrong, let me know so I can avoid headaches down the road.
__________________
http://team2168.org
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:16.

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