That should not be happening, even in sim. I mocked up a minimal test to check if it was the case and wasn’t able to reproduce the problem.
For reference, I created a new timed skeleton java project, added the CTRE vendor library, and added/modified the following code in Robot.java, then proceeded to simulate:
WPI_TalonFX _1 = new WPI_TalonFX(1);
int time = 0;
@Override
public void robotInit() {
System.out.println("Set position error code: " + _1.setSelectedSensorPosition(452));
}
@Override
public void robotPeriodic() {
System.out.println("Position is " + _1.getSelectedSensorPosition() + " @ " + time++);
}
This produces a stream of text to the terminal, so I’ll focus on the bits that matter
********** Robot program starting **********
Set position error code: OK
********** Robot program startup complete **********
Position is 0.0 @ 0
Position is 0.0 @ 1
Position is 0.0 @ 2
Position is 0.0 @ 3
Position is 452.0 @ 4
Position is 452.0 @ 5
Position is 452.0 @ 157
Position is 452.0 @ 158
[phoenix] Library initialization is complete.
Position is 452.0 @ 159
Position is 452.0 @ 160
You should be able to reproduce my test and get similar results.
The test indicates that position is not “gotten” until 4 loops have passed, about 80ms. While this is longer than I’d normally expect (we simulate the can frame latency, so I’d expect an update 20ms after setting), I’m willing to believe part of it is due to the simulation library initializing. Regardless, the setter goes out well before the print and we see the feedback well before the print, indicating no relation to the feature and the print.
I went back and modified the example to verify the 80ms latency was related to initialization
By changing the position on teleop init and printing the time I changed position
@Override
public void teleopInit() {
System.out.println("Changing position @ " + time);
_1.setSelectedSensorPosition(5489);
}
Giving me the following text
Position is 452.0 @ 103
Position is 452.0 @ 104
Changing position @ 105
Position is 452.0 @ 105
Position is 5489.0 @ 106
Position is 5489.0 @ 107
I suspect you’re seeing this behavior due to something you’re doing in your code. Would you mind sharing your code so that I can attempt to reproduce what you’re doing and possibly find the source of the problem?