|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
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. |
|
#2
|
||||
|
||||
|
Re: CANJaguar
Quote:
![]() |
|
#3
|
|||
|
|||
|
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());
}
}
|
|
#4
|
||||
|
||||
|
Re: CANJaguar
Quote:
|
|
#5
|
|||
|
|||
|
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? |
|
#6
|
|||
|
|||
|
Re: CANJaguar
Quote:
And the dashboard is just like that. No real significance. It changes color only for button-presses. |
|
#7
|
||||
|
||||
|
Re: CANJaguar
Quote:
|
|
#8
|
|||
|
|||
|
Re: CANJaguar
Quote:
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");
}
}
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? |
|
#9
|
||||
|
||||
|
Re: CANJaguar
Quote:
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 |
|
#10
|
||||
|
||||
|
Re: CANJaguar
Quote:
|
|
#11
|
||||
|
||||
|
Re: CANJaguar
Quote:
His code will compile and run as it was, it's just not going to do what he expected it to. |
|
#12
|
||||
|
||||
|
Re: CANJaguar
Quote:
|
|
#13
|
||||
|
||||
|
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 |
|
#14
|
||||
|
||||
|
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.
|
|
#15
|
||||
|
||||
|
Re: CANJaguar
Quote:
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. ![]() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|