We are working with CANJaguar for the first time, and we are sort of lost. We have the motors themselves spinning, but we can’t seem to control them as we want to. We’re in PercentVBus mode, and we are using the regular old set function (we pass it a value between -1 and 1 using the axes on our gamepad). Instead of moving the motor at the speed that is specified, though, it gradually approaches that speed.
Here is a rough outline of our code, just highlighting stuff relating to the CANJags:
cjag(12, CANJaguar::kPercentVbus), // This is in the constructor for our drivetrain class
// Settings
cjag.SetPID(0.4, 0.005, 0);
cjag.ConfigEncoderCodesPerRev(200);
cjag.SetSpeedReference(CANJaguar::kSpeedRef_Encoder);
cjag.EnableControl();
// Moving
cjag.Set(gamepad.GetY());
This is because you are using a PID controller on them. You are telling it to try to get to a certain value. Try not using the PID controller (try removing the cjag.EnableControl(); line and see if you get the same behavior)
He’s right, it’s due to the PID control. We also used CAN and C++ on our robot this year, and started with P as 1.0, I as 0.01 and D as 0. It will still loop, but will get to speed much quicker, although it may have significant overshoot until you tune it.
As far as I know, there is no way to control the Jaguars with encoders without a PID loop being involved.
I’m not a programmer so I’m not sure about this, but you might also need to construct the CANJaguar as CANJaguar::kSpeed instead of kPercentVbus.
Hope this helps!
Also note that the mode you’re using uses neither PID nor encoders. You want to use speed control to use them.
It also seems to me, looking through the FIRSTForge documentation, that kPercentVbus is no longer a control mode, and has been renamed to be “kPercentVoltage”.