Log in

View Full Version : Resetting Jaguar Encoder Count


usbcd36
15-02-2015, 20:55
We are trying to reset the internal encoder count of a Jaguar to 0. This is supposedly possible to do using the enableControl(double encoderInitialPosition) function.

The Jag is generally being run in %Vbus mode. From what we understand, it's necessary to change the control mode to Position in order for the passed double to have any effect. This is supported by looking at the source code, which only packs and sends the encoderInitialPosition if the m_controlMode instance variable is set to Position. (CANJaguar.class)

We found an example of this being done in C++ (https://github.com/FRCTeam1073-TheForceTeam/robot11Elot/blob/master/Code/SmartJagMotor.cpp)

CANJaguar::ControlMode oldMode = GetControlMode();
//printf("Reseting encoder on Jag [%d], mode %d\n", m_deviceNumber, oldMode);

SetPositionReference(CANJaguar::kPosRef_QuadEncode r);
ConfigEncoderCodesPerRev(pulsesPerFt);

ChangeControlMode(CANJaguar::kPosition);
EnableControl(0.0);
ChangeControlMode(oldMode);
EnableControl();

and wrote what would seem to be equivalent code in Java:

jaguar.setPositionMode(CANJaguar.kQuadEncoder, encoderCounts, 0, 0, 0);
jaguar.enableControl(0.0);
jaguar.setPercentMode(CANJaguar.kQuadEncoder, encoderCounts);
jaguar.enableControl();

but the next time the set method is called:

jaguar.set(0);

it throws a CANMessageNotAllowedException with the output: "messageID = 5", which is not documented anywhere.


Thoughts?