View Full Version : setX() not working
Not sure if I should post this here or in the Java section...
I was trying to use setX to set a speed of the motor. I set up the speed and position references. But the Jaguar would not do anything (RobotDrive works fine). I did not set PID and am wondering if this could be the problem. Thanks in advance for your help.
Not sure if I should post this here or in the Java section...
I was trying to use setX to set a speed of the motor. I set up the speed and position references. But the Jaguar would not do anything (RobotDrive works fine). I did not set PID and am wondering if this could be the problem. Thanks in advance for your help.
If you have configured the CANJaguar to Speed Control mode, then you must do several things to make it work... Set a speed reference, set the number of codes per rotation your encoder outputs, set the PID values (they default to 0 which will do nothing), then call enableControl().
-Joe
JewishDan18
21-01-2011, 21:19
related question: is there a default number of ticks per revolution? I had everything you listed set but that value, and the speed was always reported as 0.0. Tomorrow I'll try setting some arbitrary value (or maybe look up the proper one :p ).
related question: is there a default number of ticks per revolution? I had everything you listed set but that value, and the speed was always reported as 0.0. Tomorrow I'll try setting some arbitrary value (or maybe look up the proper one :p ).
Guess what... the default is 0. You must set it.
-Joe
JewishDan18
22-01-2011, 22:50
Ok, so I set the number of ticks, and setSpeed still does not seem to work. Here's what I've written.
CANJaguar jag;
public void robotInit() {
try {
jag = new CANJaguar(4);
jag.setPID(1, 1, 0);
jag.setSpeedReference(CANJaguar.SpeedReference.kQu adEncoder);
jag.changeControlMode(CANJaguar.ControlMode.kSpeed );
jag.configEncoderCodesPerRev(100);
jag.enableControl();
} catch (Exception e) {
e.printStackTrace();
}
}
public void teleopPeriodic() {
try {
jag.setX(10);
System.out.println(jag.getSpeed() + " " + jag.getOutputVoltage() +
" " + jag.getOutputCurrent() + " " +
jag.getTemperature() + " " + jag.isAlive() +
" " + jag.isSafetyEnabled());
} catch (Exception e) {
e.printStackTrace();
}
}
During Current or Voltage control, the encoder reads fine. But in Speed control, no signal to drive is sent to the jaguar (light is yellow, both outputs are 0, as is the speed). Is there something I'm forgetting to set? Thanks.
Ok, so I set the number of ticks, and setSpeed still does not seem to work. Here's what I've written.
CANJaguar jag;
public void robotInit() {
try {
jag = new CANJaguar(4);
jag.setPID(1, 1, 0);
jag.setSpeedReference(CANJaguar.SpeedReference.kQu adEncoder);
jag.changeControlMode(CANJaguar.ControlMode.kSpeed );
jag.configEncoderCodesPerRev(100);
jag.enableControl();
} catch (Exception e) {
e.printStackTrace();
}
}
public void teleopPeriodic() {
try {
jag.setX(10);
System.out.println(jag.getSpeed() + " " + jag.getOutputVoltage() +
" " + jag.getOutputCurrent() + " " +
jag.getTemperature() + " " + jag.isAlive() +
" " + jag.isSafetyEnabled());
} catch (Exception e) {
e.printStackTrace();
}
}
During Current or Voltage control, the encoder reads fine. But in Speed control, no signal to drive is sent to the jaguar (light is yellow, both outputs are 0, as is the speed). Is there something I'm forgetting to set? Thanks.
The code looks OK at first glance. My guess would be that your PID constants are too small. Try increasing the P at least to see if that has any impact.
-Joe
JewishDan18
23-01-2011, 09:33
I forgot to mention that with 100 ticks per revolution, my test rig reaches a max speed of 900 rpm. I'll try P=100 today, along with many other combinations of constants, and get back to you. Thanks.
JewishDan18
23-01-2011, 16:33
Ok, I found the issue. Instead of doing something like this
jag2 = new CANJaguar(2);
jag2.changeControlMode(CANJaguar.ControlMode.kSpee d);
I had to do this
jag2 = new CANJaguar(2,CANJaguar.ControlMode.kSpeed);
I want to look into switching control modes, since I feel position control would be useful during autonomous, and speed would be used for teleoperated.
Ok, I found the issue. Instead of doing something like this
jag2 = new CANJaguar(2);
jag2.changeControlMode(CANJaguar.ControlMode.kSpee d);
I had to do this
jag2 = new CANJaguar(2,CANJaguar.ControlMode.kSpeed);
I want to look into switching control modes, since I feel position control would be useful during autonomous, and speed would be used for teleoperated.
Ah yes... your symptoms reminded me of why your code did not work...
setPID() sets the PID constants for the control mode you are in. The original code you posted will work if you move setPID() below changeControlMode().
-Joe
buildmaster5000
23-01-2011, 17:43
public void teleopPeriodic() {
try {
jag.setX(10);
System.out.println(jag.getSpeed() + " " + jag.getOutputVoltage() +
" " + jag.getOutputCurrent() + " " +
jag.getTemperature() + " " + jag.isAlive() +
" " + jag.isSafetyEnabled());
} catch (Exception e) {
e.printStackTrace();
}
}[/CODE]
I am confused. My team is triying to use CAN to control a swerve drive, and most of this makes sense. The System.out.print is what puzzles me. Where does this print to?? Obviously it won't go to the driver station lcd, but how would you go about configuring a laptop (I am assuming that is where it would ultimatly print to, but I am unsure where) so that you can operate the robot and see the System.out.print?
A concerned programmer
I am confused. My team is triying to use CAN to control a swerve drive, and most of this makes sense. The System.out.print is what puzzles me. Where does this print to?? Obviously it won't go to the driver station lcd, but how would you go about configuring a laptop (I am assuming that is where it would ultimatly print to, but I am unsure where) so that you can operate the robot and see the System.out.print?
A concerned programmer
Assuming you are using NetBeans and Java, it prints to the NetBeans "Output" tab below the Source frame.
-Joe
buildmaster5000
23-01-2011, 18:07
So if i plug the laptop into the cRIO port 1 and boot the robot I should get all the println?? How would I run the robot from the driver station then??
JewishDan18
23-01-2011, 18:13
I'm using Ubuntu with Netbeans installed there, and have the driver station running in a virtual machine of Windows XP (Remember that any computer can act as the driver station). The println's go to Netbeans. if you have the driver station on a seperate laptop, simply plug both of them into the D-Link (or put one/both on wireless), and run the code from netbeans to get it to display the output. Make sure no IPs conflict!
setPID() sets the PID constants for the control mode you are in. The original code you posted will work if you move setPID() below changeControlMode().
That makes a lot of sense, since if I were to use different modes, I'd want different PID constants for each mode. Thanks a lot for the clarification.
buildmaster5000
23-01-2011, 18:27
DUH I cant believe I didnt think of that before. Thanks so much!
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.