I did a test to prove/disprove my theory. It’s actually worse than I expected, I’m using V3.6 rather than 3.62 (or 4.06) so may be a bug in that version, not sure. This may have always been there but I generally don’t use nMotorEncoder[port] = 0 in any of my code so I wouldn’t have noticed.
I did this test.
One motor, one IME. This code.
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, , tmotorVex269, openLoop, encoder, encoderPort, I2C_1, 1000)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
while(1) {
if( vexRT Btn8U] == 1 )
nMotorEncoder port1 ] = 0;
wait1Msec(10);
}
}
I turned the motor by hand so the encoder count in the debug window was -100. I hit the button and reset the encoder count to 0, the debug window shows 0 as expected. Now I remove the IME cable and replace, this causes a I2C bus reset, the encoder count jumps to +100 I consider this a bug in ROBOTC, an I2C bus reset should zero out all the internal offsets. This is why you are all having problems with lines of code being skipped. My suggestions, 1. fix the static issues by using anti-static spray. 2. consider using the library I posted in this thread which I guess I should retest as it’s been a year since I played with that.
Edit:
So I gave my old library a quick test, still works as before, here was the modified code I use to test it.
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, , tmotorVex269, openLoop, encoder, encoderPort, I2C_1, 1000)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "ImeLib.c"
long value;
task main()
{
IMEInit();
while(1) {
if( vexRT Btn8U] == 1 )
IMESetEncoder( port1, 0 );
value = IMEGetEncoder( port1 );
wait1Msec(10);
}
}
As you can see, IMESetEncoder( port1, 0 ) replaces nMotorEncoder port1 ] = 0. IMEGetEncoder( port1 ) replaces using nMotorEncoder[port1] for reading. I have not (but will) check it works with V4.06.
Edit2:
So the same bug exists in V4.06, the library works OK except for the usual warnings about capitalization of StartTask etc.