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
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 ).
Guess what… the default is 0. You must set it.
-Joe
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.kQuadEncoder);
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
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.
Ok, I found the issue. Instead of doing something like this
jag2 = new CANJaguar(2);
jag2.changeControlMode(CANJaguar.ControlMode.kSpeed);
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
Assuming you are using NetBeans and Java, it prints to the NetBeans “Output” tab below the Source frame.
-Joe
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??
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.
DUH I cant believe I didnt think of that before. Thanks so much!