CTR Magnetic Encoder Refresh Rate

Hi all,

I’m currently testing some code that logs encoder readings every 10ms and then dumps them into a csv stored in a directory on the RIO. During recording, the values are added to an ArrayList and then after the recording period is finished, that ArrayList is written into a csv.

The goal of this is to record the movement of the robot as a motion profile and play it back via the Talon SRX’s motion profile execution mode.

The issue I’m having now is that when logging the position/velocity readings from the mag encoders, the encoder reading only changes once every 100ms, meaning that because I’m taking data every 10ms, I’ll have about 10 lines of the csv containing the same numbers. This is bad because instead of smoothly mimicking the recorded motion it jumps from one speed and position setpoint to another and causes the playback to be very jittery/jumpy (and unusable).

The code I’m using to poll the sensors is as follows:


class PeriodicRunnable implements java.lang.Runnable {
		public void run() {
			leftPosition.add(talons[0].getEncPosition());
			leftVelocity.add(talons[0].getEncVelocity());

			rightPosition.add(talons[1].getEncPosition());
			rightVelocity.add(talons[1].getEncVelocity());
		}
	}

run() is called every 10ms.

I’ve tried experimenting with the Talon’s SetVelocityMeasurementPeriod and SetVelocityMeasurementWindow methods, but to no avail.

Is there any way to increase the rate at which the readings from the encoders are updated?

Any help is appreciated.

Don’t use the getEncBlah methods, use getPosition and getVelocity.

Will do, any specific reason why?

Two reasons:

The “GetEnc” methods are on a slower CAN frame than the other methods (100 ms by default, as opposed to 10), and so update less-often.

The “GetEnc” methods don’t use the internal unit scaling if you have chosen to use configEncoderCodesPerRev, and don’t account for invertSensor.

Talons, by default, only report encoder values every 100ms. You can change that with setStatusFrameRateMs.