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.